SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Update Spyse module (#1237)
DarkMristov4f96bc671834
diff --git a/README.md b/README.mdindex 6eb807ce..64fec53f 100644--- a/README.md+++ b/README.md@@ -295,7 +295,7 @@ SpamCop|Query various spamcop databases for open relays, open proxies, vulnerablSpamhaus|Query the Spamhaus databases for open relays, open proxies, vulnerable servers, etc.|[https://www.spamhaus.org/](https://www.spamhaus.org/)|Free APIspur.us|Obtain information about any malicious activities involving IP addresses found|[https://spur.us/](https://spur.us/)|Commercial APISpyOnWeb|Search SpyOnWeb for hosts sharing the same IP address, Google Analytics code, or Google Adsense code.|[http://spyonweb.com/](http://spyonweb.com/)|Tiered API-Spyse|SpiderFoot plug-in to search Spyse API for IP address and domain information.|[https://spyse.com](https://spyse.com)|Tiered API+Spyse|Search Spyse.com Internet assets registry for information about domains, IPv4 hosts, potential vulnerabilities, passive DNS, etc.|[https://spyse.com](https://spyse.com)|Tiered APISSL Certificate Analyzer|Gather information about SSL certificates used by the target's HTTPS sites.|N/A|InternalStrange Header Identifier|Obtain non-standard HTTP headers returned by web servers.|N/A|InternalSubdomain Takeover Checker|Check if affiliated subdomains are vulnerable to takeover.|N/A|Internaldiff --git a/modules/sfp_spyse.py b/modules/sfp_spyse.pyindex a06908dc..e4245812 100644--- a/modules/sfp_spyse.py+++ b/modules/sfp_spyse.py@@ -14,26 +14,22 @@import jsonimport time-import urllib.error-import urllib.parse-import urllib.requestfrom spiderfoot import SpiderFootEvent, SpiderFootPluginclass sfp_spyse(SpiderFootPlugin):-meta = {'name': "Spyse",- 'summary': "SpiderFoot plug-in to search Spyse API for IP address and domain information.",+ 'summary': "Search Spyse.com Internet assets registry for information about domains, IPv4 hosts, potential vulnerabilities, passive DNS, etc.",'flags': ["apikey"],'useCases': ["Footprint", "Investigate", "Passive"],- 'categories': ["Passive DNS"],+ 'categories': ["Search Engines"],'dataSource': {'website': "https://spyse.com",'model': "FREE_AUTH_LIMITED",'references': [- "https://spyse.com/tools/api"+ "https://spyse.com/api"],'apiKeyInstructions': ["Visit https://spyse.com",@@ -43,11 +39,14 @@ class sfp_spyse(SpiderFootPlugin):],'favIcon': "https://spyse.com/favicon/favicon-32x32.png",'logo': "https://spyse.com/favicon/favicon-32x32.png",- 'description': " Spyse Search can explore entire countries, various types of infrastructures and "- "everything down to the smallest particles of the web. "- "Use the plethora of search parameters at your disposal to achieve the most accurate results.\n"- "Spyse Scoring has been designed to quickly evaluate the "- "security status of different elements of a network - IPs and domains.",+ 'description': "Spyse is a platform that collects, analyzes, and delivers data about devices and websites "+ "available on the Internet. It regularly probes every public IP address, crawls every "+ "website, curates and enriches the resulting data, and makes it intelligible through an "+ "interactive search engine and API.\n"+ "Supported data models: IPv4 hosts, open ports, WHOIS, domains, websites, passive DNS, "+ "potential vulnerabilities, autonomous systems, technologies, subnets, emails, IP "+ "reputation, organization, etc."+}}@@ -87,7 +86,7 @@ class sfp_spyse(SpiderFootPlugin):# What events is this module interested in for inputdef watchedEvents(self):- return ["IP_ADDRESS", "IPV6_ADDRESS", "DOMAIN_NAME", "INTERNET_NAME"]+ return ["IP_ADDRESS", "DOMAIN_NAME", "INTERNET_NAME"]# What events this module producesdef producedEvents(self):@@ -99,7 +98,7 @@ class sfp_spyse(SpiderFootPlugin):def querySubdomains(self, qry, currentOffset):"""Query subdomains of domain- https://spyse.com/v3/data/tools/api#/domain/subdomain+ https://spyse-dev.readme.io/reference/domains#domain_searchArgs:qry (str): domain name@@ -109,51 +108,54 @@ class sfp_spyse(SpiderFootPlugin):dict: JSON formatted results"""- params = {- 'domain': qry.encode('raw_unicode_escape').decode("ascii", errors='replace'),- 'limit': self.limit,- 'offset': currentOffset- }headers = {'Accept': "application/json",+ 'Content-Type': "application/json",'Authorization': "Bearer " + self.opts['api_key']}+ body = {+ "search_params": [+ {+ "name": {+ "operator": "ends",+ "value": f".{qry.encode('raw_unicode_escape').decode('ascii', errors='replace')}"+ }+ }+ ],+ "limit": self.limit,+ "offset": currentOffset+ }res = self.sf.fetchUrl(- 'https://api.spyse.com/v3/data/domain/subdomain?' + urllib.parse.urlencode(params),+ 'https://api.spyse.com/v4/data/domain/search',headers=headers,timeout=15,- useragent=self.opts['_useragent']+ useragent=self.opts['_useragent'],+ postData=json.dumps(body))time.sleep(self.opts['delay'])return self.parseAPIResponse(res)- def queryIPPort(self, qry, currentOffset):- """Query IP port lookup+ def queryDomainDetails(self, qry):+ """Query domain details- https://spyse.com/v3/data/tools/api#/ip/port_by_ip+ https://spyse-dev.readme.io/reference/domains#domain_detailsArgs:- qry (str): IP address- currentOffset (int): start from this search result offset+ qry (str): Domain nameReturns:dict: JSON formatted results"""- params = {- 'ip': qry.encode('raw_unicode_escape').decode("ascii", errors='replace'),- 'limit': self.limit,- 'offset': currentOffset- }headers = {'Accept': "application/json",'Authorization': "Bearer " + self.opts['api_key']}res = self.sf.fetchUrl(- 'https://api.spyse.com/v3/data/ip/port?' + urllib.parse.urlencode(params),+ f'https://api.spyse.com/v4/data/domain/{qry.encode("raw_unicode_escape").decode("ascii", errors="replace")}',headers=headers,timeout=15,useragent=self.opts['_useragent']@@ -163,30 +165,24 @@ class sfp_spyse(SpiderFootPlugin):return self.parseAPIResponse(res)- def queryDomainsOnIP(self, qry, currentOffset):- """Query domains on IP+ def queryIPPort(self, qry):+ """Query IP port lookup- https://spyse.com/v3/data/tools/api#/ip/domain_by_ip+ https://spyse-dev.readme.io/reference/ips#ip_detailsArgs:qry (str): IP address- currentOffset (int): start from this search result offsetReturns:dict: JSON formatted results"""- params = {- 'ip': qry.encode('raw_unicode_escape').decode("ascii", errors='replace'),- 'limit': self.limit,- 'offset': currentOffset- }headers = {'Accept': "application/json",'Authorization': "Bearer " + self.opts['api_key']}res = self.sf.fetchUrl(- 'https://api.spyse.com/v3/data/ip/domain?' + urllib.parse.urlencode(params),+ f'https://api.spyse.com/v4/data/ip/{qry.encode("raw_unicode_escape").decode("ascii", errors="replace")}',headers=headers,timeout=15,useragent=self.opts['_useragent']@@ -196,13 +192,10 @@ class sfp_spyse(SpiderFootPlugin):return self.parseAPIResponse(res)- def queryDomainsAsMX(self, qry, currentOffset):- """Query domains using domain as MX server-- https://spyse.com/v3/data/apidocs#/Domain%20related%20information/get_domains_using_as_mx+ def queryDomainsOnIP(self, qry, currentOffset):+ """Query domains on IP- Note:- currently unused+ https://spyse-dev.readme.io/reference/domains#domain_searchArgs:qry (str): IP address@@ -212,19 +205,26 @@ class sfp_spyse(SpiderFootPlugin):dict: JSON formatted results"""- params = {- 'ip': qry.encode('raw_unicode_escape').decode("ascii", errors='replace'),- 'limit': self.limit,- 'offset': currentOffset- }-headers = {'Accept': "application/json",+ 'Content-Type': "application/json",'Authorization': "Bearer " + self.opts['api_key']}-+ body = {+ "search_params": [+ {+ "dns_a": {+ "operator": "eq",+ "value": f"{qry.encode('raw_unicode_escape').decode('ascii', errors='replace')}"+ }+ }+ ],+ "limit": self.limit,+ "offset": currentOffset+ }res = self.sf.fetchUrl(- 'https://api.spyse.com/v3/data/ip/mx?' + urllib.parse.urlencode(params),+ 'https://api.spyse.com/v4/data/domain/search',+ postData=json.dumps(body),headers=headers,timeout=15,useragent=self.opts['_useragent']@@ -237,7 +237,7 @@ class sfp_spyse(SpiderFootPlugin):def parseAPIResponse(self, res):"""Parse API response- https://spyse.com/v3/data/apidocs+ https://spyse-dev.readme.io/reference/quick-startArgs:res: TBD@@ -314,7 +314,6 @@ class sfp_spyse(SpiderFootPlugin):self.sf.error("You enabled sfp_spyse but did not set an API key!")self.errorState = Truereturn-eventName = event.eventTypesrcModuleName = event.moduleeventData = event.data@@ -326,162 +325,312 @@ class sfp_spyse(SpiderFootPlugin):self.sf.debug(f"Received event, {eventName}, from {srcModuleName}")- # Query cohosts- if eventName in ["IP_ADDRESS", "IPV6_ADDRESS"]:- cohosts = list()- currentOffset = 0- nextPageHasData = True-- while nextPageHasData:- if self.checkForStop():- return-- data = self.queryDomainsOnIP(eventData, currentOffset)- if not data:- nextPageHasData = False- break-- data = data.get("data")- if data is None:- self.sf.debug("No domains found on IP address " + eventData)- nextPageHasData = False- break- else:- records = data.get('items')- if records:- for record in records:- domain = record.get('name')- if domain:- evt = SpiderFootEvent('RAW_RIR_DATA', str(record), self.__name__, event)- self.notifyListeners(evt)+ # Query open ports for source IP Address+ if eventName in ["IP_ADDRESS"]:+ if self.checkForStop():+ return+ self.process_ip_event(event)++ # Query subdomains+ if eventName in ["DOMAIN_NAME", "INTERNET_NAME"]:+ if self.checkForStop():+ return+ self.process_domain_event(event)++ def process_ip_event(self, event):+ cohosts = list()+ currentOffset = 0+ nextPageHasData = True+ eventData = event.data++ while nextPageHasData:+ if self.checkForStop():+ return++ data = self.queryDomainsOnIP(eventData, currentOffset)+ if not data:+ nextPageHasData = False+ break++ data = data.get("data")+ if data is None:+ self.sf.debug("No domains found on IP address " + eventData)+ nextPageHasData = False+ break+ else:+ records = data.get('items')+ if records:+ for record in records:+ domain = record.get('name')+ if domain:+ evt = SpiderFootEvent('RAW_RIR_DATA', str(record), self.__name__, event)+ self.notifyListeners(evt)++ cohosts.append(domain)+ self.reportExtraData(record, event)- cohosts.append(domain)- self.reportExtraData(record, event)+ # Calculate if there are any records in the next offset (page)+ if len(records) < self.limit:+ nextPageHasData = False+ currentOffset += self.limit- # Calculate if there are any records in the next offset (page)- if len(records) < self.limit:- nextPageHasData = False- currentOffset += self.limit+ for co in set(cohosts):- for co in set(cohosts):+ if co in self.results:+ continue- if co in self.results:+ if self.opts['verify'] and not self.sf.validateIP(co, eventData):+ self.sf.debug("Host " + co + " no longer resolves to " + eventData)+ continue++ if not self.opts['cohostsamedomain']:+ if self.getTarget().matches(co, includeParents=True):+ evt = SpiderFootEvent('INTERNET_NAME', co, self.__name__, event)+ self.notifyListeners(evt)+ if self.sf.isDomain(co, self.opts['_internettlds']):+ evt = SpiderFootEvent('DOMAIN_NAME', co, self.__name__, event)+ self.notifyListeners(evt)continue- if self.opts['verify'] and not self.sf.validateIP(co, eventData):- self.sf.debug("Host " + co + " no longer resolves to " + eventData)+ if self.cohostcount < self.opts['maxcohost']:+ evt = SpiderFootEvent('CO_HOSTED_SITE', co, self.__name__, event)+ self.notifyListeners(evt)+ self.cohostcount += 1++ ports = list()++ data = self.queryIPPort(eventData)+ if data:+ data = data.get("data")++ if data is None:+ self.sf.debug("No open ports found for IP " + eventData)+ else:+ records = data.get('items')+ if records:++ for record in records:+ if record.get("ports"):++ for port_data in record["ports"]:++ port = port_data.get('port')+ if port:+ evt = SpiderFootEvent('RAW_RIR_DATA', str(record), self.__name__, event)+ self.notifyListeners(evt)++ ports.append(str(eventData) + ":" + str(port))+ self.reportExtraData(record, event)+ if record.get("geo_info"):+ country = record["geo_info"].get("country")+ if country:+ evt = SpiderFootEvent('COUNTRY_NAME', country, self.__name__, event)+ self.notifyListeners(evt)+ if record.get("cve_list"):+ for cve in record["cve_list"]:+ evt = SpiderFootEvent('VULNERABILITY', cve["id"], self.__name__, event)+ self.notifyListeners(evt)+ if record.get("technologies"):+ for tech in record["technologies"]:+ if tech.get("version"):+ evt = SpiderFootEvent('WEBSERVER_TECHNOLOGY',+ f"{tech['name']} {tech['version']}",+ self.__name__, event)+ else:+ evt = SpiderFootEvent('WEBSERVER_TECHNOLOGY', tech['name'], self.__name__,+ event)+ self.notifyListeners(evt)++ for port in ports:+ if port in self.results:continue+ self.results[port] = True- if not self.opts['cohostsamedomain']:- if self.getTarget().matches(co, includeParents=True):- evt = SpiderFootEvent('INTERNET_NAME', co, self.__name__, event)- self.notifyListeners(evt)- if self.sf.isDomain(co, self.opts['_internettlds']):- evt = SpiderFootEvent('DOMAIN_NAME', co, self.__name__, event)+ evt = SpiderFootEvent('TCP_PORT_OPEN', str(port), self.__name__, event)+ self.notifyListeners(evt)++ def process_domain_event(self, event):+ currentOffset = 0+ nextPageHasData = True+ domains = list()+ eventData = event.data+ if event.module == "sfp_spyse" and (self.getTarget().targetValue in event.data):+ return++ domain_details = self.queryDomainDetails(eventData)+ if domain_details:+ domain_details_data = domain_details.get("data", {}).get("items", [])+ if len(domain_details_data) > 0:+ domain_item = domain_details_data[0]+ if domain_item.get("organizations"):+ for org in domain_item.get("organizations", []):+ if org.get("crunchbase"):+ if org.get("crunchbase").get("is_primary", False):+ org_name = org["crunchbase"].get("legal_name")+ if not org_name:+ org_name = org["crunchbase"].get("name")+ if org_name:+ evt = SpiderFootEvent('COMPANY_NAME', org_name, self.__name__, event)+ self.notifyListeners(evt)++ domain_dns = domain_item.get("dns_records")+ if domain_dns:+ domain_dns_a_records = domain_dns.get("A")+ if domain_dns_a_records:+ for dns_A in domain_dns_a_records:+ evt = SpiderFootEvent('IP_ADDRESS', dns_A, self.__name__, event)self.notifyListeners(evt)- continue- if self.cohostcount < self.opts['maxcohost']:- evt = SpiderFootEvent('CO_HOSTED_SITE', co, self.__name__, event)- self.notifyListeners(evt)- self.cohostcount += 1+ domain_dns_aaaa_records = domain_dns.get("AAAA")+ if domain_dns_aaaa_records:+ for dns_AAAA in domain_dns_aaaa_records:+ evt = SpiderFootEvent('IPV6_ADDRESS', dns_AAAA, self.__name__, event)+ self.notifyListeners(evt)- # Query open ports for source IP Address- if eventName in ["IP_ADDRESS", "IPV6_ADDRESS"]:- ports = list()- currentOffset = 0- nextPageHasData = True-- while nextPageHasData:- if self.checkForStop():- return- data = self.queryIPPort(eventData, currentOffset)- if not data:- nextPageHasData = False- break-- data = data.get("data")-- if data is None:- self.sf.debug("No open ports found for IP " + eventData)- nextPageHasData = False- break- else:- records = data.get('items')- if records:- for record in records:- port = record.get('port')- if port:- evt = SpiderFootEvent('RAW_RIR_DATA', str(record), self.__name__, event)+ domain_dns_spf_records = domain_dns.get("SPF")+ if domain_dns_spf_records:+ for dns_spf in domain_dns_spf_records:+ if dns_spf.get("raw"):+ evt = SpiderFootEvent('DNS_SPF', dns_spf["raw"], self.__name__, event)self.notifyListeners(evt)- ports.append(str(eventData) + ":" + str(port))- self.reportExtraData(record, event)+ domain_dns_txt_records = domain_dns.get("TXT")+ if domain_dns_txt_records:+ for dns_txt in domain_dns_txt_records:+ evt = SpiderFootEvent('DNS_TEXT', dns_txt, self.__name__, event)+ self.notifyListeners(evt)- # Calculate if there are any records in the next offset (page)- if len(records) < self.limit:- nextPageHasData = False- currentOffset += self.limit+ domain_dns_ns_records = domain_dns.get("NS")+ if domain_dns_ns_records:+ for dns_ns in domain_dns_ns_records:+ evt = SpiderFootEvent('PROVIDER_DNS', dns_ns, self.__name__, event)+ self.notifyListeners(evt)- for port in ports:- if port in self.results:- continue- self.results[port] = True+ domain_dns_mx_records = domain_dns.get("MX")+ if domain_dns_mx_records:+ for dns_mx in domain_dns_mx_records:+ evt = SpiderFootEvent('PROVIDER_MAIL', dns_mx, self.__name__, event)+ self.notifyListeners(evt)- evt = SpiderFootEvent('TCP_PORT_OPEN', str(port), self.__name__, event)- self.notifyListeners(evt)+ hosts_enrichment = domain_item.get("hosts_enrichment")+ if hosts_enrichment:+ for host_enrichment in hosts_enrichment:+ if host_enrichment.get("country"):+ evt = SpiderFootEvent('COUNTRY_NAME', host_enrichment["country"], self.__name__, event)+ self.notifyListeners(evt)- # Query subdomains- if eventName in ["DOMAIN_NAME", "INTERNET_NAME"]:- currentOffset = 0- nextPageHasData = True- domains = list()-- while nextPageHasData:- if self.checkForStop():- return-- data = self.querySubdomains(eventData, currentOffset)- if not data:- nextPageHasData = False- break-- data = data.get("data")- if data is None:- self.sf.debug("No subdomains found for domain " + eventData)- nextPageHasData = False- break- else:- records = data.get('items')- if records:- for record in records:- domain = record.get('name')- if domain:- evt = SpiderFootEvent('RAW_RIR_DATA', str(record), self.__name__, event)- self.notifyListeners(evt)+ domain_technologies = domain_item.get("technologies")+ if domain_technologies:+ for tech in domain_technologies:+ if tech.get("version"):+ evt = SpiderFootEvent('WEBSERVER_TECHNOLOGY', f"{tech['name']} {tech['version']}",+ self.__name__, event)+ else:+ evt = SpiderFootEvent('WEBSERVER_TECHNOLOGY', tech['name'], self.__name__, event)- domains.append(domain)- self.reportExtraData(record, event)+ self.notifyListeners(evt)- # Calculate if there are any records in the next offset (page)- if len(records) < self.limit:- nextPageHasData = False- currentOffset += self.limit+ domain_cves = domain_item.get("cve_list")+ if domain_cves:+ for cve in domain_cves:+ evt = SpiderFootEvent('VULNERABILITY', cve["id"], self.__name__, event)+ self.notifyListeners(evt)- for domain in set(domains):+ domain_whois = domain_item.get("whois_parsed")+ if domain_whois:+ domain_whois_registrar = domain_whois.get("registrar")+ if domain_whois_registrar:+ if domain_whois_registrar.get("registrar_name"):+ evt = SpiderFootEvent('DOMAIN_REGISTRAR',+ domain_whois_registrar["registrar_name"], self.__name__,+ event)+ self.notifyListeners(evt)- if domain in self.results:- continue+ domain_http_extract = domain_item.get("http_extract")+ if domain_http_extract:- if not self.getTarget().matches(domain, includeChildren=True, includeParents=True):- continue+ if domain_http_extract.get("http_status_code"):+ evt = SpiderFootEvent('HTTP_CODE', str(domain_http_extract["http_status_code"]),+ self.__name__, event)+ self.notifyListeners(evt)- if self.opts['verify'] and not self.sf.resolveHost(domain):- self.sf.debug(f"Host {domain} could not be resolved")- evt = SpiderFootEvent("INTERNET_NAME_UNRESOLVED", domain, self.__name__, event)- self.notifyListeners(evt)- else:- evt = SpiderFootEvent("INTERNET_NAME", domain, self.__name__, event)- self.notifyListeners(evt)+ domain_emails = domain_http_extract.get("emails")+ if domain_emails:+ for email in domain_emails:+ evt = SpiderFootEvent('EMAILADDR', email, self.__name__, event)+ self.notifyListeners(evt)++ domain_cert_summary = domain_item.get("cert_summary")+ if domain_cert_summary:+ domain_cert_summary_subject = domain_cert_summary.get("subject")+ if domain_cert_summary_subject:+ if domain_cert_summary_subject.get("organization"):+ evt = SpiderFootEvent('SSL_CERTIFICATE_ISSUED',+ domain_cert_summary_subject["organization"], self.__name__,+ event)+ self.notifyListeners(evt)++ domain_cert_summary_issuer = domain_cert_summary.get("issuer")+ if domain_cert_summary_issuer:+ if domain_cert_summary_issuer.get("organization"):+ evt = SpiderFootEvent('SSL_CERTIFICATE_ISSUER',+ domain_cert_summary_issuer["organization"], self.__name__,+ event)+ self.notifyListeners(evt)++ domain_trackers = domain_item.get("trackers")+ if domain_trackers:+ if domain_trackers.get("google_analytics_key"):+ evt = SpiderFootEvent("WEB_ANALYTICS_ID",+ f"Google Analytics: {domain_trackers.get('google_analytics_key')}",+ self.__name__, event)+ self.notifyListeners(evt)++ while nextPageHasData:+ if self.checkForStop():+ return++ data = self.querySubdomains(eventData, currentOffset)+ if not data:+ nextPageHasData = False+ break++ data = data.get("data")+ if data is None:+ self.sf.debug("No subdomains found for domain " + eventData)+ nextPageHasData = False+ break+ else:+ records = data.get('items')+ if records:+ for record in records:+ domain = record.get('name')+ if domain:+ evt = SpiderFootEvent('RAW_RIR_DATA', str(record), self.__name__, event)+ self.notifyListeners(evt)++ domains.append(domain)+ self.reportExtraData(record, event)++ # Calculate if there are any records in the next offset (page)+ if len(records) < self.limit:+ nextPageHasData = False+ currentOffset += self.limit++ for domain in set(domains):++ if domain in self.results:+ continue++ if not self.getTarget().matches(domain, includeChildren=True, includeParents=True):+ continue++ if self.opts['verify'] and not self.sf.resolveHost(domain):+ self.sf.debug(f"Host {domain} could not be resolved")+ evt = SpiderFootEvent("INTERNET_NAME_UNRESOLVED", domain, self.__name__, event)+ self.notifyListeners(evt)+ else:+ evt = SpiderFootEvent("INTERNET_NAME", domain, self.__name__, event)+ self.notifyListeners(evt)# End of sfp_spyse class