SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Switch some modules to produce IP_ADDRESS events from netblocks, and replace SEACH_ENGINE_WEB_CONTENT with RAW_RIR_DATA.
smicallefaff397546cec
diff --git a/modules/sfp_alienvault.py b/modules/sfp_alienvault.pyindex c3bb548a..493f39af 100644--- a/modules/sfp_alienvault.py+++ b/modules/sfp_alienvault.py@@ -61,7 +61,7 @@ class sfp_alienvault(SpiderFootPlugin):# What events is this module interested in for inputdef watchedEvents(self):- return ["IP_ADDRESS", "AFFILIATE_IPADDR",+ return ["IP_ADDRESS", "AFFILIATE_IPADDR","NETBLOCK_OWNER", "NETBLOCK_MEMBER"]# What events this module produces@@ -87,7 +87,7 @@ class sfp_alienvault(SpiderFootPlugin):'Accept': 'application/json','X-OTX-API-KEY': self.opts['api_key']}- res = self.sf.fetchUrl(url, timeout=self.opts['_fetchtimeout'],+ res = self.sf.fetchUrl(url, timeout=self.opts['_fetchtimeout'],useragent="SpiderFoot", headers=headers)if res['code'] == "403":@@ -221,7 +221,15 @@ class sfp_alienvault(SpiderFootPlugin):continueexcept BaseException as e:self.sf.debug("Couldn't parse date from AlienVault so assuming it's OK.")- e = SpiderFootEvent(evtType, descr, self.__name__, event)++ # For netblocks, we need to create the IP address event so that+ # the threat intel event is more meaningful.+ if eventName.startswith('NETBLOCK_'):+ pevent = SpiderFootEvent("IP_ADDRESS", addr, self.__name__, event)+ self.notifyListeners(pevent)+ else:+ pevent = event+ e = SpiderFootEvent(evtType, descr, self.__name__, pevent)self.notifyListeners(e)# End of sfp_alienvault classdiff --git a/modules/sfp_censys.py b/modules/sfp_censys.pyindex 23fcf7af..df3f5b39 100644--- a/modules/sfp_censys.py+++ b/modules/sfp_censys.py@@ -56,7 +56,7 @@ class sfp_censys(SpiderFootPlugin):# What events this module producesdef producedEvents(self):- return ["BGP_AS_MEMBER", "TCP_PORT_OPEN", "OPERATING_SYSTEM",+ return ["BGP_AS_MEMBER", "TCP_PORT_OPEN", "OPERATING_SYSTEM","WEBSERVER_HTTPHEADERS", "NETBLOCK_MEMBER", "GEOINFO",'RAW_RIR_DATA']@@ -67,7 +67,7 @@ class sfp_censys(SpiderFootPlugin):querytype = "ipv4/{0}"if querytype == "host":querytype = "websites/{0}"-+secret = self.opts['censys_api_key_uid'] + ':' + self.opts['censys_api_key_secret']b64_val = base64.b64encode(secret.encode('utf-8'))headers = {@@ -154,7 +154,15 @@ class sfp_censys(SpiderFootPlugin):self.sf.debug("Found results in Censys.io")- e = SpiderFootEvent("RAW_RIR_DATA", str(rec), self.__name__, event)+ # For netblocks, we need to create the IP address event so that+ # the threat intel event is more meaningful.+ if eventName.startswith('NETBLOCK_'):+ pevent = SpiderFootEvent("IP_ADDRESS", addr, self.__name__, event)+ self.notifyListeners(pevent)+ else:+ pevent = event++ e = SpiderFootEvent("RAW_RIR_DATA", str(rec), self.__name__, pevent)self.notifyListeners(e)try:@@ -170,21 +178,21 @@ class sfp_censys(SpiderFootPlugin):if 'location' in rec:location = ', '.join([_f for _f in [rec['location'].get('city'), rec['location'].get('province'), rec['location'].get('postal_code'), rec['location'].get('country')] if _f])if location:- e = SpiderFootEvent("GEOINFO", location, self.__name__, event)+ e = SpiderFootEvent("GEOINFO", location, self.__name__, pevent)self.notifyListeners(e)if 'headers' in rec:dat = json.dumps(rec['headers'], ensure_ascii=False)- e = SpiderFootEvent("WEBSERVER_HTTPHEADERS", dat, self.__name__, event)+ e = SpiderFootEvent("WEBSERVER_HTTPHEADERS", dat, self.__name__, pevent)self.notifyListeners(e)if 'autonomous_system' in rec:dat = str(rec['autonomous_system']['asn'])- e = SpiderFootEvent("BGP_AS_MEMBER", dat, self.__name__, event)+ e = SpiderFootEvent("BGP_AS_MEMBER", dat, self.__name__, pevent)self.notifyListeners(e)dat = rec['autonomous_system']['routed_prefix']- e = SpiderFootEvent("NETBLOCK_MEMBER", dat, self.__name__, event)+ e = SpiderFootEvent("NETBLOCK_MEMBER", dat, self.__name__, pevent)self.notifyListeners(e)if 'protocols' in rec:@@ -192,15 +200,15 @@ class sfp_censys(SpiderFootPlugin):if 'ip' not in rec:continuedat = rec['ip'] + ":" + p.split("/")[0]- e = SpiderFootEvent("TCP_PORT_OPEN", dat, self.__name__, event)+ e = SpiderFootEvent("TCP_PORT_OPEN", dat, self.__name__, pevent)self.notifyListeners(e)if 'metadata' in rec:if 'os_description' in rec['metadata']:dat = rec['metadata']['os_description']- e = SpiderFootEvent("OPERATING_SYSTEM", dat, self.__name__, event)+ e = SpiderFootEvent("OPERATING_SYSTEM", dat, self.__name__, pevent)self.notifyListeners(e)except BaseException as e:self.sf.error("Error encountered processing record for " + eventData + " (" + str(e) + ")", False)-+# End of sfp_censys classdiff --git a/modules/sfp_darksearch.py b/modules/sfp_darksearch.pyindex d550a0ee..c12b2794 100644--- a/modules/sfp_darksearch.py+++ b/modules/sfp_darksearch.py@@ -49,7 +49,7 @@ class sfp_darksearch(SpiderFootPlugin):return ['DOMAIN_NAME', 'HUMAN_NAME', 'EMAILADDR']def producedEvents(self):- return ['DARKNET_MENTION_URL', 'DARKNET_MENTION_CONTENT', 'SEARCH_ENGINE_WEB_CONTENT']+ return ['DARKNET_MENTION_URL', 'DARKNET_MENTION_CONTENT', 'RAW_RIR_DATA']# https://darksearch.io/apidocdef query(self, qry, page):@@ -121,7 +121,7 @@ class sfp_darksearch(SpiderFootPlugin):if result is None:continue- evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", str(result), self.__name__, event)+ evt = SpiderFootEvent("RAW_RIR_DATA", str(result), self.__name__, event)self.notifyListeners(evt)link = result.get('link')diff --git a/modules/sfp_fraudguard.py b/modules/sfp_fraudguard.pyindex 688b6775..fbf99e28 100644--- a/modules/sfp_fraudguard.py+++ b/modules/sfp_fraudguard.py@@ -76,7 +76,7 @@ class sfp_fraudguard(SpiderFootPlugin):'Authorization': "Basic " + token.decode('utf-8')}- res = self.sf.fetchUrl(fraudguard_url, timeout=self.opts['_fetchtimeout'],+ res = self.sf.fetchUrl(fraudguard_url , timeout=self.opts['_fetchtimeout'],useragent="SpiderFoot", headers=headers)if res['code'] in [ "400", "429", "500", "403" ]:@@ -156,14 +156,23 @@ class sfp_fraudguard(SpiderFootPlugin):if self.opts['age_limit_days'] > 0 and created_ts < age_limit_ts:self.sf.debug("Record found but too old, skipping.")continue++ # For netblocks, we need to create the IP address event so that+ # the threat intel event is more meaningful.+ if eventName.startswith('NETBLOCK_'):+ pevent = SpiderFootEvent("IP_ADDRESS", addr, self.__name__, event)+ self.notifyListeners(pevent)+ else:+ pevent = event+if "unknown" not in [rec['country'], rec['state'], rec['city']]:dat = rec['country'] + ", " + rec['state'] + ", " + rec['city']- e = SpiderFootEvent("GEOINFO", dat, self.__name__, event)+ e = SpiderFootEvent("GEOINFO", dat, self.__name__, pevent)self.notifyListeners(e)if rec.get('threat') != "unknown":dat = rec['threat'] + " (risk level: " + rec['risk_level'] + ") [" + eventData + "]"- e = SpiderFootEvent("MALICIOUS_" + rtype, dat, self.__name__, event)+ e = SpiderFootEvent("MALICIOUS_" + rtype, dat, self.__name__, pevent)self.notifyListeners(e)-+# End of sfp_fraudguard classdiff --git a/modules/sfp_googlemaps.py b/modules/sfp_googlemaps.pyindex 8f8ce4f0..8a1fb020 100644--- a/modules/sfp_googlemaps.py+++ b/modules/sfp_googlemaps.py@@ -45,7 +45,7 @@ class sfp_googlemaps(SpiderFootPlugin):# This is to support the end user in selecting modules based on events# produced.def producedEvents(self):- return ["PHYSICAL_ADDRESS", "PHYSICAL_COORDINATES"]+ return ["PHYSICAL_ADDRESS", "PHYSICAL_COORDINATES", "RAW_RIR_DATA"]# Handle events sent to this moduledef handleEvent(self, event):@@ -71,14 +71,14 @@ class sfp_googlemaps(SpiderFootPlugin):self.results[eventData] = Trueres = self.sf.fetchUrl("https://maps.googleapis.com/maps/api/geocode/json?address=" + \- eventData + "&key=" + self.opts['api_key'],- timeout=self.opts['_fetchtimeout'],+ eventData + "&key=" + self.opts['api_key'],+ timeout=self.opts['_fetchtimeout'],useragent=self.opts['_useragent'])if res['content'] is None:self.sf.info("No location info found for " + eventData)return None- evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", res['content'],+ evt = SpiderFootEvent("RAW_RIR_DATA", res['content'],self.__name__, event)self.notifyListeners(evt)@@ -90,12 +90,12 @@ class sfp_googlemaps(SpiderFootPlugin):if 'geometry' in data:lat = str(data['geometry']['location']['lat'])lng = str(data['geometry']['location']['lng'])- evt = SpiderFootEvent("PHYSICAL_COORDINATES", lat + "," + lng,+ evt = SpiderFootEvent("PHYSICAL_COORDINATES", lat + "," + lng,self.__name__, event)self.notifyListeners(evt)if 'formatted_address' in data:- evt = SpiderFootEvent("PHYSICAL_ADDRESS", data['formatted_address'],+ evt = SpiderFootEvent("PHYSICAL_ADDRESS", data['formatted_address'],self.__name__, event)self.notifyListeners(evt)except Exception as e:diff --git a/modules/sfp_hackertarget.py b/modules/sfp_hackertarget.pyindex 1f6a881f..8f2167ec 100644--- a/modules/sfp_hackertarget.py+++ b/modules/sfp_hackertarget.py@@ -238,7 +238,7 @@ class sfp_hackertarget(SpiderFootPlugin):if strdata.endswith("."):hosts.append(strdata[:-1])else:- hosts.append(strdata + "." + name)+ hosts.append(strdata)for host in set(hosts):if self.getTarget().matches(host, includeChildren=True, includeParents=True):@@ -280,6 +280,8 @@ class sfp_hackertarget(SpiderFootPlugin):return Nonehosts = self.reverseIpLookup(ip)+ if not hosts:+ continuefor h in hosts:if " " in h:@@ -311,22 +313,30 @@ class sfp_hackertarget(SpiderFootPlugin):myres.append(h.lower())self.cohostcount += 1+ # For netblocks, we need to create the IP address event so that+ # the threat intel event is more meaningful.+ if eventName.startswith('NETBLOCK_'):+ pevent = SpiderFootEvent("IP_ADDRESS", ip, self.__name__, event)+ self.notifyListeners(pevent)+ else:+ pevent = event+if self.opts.get('http_headers', True):http_headers = self.httpHeaders(ip)if http_headers is not None:- e = SpiderFootEvent('WEBSERVER_HTTPHEADERS', json.dumps(http_headers), self.__name__, event)+ e = SpiderFootEvent('WEBSERVER_HTTPHEADERS', json.dumps(http_headers), self.__name__, pevent)self.notifyListeners(e)if self.opts.get('udp_portscan', True):udp_ports = self.portScanUDP(ip)for port in udp_ports:- e = SpiderFootEvent("UDP_PORT_OPEN", ip + ":" + port, self.__name__, event)+ e = SpiderFootEvent("UDP_PORT_OPEN", ip + ":" + port, self.__name__, pevent)self.notifyListeners(e)if self.opts.get('tcp_portscan', True):tcp_ports = self.portScanTCP(ip)for port in tcp_ports:- e = SpiderFootEvent("TCP_PORT_OPEN", ip + ":" + port, self.__name__, event)+ e = SpiderFootEvent("TCP_PORT_OPEN", ip + ":" + port, self.__name__, pevent)self.notifyListeners(e)# End of sfp_hackertarget classdiff --git a/modules/sfp_shodan.py b/modules/sfp_shodan.pyindex 8a406b44..3d104807 100644--- a/modules/sfp_shodan.py+++ b/modules/sfp_shodan.py@@ -55,8 +55,7 @@ class sfp_shodan(SpiderFootPlugin):def producedEvents(self):return ["OPERATING_SYSTEM", "DEVICE_TYPE","TCP_PORT_OPEN", "TCP_PORT_OPEN_BANNER",- "SEARCH_ENGINE_WEB_CONTENT", 'RAW_RIR_DATA',- 'GEOINFO', 'VULNERABILITY']+ 'RAW_RIR_DATA', 'GEOINFO', 'VULNERABILITY']def query(self, qry):res = self.sf.fetchUrl("https://api.shodan.io/shodan/host/" + qry +@@ -137,8 +136,8 @@ class sfp_shodan(SpiderFootPlugin):hosts = self.searchHosts(eventData)if hosts is None:return None-- evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", str(hosts), self.__name__, event)++ evt = SpiderFootEvent("RAW_RIR_DATA", str(hosts), self.__name__, event)self.notifyListeners(evt)if eventName == 'WEB_ANALYTICS_ID':@@ -159,7 +158,7 @@ class sfp_shodan(SpiderFootPlugin):if rec is None:return None- evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", str(rec), self.__name__, event)+ evt = SpiderFootEvent("RAW_RIR_DATA", str(rec), self.__name__, event)self.notifyListeners(evt)return None@@ -186,7 +185,15 @@ class sfp_shodan(SpiderFootPlugin):if rec is None:continue- evt = SpiderFootEvent("RAW_RIR_DATA", str(rec), self.__name__, event)+ # For netblocks, we need to create the IP address event so that+ # the threat intel event is more meaningful.+ if eventName.startswith('NETBLOCK_'):+ pevent = SpiderFootEvent("IP_ADDRESS", addr, self.__name__, event)+ self.notifyListeners(pevent)+ else:+ pevent = event++ evt = SpiderFootEvent("RAW_RIR_DATA", str(rec), self.__name__, pevent)self.notifyListeners(evt)if self.checkForStop():@@ -195,18 +202,18 @@ class sfp_shodan(SpiderFootPlugin):if rec.get('os') is not None:# Notify other modules of what you've foundevt = SpiderFootEvent("OPERATING_SYSTEM", rec.get('os') +- " (" + addr + ")", self.__name__, event)+ " (" + addr + ")", self.__name__, pevent)self.notifyListeners(evt)if rec.get('devtype') is not None:# Notify other modules of what you've foundevt = SpiderFootEvent("DEVICE_TYPE", rec.get('devtype') +- " (" + addr + ")", self.__name__, event)+ " (" + addr + ")", self.__name__, pevent)self.notifyListeners(evt)if rec.get('country_name') is not None:location = ', '.join([_f for _f in [rec.get('city'), rec.get('country_name')] if _f])- evt = SpiderFootEvent("GEOINFO", location, self.__name__, event)+ evt = SpiderFootEvent("GEOINFO", location, self.__name__, pevent)self.notifyListeners(evt)if 'data' in rec:@@ -222,29 +229,29 @@ class sfp_shodan(SpiderFootPlugin):# Notify other modules of what you've foundcp = addr + ":" + portevt = SpiderFootEvent("TCP_PORT_OPEN", cp,- self.__name__, event)+ self.__name__, pevent)self.notifyListeners(evt)if banner is not None:# Notify other modules of what you've foundevt = SpiderFootEvent("TCP_PORT_OPEN_BANNER", banner,- self.__name__, event)+ self.__name__, pevent)self.notifyListeners(evt)if product is not None:evt = SpiderFootEvent("SOFTWARE_USED", product,- self.__name__, event)+ self.__name__, pevent)self.notifyListeners(evt)if asn is not None:evt = SpiderFootEvent("BGP_AS_MEMBER", asn.replace("AS", ""),- self.__name__, event)+ self.__name__, pevent)self.notifyListeners(evt)if vulns is not None:for vuln in list(vulns.keys()):evt = SpiderFootEvent('VULNERABILITY', vuln,- self.__name__, event)+ self.__name__, pevent)self.notifyListeners(evt)return Nonediff --git a/sfdb.py b/sfdb.pyindex 35421672..f135b2a1 100644--- a/sfdb.py+++ b/sfdb.py@@ -144,6 +144,7 @@ class SpiderFootDb:"INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('ERROR_MESSAGE', 'Error Message', 0, 'DATA')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('ETHEREUM_ADDRESS', 'Ethereum Address', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('GEOINFO', 'Physical Location', 0, 'DESCRIPTOR')",+ "INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('HASH', 'Hash', 0, 'DATA')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('HASH_COMPROMISED', 'Compromised Password Hash', 0, 'DATA')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('HTTP_CODE', 'HTTP Status Code', 0, 'DATA')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('HUMAN_NAME', 'Human Name', 0, 'ENTITY')",