SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
New modules and cleaned up usage of Google search.
smicallef91c00481d7b4
diff --git a/evtypes.sql b/evtypes.sqlindex 5a596cc4..12897fbc 100644--- a/evtypes.sql+++ b/evtypes.sql@@ -20,6 +20,7 @@ INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('GEOINFO', 'INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('HTTP_CODE', 'HTTP Status Code', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('HUMAN_NAME', 'Human Name', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('INITIAL_TARGET', 'User-Supplied Target', 0);+INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('INTERESTING_FILE', 'Interesting File', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('IP_ADDRESS', 'IP Address', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('IP_SUBNET', 'IP Subnet', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('LINKED_URL_INTERNAL', 'Linked URL - Internal', 0);@@ -51,7 +52,8 @@ INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('SSL_CERTIFIINSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('SSL_CERTIFICATE_MISMATCH', 'SSL Certificate Host Mismatch', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('SSL_CERTIFICATE_EXPIRED', 'SSL Certificate Expired', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('SSL_CERTIFICATE_EXPIRING', 'SSL Certificate Expiring', 0);-INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('TARGET_WEB_CONTENT', 'Target''s Web Content', 1);+INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('TARGET_WEB_CONTENT', 'Web Content', 1);+INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('TARGET_WEB_COOKIE', 'Cookies', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('TCP_PORT_OPEN', 'Open TCP Port', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('TCP_PORT_OPEN_BANNER', 'Open TCP Port Banner', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('URL_FORM', 'URL (Form)', 0);diff --git a/modules/sfp_cookie.py b/modules/sfp_cookie.pynew file mode 100644index 00000000..581e10de--- /dev/null+++ b/modules/sfp_cookie.py@@ -0,0 +1,74 @@+#-------------------------------------------------------------------------------+# Name: sfp_cookie+# Purpose: SpiderFoot plug-in for extracting cookies from HTTP headers.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 06/04/2014+# Copyright: (c) Steve Micallef 2014+# Licence: GPL+#-------------------------------------------------------------------------------++import sys+import re+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent++# SpiderFoot standard lib (must be initialized in setup)+sf = None++class sfp_cookie(SpiderFootPlugin):+ """Cookies:Extract Cookies from HTTP headers."""++ # Default options+ opts = { }++ # Target+ baseDomain = None # calculated from the URL in setup+ results = dict()++ def setup(self, sfc, target, userOpts=dict()):+ global sf++ sf = sfc+ self.baseDomain = target+ self.results = dict()++ for opt in userOpts.keys():+ self.opts[opt] = userOpts[opt]++ # What events is this module interested in for input+ def watchedEvents(self):+ return ["WEBSERVER_HTTPHEADERS"]++ # What events this module produces+ # This is to support the end user in selecting modules based on events+ # produced.+ def producedEvents(self):+ return [ "TARGET_WEB_COOKIE" ]++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data+ parentEvent = event.sourceEvent+ eventSource = event.sourceEvent.data++ sf.debug("Received event, " + eventName + ", from " + srcModuleName)+ if self.results.has_key(eventSource):+ return None+ else:+ self.results[eventSource] = True++ if not sf.urlBaseUrl(eventSource).endswith(self.baseDomain):+ sf.debug("Not collecting cookies from external sites.")+ return None++ if eventData.has_key('set-cookie'):+ evt = SpiderFootEvent("TARGET_WEB_COOKIE", eventData['set-cookie'],+ self.__name__, parentEvent)+ self.notifyListeners(evt)++ sf.info("Found cookie: " + eventData['set-cookie'] + " (" + eventSource + ")")++# End of sfp_cookie classdiff --git a/modules/sfp_files.py b/modules/sfp_files.pynew file mode 100644index 00000000..6b7aa3c9--- /dev/null+++ b/modules/sfp_files.py@@ -0,0 +1,106 @@+#-------------------------------------------------------------------------------+# Name: sfp_files+# Purpose: Searches Google for files of potential interest.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 06/04/2014+# Copyright: (c) Steve Micallef 2014+# Licence: GPL+#-------------------------------------------------------------------------------++import sys+import random+import re+import time+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent++# SpiderFoot standard lib (must be initialized in setup)+sf = None++class sfp_files(SpiderFootPlugin):+ """Files:Identifies potential files of interest, e.g. office documents."""++ # Default options+ opts = {+ 'pages': 20, # Number of google results pages to iterate+ 'fileexts': [ "doc", "docx", "ppt", "pptx", "pdf", "zip", "txt",+ "rtf", "old", "tmp" ]+ }++ # Option descriptions+ optdescs = {+ 'pages': "Number of search results pages to iterate through.",+ 'fileexts': "File extensions of files you consider interesting."+ }++ # Target+ baseDomain = None+ results = list()++ def setup(self, sfc, target, userOpts=dict()):+ global sf++ sf = sfc+ self.baseDomain = target+ 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 None++ # What events this module produces+ # This is to support the end user in selecting modules based on events+ # produced.+ def producedEvents(self):+ return [ "SEARCH_ENGINE_WEB_CONTENT", "INTERESTING_FILE" ]++ def start(self):+ for fileExt in self.opts['fileexts']:+ # Sites hosted on the domain+ pages = sf.googleIterate("site:" + self.baseDomain + "+" + \+ "%2Bext:" + fileExt, dict(limit=self.opts['pages'],+ useragent=self.opts['_useragent'], timeout=self.opts['_fetchtimeout']))++ if pages == None:+ sf.info("No results returned from Google for " + fileExt + " files.")+ continue++ for page in pages.keys():+ if page in self.results:+ continue+ else:+ self.results.append(page)++ # Check if we've been asked to stop+ if self.checkForStop():+ return None++ # Submit the google results for analysis+ evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", pages[page], self.__name__)+ self.notifyListeners(evt)++ # Fetch the PasteBin page+ links = sf.parseLinks(page, pages[page], self.baseDomain)+ if len(links) == 0:+ continue++ for link in links:+ if link in self.results:+ continue+ else:+ self.results.append(link)++ sf.debug("Found a link: " + link)+ if sf.urlBaseUrl(link).endswith(self.baseDomain) and \+ "." + fileExt in link:+ if self.checkForStop():+ return None++ evt = SpiderFootEvent("INTERESTING_FILE", link, self.__name__)+ self.notifyListeners(evt)++# End of sfp_files classdiff --git a/modules/sfp_googlesearch.py b/modules/sfp_googlesearch.pyindex 1001ec15..e98ac387 100644--- a/modules/sfp_googlesearch.py+++ b/modules/sfp_googlesearch.py@@ -57,77 +57,11 @@ class sfp_googlesearch(SpiderFootPlugin):def producedEvents(self):return [ "LINKED_URL_INTERNAL", "SEARCH_ENGINE_WEB_CONTENT" ]- # Scrape Google for content, starting at startUrl and iterating through- # results based on options supplied. Will return a dictionary of all pages- # fetched and their contents {page => content}.- # Options accepted:- # limit: number of search result pages before returning, default is 10- # nopause: don't randomly pause between fetches- def googleIterate(self, searchString, opts=dict()):- limit = 10- fetches = 0- returnResults = dict()-- if opts.has_key('limit'):- limit = opts['limit']-- # We attempt to make the URL look as authentically human as possible- seedUrl = "http://www.google.com/search?q={0}".format(searchString) + \- "&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a"- firstPage = sf.fetchUrl(seedUrl, timeout=self.opts['_fetchtimeout'],- useragent=self.opts['_useragent'])- if firstPage['code'] == "403":- sf.error("Google doesn't like us right now..", False)- return None-- if firstPage['content'] == None:- sf.error("Failed to fetch content from Google.", False)- return None-- returnResults[seedUrl] = firstPage['content']-- matches = re.findall("(\/search\S+start=\d+.[^\'\"]*sa=N)", firstPage['content'])- while matches > 0 and fetches < limit:- nextUrl = None- fetches += 1- for match in matches:- # Google moves in increments of 10- if "start=" + str(fetches*10) in match:- nextUrl = match.replace("&", "&")-- if nextUrl == None:- sf.debug("Nothing left to scan for in Google results.")- return returnResults- sf.info("Next Google URL: " + nextUrl)-- # Wait for a random number of seconds between fetches- if not opts.has_key('nopause'):- pauseSecs = random.randint(4, 15)- sf.info("Pausing for " + str(pauseSecs))- time.sleep(pauseSecs)-- # Check if we've been asked to stop- if self.checkForStop():- return None-- nextPage = sf.fetchUrl('http://www.google.com' + nextUrl,- timeout=self.opts['_fetchtimeout'], useragent=self.opts['_useragent'])- if firstPage['code'] == 403:- sf.error("Google doesn't like us any more..", False)- return returnResults-- if nextPage['content'] == None:- sf.error("Failed to fetch subsequent content from Google.", False)- return returnResults-- returnResults[nextUrl] = nextPage['content']- matches = re.findall("(\/search\S+start=\d+.[^\'\"]*)", nextPage['content'], re.IGNORECASE)-- return returnResults-def start(self):# Sites hosted on the domain- pages = self.googleIterate("site:" + self.baseDomain, dict(limit=self.opts['pages']))+ pages = sf.googleIterate("site:" + self.baseDomain,+ dict(limit=self.opts['pages'], useragent=self.opts['_useragent'],+ timeout=self.opts['_fetchtimeout']))if pages == None:sf.info("No results returned from Google.")return Nonediff --git a/modules/sfp_malcheck.py b/modules/sfp_malcheck.pyindex e9d4fe1e..6dcba7fe 100644--- a/modules/sfp_malcheck.py+++ b/modules/sfp_malcheck.py@@ -155,6 +155,22 @@ malchecks = {'type': 'list','checks': [ 'ip', 'netblock' ],'url': 'http://www.openbl.org/lists/base.txt'+ },+ 'ThreatExpert.com Database': {+ 'id': 'threatexpert',+ 'type': 'query',+ 'checks': [ 'ip', 'domain' ],+ 'url': 'http://www.threatexpert.com/reports.aspx?find={0}&tf=3',+ 'badregex': [ '.*<strong>Findings</strong>.*' ],+ 'goodregex': []+ },+ 'TotalHash.com Database': {+ 'id': 'totalhash',+ 'type': 'query',+ 'checks': [ 'ip', 'domain' ],+ 'url': 'http://totalhash.com/search/dnsrr:*{0}%20or%20ip:{0}',+ 'badregex': [ '.*<a href=\"/analysis.*' ],+ 'goodregex': []}}@@ -183,6 +199,8 @@ class sfp_malcheck(SpiderFootPlugin):'tornodes': True,'alienvault': True,'openbl': True,+ 'totalhash': True,+ 'threatexpert': True,'aaacheckaffiliates': True, # prefix with aaa so they appear on the top of the UI list'aaacheckcohosts': True,'aaacacheperiod': 18,@@ -212,6 +230,8 @@ class sfp_malcheck(SpiderFootPlugin):'isc': 'Enable Internet Storm Center check?','alienvault': 'Enable AlienVault IP Reputation check?','openbl': 'Enable OpenBL.org Blacklist check?',+ 'totalhash': 'Enable totalhash.com check?',+ 'threatexpert': 'Enable threatexpert.com check?','aaacheckaffiliates': "Apply checks to affiliates?",'aaacheckcohosts': "Apply checks to sites found to be co-hosted on the target's IP?",'aaacacheperiod': "Hours to cache list data before re-fetching.",diff --git a/modules/sfp_pastebin.py b/modules/sfp_pastebin.pyindex d48c5b8d..5069a2c1 100644--- a/modules/sfp_pastebin.py+++ b/modules/sfp_pastebin.py@@ -56,79 +56,12 @@ class sfp_pastebin(SpiderFootPlugin):def producedEvents(self):return [ "SEARCH_ENGINE_WEB_CONTENT", "PASTEBIN_CONTENT" ]- # Scrape Google for content, starting at startUrl and iterating through- # results based on options supplied. Will return a dictionary of all pages- # fetched and their contents {page => content}.- # Options accepted:- # limit: number of search result pages before returning, default is 10- # nopause: don't randomly pause between fetches- def googleIterate(self, searchString, opts=dict()):- limit = 10- fetches = 0- returnResults = dict()-- if opts.has_key('limit'):- limit = opts['limit']-- # We attempt to make the URL look as authentically human as possible- seedUrl = "http://www.google.com/search?q={0}".format(searchString) + \- "&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a"- firstPage = sf.fetchUrl(seedUrl, timeout=self.opts['_fetchtimeout'],- useragent=self.opts['_useragent'])- if firstPage['code'] == "403":- sf.error("Google doesn't like us right now..", False)- return None-- if firstPage['content'] == None:- sf.error("Failed to fetch content from Google for PasteBin.", False)- return None-- returnResults[seedUrl] = firstPage['content']-- matches = re.findall("(\/search\S+start=\d+.[^\'\"]*sa=N)", firstPage['content'])- while matches > 0 and fetches < limit:- nextUrl = None- fetches += 1- for match in matches:- # Google moves in increments of 10- if "start=" + str(fetches*10) in match:- nextUrl = match.replace("&", "&")-- if nextUrl == None:- sf.debug("Nothing left to scan for in Google PasteBin results.")- return returnResults- sf.info("Next Google URL: " + nextUrl)-- # Wait for a random number of seconds between fetches- if not opts.has_key('nopause'):- pauseSecs = random.randint(4, 15)- sf.info("Pausing for " + str(pauseSecs))- time.sleep(pauseSecs)-- # Check if we've been asked to stop- if self.checkForStop():- return None-- nextPage = sf.fetchUrl('http://www.google.com' + nextUrl,- timeout=self.opts['_fetchtimeout'], useragent=self.opts['_useragent'])- if firstPage['code'] == 403:- sf.error("Google doesn't like us any more..", False)- return returnResults-- if nextPage['content'] == None:- sf.error("Failed to fetch subsequent content from Google PasteBin search.",- False)- return returnResults-- returnResults[nextUrl] = nextPage['content']- matches = re.findall("(\/search\S+start=\d+.[^\'\"]*)", nextPage['content'], re.IGNORECASE)-- return returnResults-def start(self):# Sites hosted on the domain- pages = self.googleIterate("site:pastebin.com+\"" + \- self.baseDomain + "\"", dict(limit=self.opts['pages']))+ pages = sf.googleIterate("site:pastebin.com+\"" + \+ self.baseDomain + "\"", dict(limit=self.opts['pages'],+ useragent=self.opts['_useragent'], timeout=self.opts['_fetchtimeout']))+if pages == None:sf.info("No results returned from Google PasteBin search.")return Nonediff --git a/sfdb.py b/sfdb.pyindex 473aeaf6..c92f7e88 100644--- a/sfdb.py+++ b/sfdb.py@@ -93,6 +93,7 @@ class SpiderFootDb:"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('HTTP_CODE', 'HTTP Status Code', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('HUMAN_NAME', 'Human Name', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('INITIAL_TARGET', 'User-Supplied Target', 0)",+ "INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('INTERESTING_FILE', 'Interesting File', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('IP_ADDRESS', 'IP Address', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('IP_SUBNET', 'IP Address - Subnet', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('NETBLOCK', 'Netblock Ownership', 0)",@@ -124,7 +125,8 @@ class SpiderFootDb:"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('SSL_CERTIFICATE_EXPIRED', 'SSL Certificate Expired', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('SSL_CERTIFICATE_EXPIRING', 'SSL Certificate Expiring', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('SSL_CERTIFICATE_RAW', 'SSL Certificate - Raw Data', 1)",- "INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('TARGET_WEB_CONTENT', 'Target''s Web Content', 1)",+ "INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('TARGET_WEB_CONTENT', 'Web Content', 1)",+ "INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('TARGET_WEB_COOKIE', 'Cookies', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('TCP_PORT_OPEN', 'Open TCP Port', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('TCP_PORT_OPEN_BANNER', 'Open TCP Port Banner', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('URL_FORM', 'URL (Form)', 0)",diff --git a/sflib.py b/sflib.pyindex 965c6071..58bcfa33 100644--- a/sflib.py+++ b/sflib.py@@ -725,6 +725,73 @@ class SpiderFoot:self.debug(target + " does not have wildcard DNS.")return False+ # Scrape Google for content, starting at startUrl and iterating through+ # results based on options supplied. Will return a dictionary of all pages+ # fetched and their contents {page => content}.+ # Options accepted:+ # limit: number of search result pages before returning, default is 10+ # nopause: don't randomly pause between fetches+ # useragent: User-Agent string to use+ # timeout: Fetch timeout+ def googleIterate(self, searchString, opts=dict()):+ limit = 10+ fetches = 0+ returnResults = dict()++ if opts.has_key('limit'):+ limit = opts['limit']++ # We attempt to make the URL look as authentically human as possible+ seedUrl = "http://www.google.com/search?q={0}".format(searchString) + \+ "&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a"+ firstPage = self.fetchUrl(seedUrl, timeout=opts['timeout'],+ useragent=opts['useragent'])+ if firstPage['code'] == "403":+ self.error("Google doesn't like us right now..", False)+ return None++ if firstPage['content'] == None:+ self.error("Failed to fetch content from Google.", False)+ return None++ returnResults[seedUrl] = firstPage['content']+ matches = re.findall("(\/search\S+start=\d+.[^\'\"]*sa=N)", firstPage['content'])++ while matches > 0 and fetches < limit:+ nextUrl = None+ fetches += 1+ for match in matches:+ # Google moves in increments of 10+ if "start=" + str(fetches*10) in match:+ nextUrl = match.replace("&", "&")++ if nextUrl == None:+ self.debug("Nothing left to scan for in Google results.")+ return returnResults+ self.info("Next Google URL: " + nextUrl)++ # Wait for a random number of seconds between fetches+ if not opts.has_key('nopause'):+ pauseSecs = random.randint(4, 15)+ self.info("Pausing for " + str(pauseSecs))+ time.sleep(pauseSecs)++ nextPage = self.fetchUrl('http://www.google.com' + nextUrl,+ timeout=opts['timeout'], useragent=opts['useragent'])+ if firstPage['code'] == 403:+ self.error("Google doesn't like us any more..", False)+ return returnResults++ if nextPage['content'] == None:+ self.error("Failed to fetch subsequent content from Google.", False)+ return returnResults++ returnResults[nextUrl] = nextPage['content']+ matches = re.findall("(\/search\S+start=\d+.[^\'\"]*)", nextPage['content'], re.IGNORECASE)++ return returnResults++## SpiderFoot plug-in module base class#