SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
sfp_iknowwhatyoudownload: Cleanup and add support for IPv6 addresses (#1480)
bcoles5b11c5762116
diff --git a/modules/sfp_iknowwhatyoudownload.py b/modules/sfp_iknowwhatyoudownload.pyindex 2ffe0009..03f26206 100644--- a/modules/sfp_iknowwhatyoudownload.py+++ b/modules/sfp_iknowwhatyoudownload.py@@ -1,6 +1,6 @@# -------------------------------------------------------------------------------# Name: sfp_iknowwhatyoudownload-# Purpose: Query iknowwhatyoudownload.com for IP addresses using BitTorrent.+# Purpose: Query iknowwhatyoudownload.com for IP addresses using torrents.## Author: Steve Micallef <[email protected]>#@@ -10,6 +10,9 @@# -------------------------------------------------------------------------------import json+import urllib.error+import urllib.parse+import urllib.requestfrom spiderfoot import SpiderFootEvent, SpiderFootPlugin@@ -18,7 +21,7 @@ class sfp_iknowwhatyoudownload(SpiderFootPlugin):meta = {'name': "Iknowwhatyoudownload.com",- 'summary': "Check iknowwhatyoudownload.com for IP addresses that have been using BitTorrent.",+ 'summary': "Check iknowwhatyoudownload.com for IP addresses that have been using torrents.",'flags': ["apikey"],'useCases': ["Footprint", "Investigate", "Passive"],'categories': ["Secondary Networks"],@@ -38,26 +41,21 @@ class sfp_iknowwhatyoudownload(SpiderFootPlugin):'favIcon': "https://iknowwhatyoudownload.com/assets/img/utorrent2.png",'logo': "https://iknowwhatyoudownload.com/assets/img/logo.png",'description': "Our system collects torrent files in two ways: parsing torrent sites, and listening DHT network. "- "We have more than 1.500.000 torrents which where classified and which are using now "+ "The system contains more than 7 million torrents (as of Oct 2021) which were classified and which are using now ""for collecting peer sharing facts (up to 200.000.000 daily).",}}- # Default optionsopts = {"daysback": 30,"api_key": ""}- # Option descriptionsoptdescs = {"daysback": "How far back (in days) to look for activity.","api_key": "Iknowwhatyoudownload.com API key."}- # Be sure to completely clear any class variables in setup()- # or you run the risk of data persisting between scan runs.-results = NoneerrorState = False@@ -66,59 +64,63 @@ class sfp_iknowwhatyoudownload(SpiderFootPlugin):self.results = self.tempStorage()self.errorState = False- # Clear / reset any other class member variables here- # or you risk them persisting between threads.-for opt in list(userOpts.keys()):self.opts[opt] = userOpts[opt]- # What events is this module interested in for inputdef watchedEvents(self):- return ["IP_ADDRESS"]+ return ["IP_ADDRESS", "IPV6_ADDRESS"]- # What events this module producesdef producedEvents(self):return ["MALICIOUS_IPADDR"]def query(self, qry):- ret = None- retdata = None-- url = "https://api.antitor.com/history/peer/?ip="- url += qry + "&days=" + str(self.opts['daysback'])- url += "&key=" + self.opts['api_key']-- res = self.sf.fetchUrl(url, timeout=self.opts['_fetchtimeout'], useragent="SpiderFoot")+ """Search iknowwhatyoudownload.com for an IPv4/IPv6 address.++ Args:+ qry: IPv4/IPv6 address++ Returns:+ dict: JSON response containing dowloaded content+ """+ params = urllib.parse.urlencode({+ 'ip': qry,+ 'days': self.opts['daysback'],+ 'key': self.opts['api_key'],+ })++ res = self.sf.fetchUrl(+ f"https://api.antitor.com/history/peer/?{params}",+ timeout=self.opts['_fetchtimeout'],+ useragent="SpiderFoot"+ )++ if res['code'] != "200":+ self.error(f"Unexpected HTTP response code {res['code']} from iknowwhatyoudownload.com.")+ return None- if res['code'] in ["403", "500"]:- self.info("Unable to fetch data from iknowwhatyoudownload.com right now.")+ if res['content'] is None:+ self.info(f"No results for {qry} from iknowwhatyoudownload.com")return Nonetry:- ret = json.loads(res['content'])+ data = json.loads(res['content'])except Exception as e:self.error(f"Error processing JSON response from iknowwhatyoudownload.com: {e}")return None- if 'error' in ret:- if ret['error'] == "INVALID_DAYS":- self.errorState = True- self.error("The number of days you have configured is not accepted. If you have the demo key, try 30 days or less.")- return None-- if 'contents' not in ret:+ error = data.get('error')+ if error and error == "INVALID_DAYS":+ self.errorState = True+ self.error(f"The number of days you have configured ({self.opts['daysback']}) was not accepted. If you have the demo key, try 30 days or less.")return None- if not len(ret['contents']):- return None+ contents = data.get('contents')- retdata = f"<SFURL>https://iknowwhatyoudownload.com/en/peer/?ip={qry}</SFURL>\n"- for d in ret['contents']:- retdata += d['torrent']['name'] + " (" + d.get("endDate", "Date unknown") + ")\n"+ if not contents:+ return None- return retdata+ return contents- # Handle events sent to this moduledef handleEvent(self, event):eventName = event.eventTypesrcModuleName = event.module@@ -134,7 +136,6 @@ class sfp_iknowwhatyoudownload(SpiderFootPlugin):self.errorState = Truereturn- # Don't look up stuff twiceif eventData in self.results:self.debug(f"Skipping {eventData}, already checked.")return@@ -146,7 +147,19 @@ class sfp_iknowwhatyoudownload(SpiderFootPlugin):if not data:return- e = SpiderFootEvent("MALICIOUS_IPADDR", data, self.__name__, event)+ retdata = [f"<SFURL>https://iknowwhatyoudownload.com/en/peer/?ip={eventData}</SFURL>"]++ for d in data:+ torrent = d.get('torrent')++ if not torrent:+ continue++ download_name = torrent.get('name')+ download_date = d.get("endDate", "Date unknown")+ retdata.append(f"{download_name} ({download_date})")++ e = SpiderFootEvent("MALICIOUS_IPADDR", "\n".join(retdata), self.__name__, event)self.notifyListeners(e)# End of sfp_iknowwhatyoudownload class