SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Cleanup sfp_crt
bcolesc730fb776b53
diff --git a/modules/sfp_crt.py b/modules/sfp_crt.pyindex cc9e9651..76bb7c07 100644--- a/modules/sfp_crt.py+++ b/modules/sfp_crt.py@@ -11,20 +11,17 @@# Licence: GPL# --------------------------------------------------------------------------------try:- import re2 as re-except ImportError as e:- import re-+import json+import urllibfrom sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEventclass sfp_crt(SpiderFootPlugin):"""Certificate Transparency:Footprint,Investigate,Passive:Search Engines::Gather hostnames from historical certificates in crt.sh."""-- # Default optionsopts = {}+ optdescs = {}+results = Nonedef setup(self, sfc, userOpts=dict()):@@ -50,43 +47,61 @@ class sfp_crt(SpiderFootPlugin):srcModuleName = event.moduleeventData = event.data- self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)-- # Don't look up stuff twiceif eventData in self.results:- self.sf.debug("Skipping " + eventData + " as already mapped.")return None- else:- self.results[eventData] = True- res = self.sf.fetchUrl("https://crt.sh/?CN=%25." + eventData + "&output=json",- timeout=self.opts['_fetchtimeout'], useragent=self.opts['_useragent'])- if res['content'] is None:+ self.results[eventData] = True++ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)++ params = {+ 'CN': '%.' + eventData.encode('raw_unicode_escape'),+ 'output': 'json'+ }++ res = self.sf.fetchUrl('https://crt.sh/?' + urllib.urlencode(params),+ timeout=self.opts['_fetchtimeout'],+ useragent=self.opts['_useragent'])++ if res['content'] is None or res['content'] == "[]":self.sf.info("No certificate transparency info found for " + eventData)return None- if res['content'] == "[]":+ try:+ data = json.loads(res['content'])+ except BaseException as e:+ self.sf.debug('Error processing JSON response: ' + str(e))return None- try:- evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", res['content'], self.__name__, event)- self.notifyListeners(evt)+ evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", str(data), self.__name__, event)+ self.notifyListeners(evt)- matches = re.findall("\"min_cert_id\":(\d+),", res['content'], re.IGNORECASE)- for m in matches:- if self.checkForStop():- return None- dat = self.sf.fetchUrl("https://crt.sh/?d=" + m, timeout=self.opts['_fetchtimeout'],- useragent=self.opts['_useragent'])-- cert = self.sf.parseCert(str(dat['content']))- rawevt = SpiderFootEvent("SSL_CERTIFICATE_RAW", cert['text'],- self.__name__, event)- self.notifyListeners(rawevt)- except Exception as e:- self.sf.debug("Error processing JSON response: " + str(e))- return None+ cert_ids = list()++ for cert_info in data:+ cert_id = cert_info.get('min_cert_id')+ if cert_id:+ cert_ids.append(cert_id)- return None+ for cert_id in set(cert_ids):+ if self.checkForStop():+ return None++ params = {+ 'd': str(cert_id)+ }++ res = self.sf.fetchUrl('https://crt.sh/?' + urllib.urlencode(params),+ timeout=self.opts['_fetchtimeout'],+ useragent=self.opts['_useragent'])++ try:+ cert = self.sf.parseCert(str(res['content']))+ except BaseException as e:+ self.sf.info('Error parsing certificate: ' + str(e))+ continue++ evt = SpiderFootEvent("SSL_CERTIFICATE_RAW", cert['text'], self.__name__, event)+ self.notifyListeners(evt)# End of sfp_crt class