SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
feat: update sfp_bingsharedip module to use bing api
Amr Awad829aa3b67058
diff --git a/modules/sfp_bingsharedip.py b/modules/sfp_bingsharedip.pyindex 530af161..27e98f7a 100644--- a/modules/sfp_bingsharedip.py+++ b/modules/sfp_bingsharedip.py@@ -12,6 +12,7 @@import reimport socket+import requestsfrom netaddr import IPNetworkfrom sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent@@ -19,21 +20,15 @@ from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEventclass sfp_bingsharedip(SpiderFootPlugin):"""Bing (Shared IPs):Footprint,Investigate,Passive:Search Engines::Search Bing for hosts sharing the same IP."""-# Default options- opts = {- 'cohostsamedomain': False,- 'pages': 20,- 'verify': True,- 'maxcohost': 100- }+ opts = {"cohostsamedomain": False, "pages": 20, "verify": True, "maxcohost": 100}# Option descriptionsoptdescs = {- 'cohostsamedomain': "Treat co-hosted sites on the same target domain as co-hosting?",- 'pages': "How many pages of results to iterate through.",- 'verify': "Verify co-hosts are valid by checking if they still resolve to the shared IP.",- 'maxcohost': "Stop reporting co-hosted sites after this many are found, as it would likely indicate web hosting."+ "cohostsamedomain": "Treat co-hosted sites on the same target domain as co-hosting?",+ "pages": "Number of max bing results to request from api.",+ "verify": "Verify co-hosts are valid by checking if they still resolve to the shared IP.",+ "maxcohost": "Stop reporting co-hosted sites after this many are found, as it would likely indicate web hosting.",}results = dict()@@ -95,7 +90,7 @@ class sfp_bingsharedip(SpiderFootPlugin):self.sf.debug("Ignoring " + eventName + ", from self.")return None- if self.cohostcount > self.opts['maxcohost']:+ if self.cohostcount > self.opts["maxcohost"]:return Noneqrylist = list()@@ -114,44 +109,78 @@ class sfp_bingsharedip(SpiderFootPlugin):if self.checkForStop():return None- results = self.sf.bingIterate("ip:" + ip, dict(limit=self.opts['pages'],- useragent=self.opts['_useragent'],- timeout=self.opts['_fetchtimeout']))- if results is None:- self.sf.info("No data returned from Bing.")- continue-- for key in results.keys():- res = results[key]- pat = re.compile("<h2><a href=\"(\S+)\"", re.IGNORECASE)- matches = re.findall(pat, res)- for match in matches:- self.sf.info("Found something on same IP: " + match)- site = self.sf.urlFQDN(match.lower())- if site not in myres and site != ip:- if not self.opts['cohostsamedomain']:- if self.getTarget().matches(site, includeParents=True):- self.sf.debug("Skipping " + site + " because it is on the same domain.")- continue- if self.opts['verify'] and not self.validateIP(site, ip):- self.sf.debug("Host " + site + " no longer resolves to " + ip)+ endpoint = "https://api.cognitive.microsoft.com/bing/v7.0/search"+ # ToDO: figure out how to add credentials in config:+ key = ""+ response = requests.get(+ endpoint,+ timeout=self.opts["_fetchtimeout"],+ headers={+ "Ocp-Apim-Subscription-Key": key,+ "User-Agent": self.opts["_useragent"],+ },+ params={+ "q": "ip:" + ip,+ "responseFilter": "Webpages",+ "count": self.opts["pages"],+ },+ )++ if response.status_code != 200:+ message = "Failed to talk to Bing API, status code: %s, response: %s".format(+ response.status_code, response.text+ )+ self.error(message)++ urls = [result["url"] for result in response.json()["webPages"]["value"]]++ for url in urls:+ self.sf.info("Found something on same IP: " + url)+ site = self.sf.urlFQDN(url.lower())+ if site not in myres and site != ip:+ if not self.opts["cohostsamedomain"]:+ if self.getTarget().matches(site, includeParents=True):+ self.sf.debug(+ "Skipping "+ + site+ + " because it is on the same domain."+ )continue- # Create an IP Address event stemming from the netblock as the- # link to the co-host.- if eventName == "NETBLOCK_OWNER":- ipe = SpiderFootEvent("IP_ADDRESS", ip, self.__name__, event)- self.notifyListeners(ipe)- evt = SpiderFootEvent("CO_HOSTED_SITE", site, self.__name__, ipe)- self.notifyListeners(evt)- else:- evt = SpiderFootEvent("CO_HOSTED_SITE", site, self.__name__, event)- self.notifyListeners(evt)- self.cohostcount += 1- myres.append(site)-+ if self.opts["verify"] and not self.validateIP(site, ip):+ self.sf.debug("Host " + site + " no longer resolves to " + ip)+ continue+ # Create an IP Address event stemming from the netblock as the+ # link to the co-host.+ if eventName == "NETBLOCK_OWNER":+ ipe = SpiderFootEvent("IP_ADDRESS", ip, self.__name__, event)+ self.notifyListeners(ipe)+ evt = SpiderFootEvent(+ "CO_HOSTED_SITE", site, self.__name__, ipe+ )+ self.notifyListeners(evt)+ else:+ evt = SpiderFootEvent(+ "CO_HOSTED_SITE", site, self.__name__, event+ )+ self.notifyListeners(evt)+ self.cohostcount += 1+ myres.append(site)++ if urls:# Submit the bing results for analysis- evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", results[key],- self.__name__, event)+ bingsearch_url = response.json()["webPages"]["webSearchUrl"]+ response = self.sf.fetchUrl(+ bingsearch_url,+ timeout=self.opts["_fetchtimeout"],+ useragent=self.opts["_useragent"],+ )+ evt = SpiderFootEvent(+ "SEARCH_ENGINE_WEB_CONTENT",+ response["content"],+ self.__name__,+ event,+ )self.notifyListeners(evt)+# End of sfp_bingsharedip class