SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Many bug fixes and CLI improvements.
Steve Micallef3d7bc72ab236
diff --git a/LICENSE.tp b/LICENSE.tpindex 3f98a6f1..4861784d 100644--- a/LICENSE.tp+++ b/LICENSE.tp@@ -62,20 +62,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORTOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.-License for pythonwhois:-========================-Copyright (C) 2004 Sam Hocevar <[email protected]>--Everyone is permitted to copy and distribute verbatim or modified- copies of this license document, and changing it is allowed as long- as the name is changed.-- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE-TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION--0. You just DO WHAT THE FUCK YOU WANT TO.--License for adblockparser:==========================Copyright (c) 2014 ScrapingHub Inc.diff --git a/modules/sfp__stor_stdout.py b/modules/sfp__stor_stdout.pyindex 99b8dd9a..4888fbff 100644--- a/modules/sfp__stor_stdout.py+++ b/modules/sfp__stor_stdout.py@@ -23,6 +23,8 @@ class sfp__stor_stdout(SpiderFootPlugin):"_requested": [],"_showonlyrequested": False,"_stripnewline": False,+ "_showsource": False,+ "_csvdelim": ",","_maxlength": 0,"_eventtypes": dict()}@@ -44,6 +46,7 @@ class sfp__stor_stdout(SpiderFootPlugin):return ["*"]def output(self, event):+ d = self.opts['_csvdelim']if type(event.data) in [list, dict]:data = unicode(str(event.data), 'utf-8', errors='replace')else:@@ -52,17 +55,30 @@ class sfp__stor_stdout(SpiderFootPlugin):if type(data) != unicode:data = unicode(event.data, 'utf-8', errors='replace')+ if type(event.sourceEvent.data) in [list, dict]:+ srcdata = unicode(str(event.sourceEvent.data), 'utf-8', errors='replace')+ else:+ srcdata = event.sourceEvent.data++ if type(srcdata) != unicode:+ srcdata = unicode(event.sourceEvent.data, 'utf-8', errors='replace')+if self.opts['_stripnewline']:data = data.replace("\n", "").replace("\r", "")+ srcdata = srcdata.replace("\n", "").replace("\r", "")if self.opts['_maxlength'] > 0:data = data[0:self.opts['_maxlength']]+ srcdata = srcdata[0:self.opts['_maxlength']]if self.opts['_format'] == "tab":- print u'{0:45} {1}'.format(self.opts['_eventtypes'][event.eventType], data)+ if self.opts['_showsource']:+ print '{0:30}\t{1:45}\t{2}\t{3}'.format(event.module, self.opts['_eventtypes'][event.eventType], srcdata, data)+ else:+ print '{0:30}\t{1:45}\t{2}'.format(event.module, self.opts['_eventtypes'][event.eventType], data)if self.opts['_format'] == "csv":- print self.opts['_eventtypes'][event.eventType] + "," + data+ print event.module + d + self.opts['_eventtypes'][event.eventType] + d + srcdata + d + dataif self.opts['_format'] == "json":d = event.asDict()diff --git a/modules/sfp_builtwith.py b/modules/sfp_builtwith.pyindex f4e81dc2..46811beb 100644--- a/modules/sfp_builtwith.py+++ b/modules/sfp_builtwith.py@@ -54,7 +54,7 @@ class sfp_builtwith(SpiderFootPlugin):# What events this module producesdef producedEvents(self):return [ "INTERNET_NAME", "EMAILADDR", "RAW_RIR_DATA",- "WEB_TECHNOLOGY", "PHONE_NUMBER" ]+ "WEBSERVER_TECHNOLOGY", "PHONE_NUMBER" ]def query(self, t):ret = Nonediff --git a/modules/sfp_mnemonic.py b/modules/sfp_mnemonic.pyindex 78fff438..a0fe9d19 100644--- a/modules/sfp_mnemonic.py+++ b/modules/sfp_mnemonic.py@@ -186,6 +186,9 @@ class sfp_mnemonic(SpiderFootPlugin):self.sf.debug("Host " + co + " no longer resolves to " + eventData)continue+ if co in self.results:+ continue+if not self.opts['cohostsamedomain']:if self.getTarget().matches(co, includeParents=True):evt = SpiderFootEvent("INTERNET_NAME", co, self.__name__, event)diff --git a/modules/sfp_tool_dnstwist.py b/modules/sfp_tool_dnstwist.pyindex 05cb6268..ef3944cc 100644--- a/modules/sfp_tool_dnstwist.py+++ b/modules/sfp_tool_dnstwist.py@@ -29,7 +29,7 @@ class sfp_tool_dnstwist(SpiderFootPlugin):# Option descriptionsoptdescs = {- 'pythonpath': "Path to Python interpreter to use for DNSTwist. If just 'python' then it should be in your PATH.",+ 'pythonpath': "Path to Python interpreter to use for DNSTwist. If just 'python' then it must be in your PATH.",'dnstwistpath': "Path to the where the dnstwist.py file lives. Must be set."}@@ -70,6 +70,8 @@ class sfp_tool_dnstwist(SpiderFootPlugin):if eventData in self.results:self.sf.debug("Skipping " + eventData + " as already scanned.")return None+ else:+ self.results[eventData] = Trueif not self.opts['dnstwistpath']:self.sf.error("You enabled sfp_tool_dnstwist but did not set a path to the tool!", False)diff --git a/modules/sfp_whois.py b/modules/sfp_whois.pyindex 8d5f61fb..3ac9a596 100644--- a/modules/sfp_whois.py+++ b/modules/sfp_whois.py@@ -12,6 +12,8 @@# -------------------------------------------------------------------------------import whois+import ipwhois+from netaddr import IPAddressfrom sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEventclass sfp_whois(SpiderFootPlugin):@@ -29,7 +31,6 @@ class sfp_whois(SpiderFootPlugin):def setup(self, sfc, userOpts=dict()):self.sf = sfc-self.results = dict()for opt in userOpts.keys():@@ -62,11 +63,20 @@ class sfp_whois(SpiderFootPlugin):self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)try:- #whoisdata = pythonwhois.net.get_whois_raw(eventData)- whoisdata = whois.whois(eventData)- if whoisdata:- data = whoisdata.text+ data = None+ if eventName != "NETBLOCK_OWNER":+ whoisdata = whois.whois(eventData)+ if whoisdata:+ data = whoisdata.textelse:+ qry = eventData.split("/")[0]+ ip = IPAddress(qry) + 1+ self.sf.debug("Querying for IP ownership of " + str(ip))+ r = ipwhois.IPWhois(ip)+ whoisdata = r.lookup_rdap(depth=1)+ if whoisdata:+ data = str(whoisdata)+ if not data:self.sf.error("Unable to perform WHOIS on " + eventData + ": " + str(e), False)return Noneexcept BaseException as e:diff --git a/requirements.txt b/requirements.txtindex 5fbfeed9..4ea0d8fd 100644--- a/requirements.txt+++ b/requirements.txt@@ -1,7 +1,9 @@-CherryPy==5.1.0-M2Crypto==0.23.0-Mako==1.0.4-beautifulsoup4==4.4.1-lxml==3.4.4-netaddr==0.7.18-requests>=2.20.0+CherryPy>=14.0.0+M2Crypto>=0.29.0+Mako>=1.0.4+beautifulsoup4>=4.4.1+lxml>=3.4.4+netaddr>=0.7.18+requests>=2.20.0+ipwhois==1.0.0+ipaddr>=2.2.0diff --git a/setup.py b/setup.pyindex aa9cf7c6..09ded4ca 100644--- a/setup.py+++ b/setup.py@@ -8,7 +8,7 @@ setup("py2exe": {"packages": ["modules", "ext.dns", "sflib", "sfwebui", "sfdb", "mako","cherrypy", "M2Crypto", "netaddr", "ext.socks", "ext.PyPDF2",- "ext.openxmllib", "ext.stem",+ "ext.openxmllib", "ext.stem", "ext.whois","ext.phonenumbers", "ext.gexf", "bs4", "requests" ],"bundle_files": 1,"compressed": True,diff --git a/sf.py b/sf.pyindex f1736d20..d4e7d6f9 100755--- a/sf.py+++ b/sf.py@@ -24,8 +24,9 @@ cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspif cmd_subfolder not in sys.path:sys.path.insert(0, cmd_subfolder)-deps = ['M2Crypto', 'netaddr', 'dns', 'cherrypy', 'mako', 'socks',- 'PyPDF2', 'openxmllib', 'stem', 'bs4', 'gexf', 'phonenumbers']+deps = ['M2Crypto', 'netaddr', 'dns', 'cherrypy', 'mako', 'socks', 'whois',+ 'PyPDF2', 'openxmllib', 'stem', 'bs4', 'gexf', 'phonenumbers', 'ipaddr',+ 'ipwhois']for mod in deps:try:if mod.startswith("ext."):@@ -66,6 +67,7 @@ from sfscan import SpiderFootScannersfConfig = {'_debug': False, # Debug'__logging': True, # Logging in general+ '__outputfilter': None, # Event types to filter from modules' output'__blocknotif': False, # Block notifications'_fatalerrors': False,'_useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0', # User-Agent to use for HTTP requests@@ -131,13 +133,16 @@ if __name__ == '__main__':p.add_argument("-m", metavar="mod1,mod2,...", type=str, help="Modules to enable.")p.add_argument("-M", "--modules", action='store_true', help="List available modules.")p.add_argument("-s", metavar="TARGET", help="Target for the scan.")- p.add_argument("-t", metavar="type1,type2,...", type=str, help="Event types to enable.")+ p.add_argument("-t", metavar="type1,type2,...", type=str, help="Event types to collect.")p.add_argument("-T", "--types", action='store_true', help="List available event types.")p.add_argument("-o", metavar="tab|csv|json", type=str, help="Output format. Tab is default.")p.add_argument("-n", action='store_true', help="Strip newlines from data.")+ p.add_argument("-r", action='store_true', help="Include the source data field in tab/csv output.")p.add_argument("-S", metavar="LENGTH", type=int, help="Maximum data length to display. By default, all data is shown.")+ p.add_argument("-D", action='store_true', help="Delimter to use for CSV output. Default is ,.")p.add_argument("-f", action='store_true', help="Filter out other event types that weren't requested with -t.")p.add_argument("-F", metavar="FILTER", type=str, help="Filter out a set of event types.")+ p.add_argument("-x", action='store_true', help="STRICT MODE. Means that only modules consuming your target type will be enabled and if -t was specified, only those events will be consumed by modules. This overrides -t and -m options.")p.add_argument("-q", action='store_true', help="Disable logging.")args = p.parse_args()@@ -214,6 +219,22 @@ if __name__ == '__main__':print "You must specify a target when running in scan mode. Try sf.py --help for guidance."sys.exit(-1)+ if args.x and not args.t:+ print "-x can only be used with -t. Use --help for guidance."+ sys.exit(-1)++ if args.x and args.m:+ print "-x can only be used with -t and not with -m. Use --help for guidance."+ sys.exit(-1)++ if args.r and (args.o and args.o not in ["tab", "csv"]):+ print "-r can only be used when your output format is tab or csv."+ sys.exit(-1)++ if args.D and args.o != "csv":+ print "-D can only be used when using the csv output format."+ sys.exit(-1)+target = args.stargetType = sf.targetType(args.s)@@ -233,6 +254,7 @@ if __name__ == '__main__':modlist = sf.modulesProducing(types)newmods = deepcopy(modlist)newmodcpy = deepcopy(newmods)+# 2. For each type those modules consume, get modules producingwhile len(newmodcpy) > 0:for etype in sf.eventsToModules(newmodcpy):@@ -270,8 +292,30 @@ if __name__ == '__main__':sfConfig['__modules__']['sfp__stor_stdout']['opts']['_requested'] = args.t.split(",")if args.n:sfConfig['__modules__']['sfp__stor_stdout']['opts']['_stripnewline'] = True+ if args.r:+ sfConfig['__modules__']['sfp__stor_stdout']['opts']['_showsource'] = Trueif args.S:sfConfig['__modules__']['sfp__stor_stdout']['opts']['_maxlength'] = args.S+ if args.x:+ tmodlist = list()+ modlist = list()+ xmods = sf.modulesConsuming([targetType])+ for mod in xmods:+ if mod not in modlist:+ tmodlist.append(mod)++ # Remove any modules not producing the type requested+ rtypes = args.t.split(",")+ for mod in tmodlist:+ for r in rtypes:+ if not sfModules[mod]['provides']:+ continue+ if r in sfModules[mod].get('provides', []) and mod not in modlist:+ modlist.append(mod)++ if len(modlist) == 0:+ print "Based on your criteria, no modules were enabled."+ sys.exit(-1)modlist += ["sfp__stor_db", "sfp__stor_stdout"]@@ -287,6 +331,10 @@ if __name__ == '__main__':else:cfg['_debug'] = False+ # If strict mode is enabled, filter the output from modules.+ if args.x and args.t:+ cfg['__outputfilter'] = args.t.split(",")+t = SpiderFootScanner(target, target, targetType, scanId,modlist, cfg, dict())t.daemon = Truediff --git a/sflib.py b/sflib.pyindex 3fcd3ccf..8adaf801 100644--- a/sflib.py+++ b/sflib.py@@ -379,7 +379,7 @@ class SpiderFoot:else:self._dblog("DEBUG", message, modName)if self.opts.get('__logstdout'):- print "[d] " + message+ print "[d:" + modName +"] " + messagereturndef myPath(self):@@ -1459,6 +1459,8 @@ class SpiderFootPlugin(object):__scanId__ = None# (Unused) tracking of data sources__dataSource__ = None+ # If set, events not matching this list are dropped+ __outputFilter__ = None# Not really needed in most cases.def __init__(self):@@ -1514,12 +1516,22 @@ class SpiderFootPlugin(object):def registerListener(self, listener):self._listenerModules.append(listener)+ def setOutputFilter(self, types):+ self.__outputFilter__ = types+# Call the handleEvent() method of every other plug-in listening for# events from this plug-in. Remember that those plug-ins will be called# within the same execution context of this thread, not on their own.def notifyListeners(self, sfEvent):eventName = sfEvent.eventType+ if self.__outputFilter__:+ # Be strict about what events to pass on, unless they are+ # the ROOT event or the event type of the target.+ if eventName != 'ROOT' and eventName != self.getTarget().getType() \+ and eventName not in self.__outputFilter__:+ return None+# Convert strings to unicodeif type(sfEvent.data) == str:sfEvent.data = unicode(sfEvent.data, 'utf-8', errors='replace')@@ -1781,7 +1793,8 @@ class SpiderFootEvent(object):'generated': int(self.generated),'type': self.eventType,'data': self.data,- 'module': self.module+ 'module': self.module,+ 'source': self.sourceEvent.data}# Unique hash of this eventdiff --git a/sfscan.py b/sfscan.pyindex 8ae55014..6fd97318 100644--- a/sfscan.py+++ b/sfscan.py@@ -226,6 +226,10 @@ class SpiderFootScanner(threading.Thread):if self.ts.config['_socks1type'] != '':mod._updateSocket(socket)+ # Set up event output filters if requested+ if self.ts.config['__outputfilter']:+ mod.setOutputFilter(self.ts.config['__outputfilter'])+self.ts.sf.status(modName + " module loaded.")# Register listener modules and then start all modules sequentially@@ -260,8 +264,6 @@ class SpiderFootScanner(threading.Thread):psMod.notifyListeners(rootEvent)firstEvent = SpiderFootEvent(self.ts.targetType, self.ts.targetValue,"SpiderFoot UI", rootEvent)-- # If in interactive mode, this needs the storeOnly arg.psMod.notifyListeners(firstEvent)# If in interactive mode, loop through this shared global variable