SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
PGP Public Key lookup module and Whois module.
smicallef52325793edc3
diff --git a/modules/sfp_pgp.py b/modules/sfp_pgp.pynew file mode 100644index 00000000..1d1d2360--- /dev/null+++ b/modules/sfp_pgp.py@@ -0,0 +1,109 @@+#-------------------------------------------------------------------------------+# Name: sfp_pgp+# Purpose: SpiderFoot plug-in for looking up received e-mails in PGP+# key servers as well as finding e-mail addresses belonging to+# your target.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 17/02/2015+# Copyright: (c) Steve Micallef 2015+# Licence: GPL+#-------------------------------------------------------------------------------++import sys+import re+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent++class sfp_pgp(SpiderFootPlugin):+ """PGP Key Look-up:Look up e-mail addresses in PGP public key servers."""++ results = list()++ # Default options+ opts = {+ # options specific to this module+ 'keyserver_search': "http://pgp.mit.edu/pks/lookup?op=index&search=",+ 'keyserver_fetch': "http://pgp.mit.edu/pks/lookup?op=get&search="+ }++ # Option descriptions+ optdescs = {+ 'keyserver_search': "PGP public key server URL to find e-mail addresses on a domain. Domain will get appended.",+ 'keyserver_fetch': "PGP public key server URL to find the public key for an e-mail address. Email address will get appended."+ }++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc++ self.results = list()++ for opt in userOpts.keys():+ self.opts[opt] = userOpts[opt]++ # What events is this module interested in for input+ def watchedEvents(self):+ return ["EMAILADDR", "DOMAIN_NAME"]++ # What events this module produces+ # This is to support the end user in selecting modules based on events+ # produced.+ def producedEvents(self):+ return [ "EMAILADDR", "PGP_KEY" ]++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data+ parentEvent = event.sourceEvent++ if eventData in self.results:+ return None+ else:+ self.results.append(eventData)++ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)++ # Get e-mail addresses on this domain+ if eventName == "DOMAIN_NAME":+ res = self.sf.fetchUrl(self.opts['keyserver_search'] + eventData,+ timeout=self.opts['_fetchtimeout'],+ useragent=self.opts['_useragent'])+ if res['content'] != None:+ pat = re.compile("([a-zA-Z\.0-9_\-]+@[a-zA-Z\.0-9\-]+\.[a-zA-Z\.0-9\-]+)")+ matches = re.findall(pat, res['content'])+ for match in matches:+ self.sf.debug("Found possible email: " + match)+ if len(match) < 4:+ self.sf.debug("Likely invalid address.")+ continue++ mailDom = match.lower().split('@')[1]+ if not self.getTarget().matches(mailDom):+ self.sf.debug("Ignoring e-mail address on an external domain: " + match)+ continue++ self.sf.info("Found e-mail address: " + match)+ evt = SpiderFootEvent("EMAILADDR", match, self.__name__, event)+ self.notifyListeners(evt)++ if eventName == "EMAILADDR":+ res = self.sf.fetchUrl(self.opts['keyserver_fetch'] + eventData,+ timeout=self.opts['_fetchtimeout'],+ useragent=self.opts['_useragent'])+ if res['content'] != None:+ pat = re.compile("(-----BEGIN.*END.*BLOCK-----)", re.MULTILINE|re.DOTALL)+ matches = re.findall(pat, res['content'])+ for match in matches:+ self.sf.debug("Found public key: " + match)+ if len(match) < 300:+ self.sf.debug("Likely invalid public key.")+ continue++ evt = SpiderFootEvent("PGP_KEY", match, self.__name__, event)+ self.notifyListeners(evt)++ return None++# End of sfp_pgp classdiff --git a/modules/sfp_whois.py b/modules/sfp_whois.pynew file mode 100644index 00000000..4d1ef848--- /dev/null+++ b/modules/sfp_whois.py@@ -0,0 +1,83 @@+#-------------------------------------------------------------------------------+# Name: sfp_whois+# Purpose: SpiderFoot plug-in for scanning retreived content by other+# modules (such as sfp_spider) and identifying e-mail addresses+#+# Author: Steve Micallef <[email protected]>+#+# Created: 06/04/2012+# Copyright: (c) Steve Micallef 2012+# Licence: GPL+#-------------------------------------------------------------------------------++import sys+import re+import pythonwhois+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent++class sfp_whois(SpiderFootPlugin):+ """Whois:Perform a WHOIS look-up on domain names and owned netblocks."""++ # Default options+ opts = {+ }++ # Option descriptions+ optdescs = {+ }++ results = list()++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc++ self.results = list()++ for opt in userOpts.keys():+ self.opts[opt] = userOpts[opt]++ # What events is this module interested in for input+ def watchedEvents(self):+ return ["DOMAIN_NAME", "OWNED_NETBLOCK"]++ # What events this module produces+ # This is to support the end user in selecting modules based on events+ # produced.+ def producedEvents(self):+ return [ "DOMAIN_WHOIS", "NETBLOCK_WHOIS", "DOMAIN_REGISTRAR" ]++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data+ parentEvent = event.sourceEvent++ if eventData in self.results:+ return None+ else:+ self.results.append(eventData)++ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)++ try:+ data = pythonwhois.net.get_whois_raw(eventData)+ except BaseException as e:+ self.sf.error("Unable to perform WHOIS on " + eventData + ": " + str(e), False)+ return None++ if eventName == "DOMAIN_NAME":+ typ = "DOMAIN_WHOIS"+ else:+ typ = "NETBLOCK_WHOIS"++ evt = SpiderFootEvent(typ, '\n'.join(data), self.__name__, event)+ self.notifyListeners(evt)++ info = pythonwhois.parse.parse_raw_whois(data, True)+ if eventName == "DOMAIN_NAME" and info['registrar'] != None:+ evt = SpiderFootEvent("DOMAIN_REGISTRAR", info['registrar'][0],+ self.__name__, event)+ self.notifyListeners(evt)++# End of sfp_whois class