Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def censys_search_certs(host):
try:
certificates = censys.certificates.CensysCertificates(api_id=UID, api_secret=TOKEN)
cert_query = certificates.search("parsed.names: {0} AND tags.raw: trusted AND NOT parsed.names: cloudflaressl.com".format(host))
result = set([cert['parsed.fingerprint_sha256'] for cert in cert_query])
hosts_query = censys.ipv4.CensysIPv4(api_id=UID, api_secret=TOKEN)
hosts = ' OR '.join(result)
if hosts:
searching = hosts_query.search(hosts)
host_result = set([ search_result['ip'] for search_result in searching ])
return host_result
except:
print("[-] We got an error here, maybe with your credentials!")
exit(1)
def get_certificates():
try:
if not CENSYS_API_ID or not CENSYS_API_SECRET:
logging.info("\033[1;31m[!] API KEY or Secret for Censys not provided.\033[1;m" \
"\nYou'll have to provide them in the script")
sys.exit()
logging.info("[+] Extracting certificates using Censys")
censys_certificates = censys.certificates.CensysCertificates(CENSYS_API_ID, CENSYS_API_SECRET)
return censys_certificates
except censys.base.CensysUnauthorizedException:
logging.info('\033[93m[!] Your Censys credentials look invalid.\n\033[1;m')
sys.exit(1)
except censys.base.CensysRateLimitExceededException:
logging.info('\033[93m[!] Looks like you exceeded your Censys account limits rate. Exiting\n\033[1;m')
sys.exit(1)
def search(self):
temp_domains = []
try:
main_of_domain = tldextract.extract(self.domain).domain
c = censys.certificates.CensysCertificates(api_id=self.api_id, api_secret=self.api_secret)
# iterate over certificates that match a search
fields = ["parsed.subject_dn", "parsed.fingerprint_sha256"] #parsed.issuer_dn
for cert in c.search("{0}".format(self.domain), fields=fields):
#print cert["parsed.subject_dn"]
cn_domain= cert["parsed.subject_dn"].split(",")[-1].split("=")[-1]#cn一定是在最后吗
main_of_cn_domain =tldextract.extract(cn_domain).domain
if main_of_domain in main_of_cn_domain:
detail = c.view(cert["parsed.fingerprint_sha256"]) #print c.view("a762bf68f167f6fbdf2ab00fdefeb8b96f91335ad6b483b482dfd42c179be076")
#print detail
#print detail["parsed"]["names"]
temp_domains.extend(detail["parsed"]["names"])
temp_domains = list(set(temp_domains))
except Exception,e:
logger.error("Error in {0}: {1}".format(__file__.split('/')[-1], e))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author = i@cdxy.me
# project = https://github.com/Xyntax/POC-T
import censys.certificates
UID = "login for API key"
SECRET = "login for API secret"
certificates = censys.certificates.CensysCertificates(UID, SECRET)
fields = ["parsed.subject_dn", "parsed.fingerprint_sha256", "parsed.fingerprint_sha1"]
for c in certificates.search("current_valid_nss: true"):
print c["parsed.subject_dn"]
def initialize(self, base_dir):
uid = self.censys_struct['uid']
secret = self.censys_struct['secret']
try:
if uid is not None and secret is not None:
self.certificates = censys.certificates.CensysCertificates(uid, secret)
else:
uid = self.conf.items("censys")[0][1]
secret = self.conf.items("censys")[1][1]
if uid != '' and secret != '':
self.certificates = censys.certificates.CensysCertificates(uid, secret)
else:
return False
self.conf.set("censys", "UID", uid)
self.conf.set("censys", "SECRET", secret)
self.conf.write(open(base_dir + "/key.ini", "w"))
except Exception as e:
return False
return True