SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Ability to perform google searches.
Steve Micallef2b8e219057e5
diff --git a/sflib.py b/sflib.pyindex 40cbb4aa..da8818fc 100644--- a/sflib.py+++ b/sflib.py@@ -10,10 +10,14 @@# Licence: GPL#--------------------------------------------------------------------------------import sys+import inspect+import randomimport re+import sys+import time+import urllibimport urllib2-import inspect+class SpiderFoot:# 'options' is a dictionary of options which changes the behaviour@@ -216,6 +220,60 @@ class SpiderFoot:return returnLinks+ # 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 pages before returning, default is 10+ # pause: 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 = self.fetchUrl(seedUrl)+ if firstPage['code'] == "403":+ self.error("Google doesn't like us right now..")+ 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.debug("Next Google URL: " + nextUrl)++ # Wait for a random number of seconds between fetches+ if opts.has_key('pause'):+ pauseSecs = random.randint(4, 15)+ self.debug("Pausing for " + str(pauseSecs))+ time.sleep(pauseSecs)++ nextPage = self.fetchUrl('http://www.google.com' + nextUrl)+ if firstPage['code'] == 403:+ self.error("Google doesn't like us any more..")+ return returnResults++ returnResults[nextUrl] = nextPage['content']+ matches = re.findall("(\/search\S+start=\d+.[^\'\"]*)", nextPage['content'])++ return returnResults+# Fetch a URL, return the response objectdef fetchUrl(self, url, fatal=False):result = {