SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Trashpanda (#1154)
Krishnasis Mandal4b3dec3bc3c4
diff --git a/modules/sfp_trashpanda.py b/modules/sfp_trashpanda.pynew file mode 100644index 00000000..c8ceeab0--- /dev/null+++ b/modules/sfp_trashpanda.py@@ -0,0 +1,181 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_trashpanda+# Purpose: Spiderfoot plugin to query Trashpanda - got-hacked.wtf API to gather intelligence about+# mentions of your target in paste sites like Pastebin, Ghostbin and Zeropaste+#+# Author: Krishnasis Mandal <[email protected]>+#+# Created: 17/04/2021+# Copyright: (c) Steve Micallef+# Licence: GPL+# -------------------------------------------------------------------------------++import json+import base64+import re++from spiderfoot import SpiderFootEvent, SpiderFootPlugin+++class sfp_trashpanda(SpiderFootPlugin):++ meta = {+ 'name': "Trashpanda",+ 'summary': "Queries Trashpanda to gather intelligence about mentions of target in pastesites",+ 'flags': ["apikey"],+ 'useCases': ["Investigate", "Passive"],+ 'categories': ["Leaks, Dumps and Breaches"],+ 'dataSource': {+ 'website': "https://got-hacked.wtf",+ 'model': "FREE_AUTH_LIMITED",+ 'references': [+ "http://api.got-hacked.wtf:5580/help"+ ],+ 'apiKeyInstructions': [+ "Follow the guide at https://got-hacked.wtf/"+ ],+ 'favIcon': "https://got-hacked.wtf/wp-content/uploads/2020/07/cropped-IMG_7619.jpg",+ 'logo': "https://got-hacked.wtf/wp-content/uploads/2020/07/cropped-IMG_7619.jpg",+ 'description': "The bot searches different paste sites for leaked credentials."+ "The API itself gives access to all unique credentials the bot ever detected.",+ }+ }++ # Default options+ opts = {+ 'api_key_username': '',+ 'api_key_password': '',+ }++ # Option descriptions+ optdescs = {+ 'api_key_username': "Trashpanda API Username",+ 'api_key_password': 'Trashpanda API Password',+ }++ results = None++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc+ self.results = self.tempStorage()++ for opt in list(userOpts.keys()):+ self.opts[opt] = userOpts[opt]++ # What events is this module interested in for input+ def watchedEvents(self):+ return [+ "DOMAIN_NAME",+ "INTERNET_NAME",+ "EMAILADDR"+ ]++ # What events this module produces+ # This is to support the end user in selecting modules based on events+ # produced.+ def producedEvents(self):+ return [+ "LEAKSITE_CONTENT",+ "LEAKSITE_URL",+ "PASSWORD_COMPROMISED",+ ]++ def query(self, qry, eventName):+ secret = self.opts['api_key_username'] + ':' + self.opts['api_key_password']+ auth = base64.b64encode(secret.encode('utf-8')).decode('utf-8')++ queryString = ""+ if eventName == "DOMAIN_NAME" or eventName == "INTERNET_NAME":+ queryString = f"http://api.got-hacked.wtf:5580/domain?v={qry}&s=zpg"+ elif eventName == "EMAILADDR":+ queryString = f"http://api.got-hacked.wtf:5580/email?v={qry}&s=zpg"++ headers = {+ 'Accept': "application/json",+ 'Authorization': f"Basic {auth}"+ }++ res = self.sf.fetchUrl(+ queryString,+ headers=headers,+ timeout=15,+ useragent=self.opts['_useragent']+ )++ if res['code'] != "200":+ self.sf.error("Error retrieving search results from Trashpanda(got-hacked.wtf)")+ return None++ return json.loads(res['content'])++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data++ self.sf.debug(f"Received event, {eventName}, from {srcModuleName}")++ if self.errorState:+ return None++ if self.opts['api_key_username'] == "" or self.opts['api_key_password'] == "":+ self.sf.error("You enabled sfp_trashpanda but did not set an API username / password!")+ self.errorState = True+ return++ # Don't look up stuff twice+ if eventData in self.results:+ self.sf.debug(f"Skipping {eventData}, already checked.")+ return None+ else:+ self.results[eventData] = True++ data = self.query(eventData, eventName)++ if data is None:+ return None++ leaksiteUrls = set()+ for row in data:+ evt = SpiderFootEvent("PASSWORD_COMPROMISED", f"{row.get('email')}:{row.get('password')} [{row.get('paste')}]", self.__name__, event)+ self.notifyListeners(evt)++ leaksiteUrls.add(row.get("paste"))++ for leaksiteUrl in leaksiteUrls:+ try:+ self.sf.debug("Found a link: " + leaksiteUrl)++ if self.checkForStop():+ return None++ res = self.sf.fetchUrl(leaksiteUrl, timeout=self.opts['_fetchtimeout'],+ useragent=self.opts['_useragent'])++ if res['content'] is None:+ self.sf.debug(f"Ignoring {leaksiteUrl} as no data returned")+ continue++ # Sometimes pastes search results false positives+ if eventData.lower() not in str(res['content']).lower():+ self.sf.debug("String not found in pastes content.")+ continue++ if re.search(+ r"[^a-zA-Z\-\_0-9]" + re.escape(eventData) + r"[^a-zA-Z\-\_0-9]",+ res['content'],+ re.IGNORECASE+ ) is None:+ continue++ evt = SpiderFootEvent("LEAKSITE_URL", leaksiteUrl, self.__name__, event)+ self.notifyListeners(evt)++ evt = SpiderFootEvent("LEAKSITE_CONTENT", res['content'], self.__name__, evt)+ self.notifyListeners(evt)+ except Exception as e:+ self.sf.debug(f"Error while fetching leaksite content : {str(e)}")++# End of sfp_trashpanda classdiff --git a/test/unit/modules/test_sfp_trashpanda.py b/test/unit/modules/test_sfp_trashpanda.pynew file mode 100644index 00000000..281e66f6--- /dev/null+++ b/test/unit/modules/test_sfp_trashpanda.py@@ -0,0 +1,79 @@+# test_sfp_trashpanda.py+import unittest++from modules.sfp_trashpanda import sfp_trashpanda+from sflib import SpiderFoot+from spiderfoot import SpiderFootEvent, SpiderFootTarget+++class TestModuletrashpanda(unittest.TestCase):+ """+ Test modules.sfp_trashpanda+ """++ default_options = {+ '_debug': False, # Debug+ '__logging': True, # Logging in general+ '__outputfilter': None, # Event types to filter from modules' output+ '_useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0', # User-Agent to use for HTTP requests+ '_dnsserver': '', # Override the default resolver+ '_fetchtimeout': 5, # number of seconds before giving up on a fetch+ '_internettlds': 'https://publicsuffix.org/list/effective_tld_names.dat',+ '_internettlds_cache': 72,+ '_genericusers': "abuse,admin,billing,compliance,devnull,dns,ftp,hostmaster,inoc,ispfeedback,ispsupport,list-request,list,maildaemon,marketing,noc,no-reply,noreply,null,peering,peering-notify,peering-request,phish,phishing,postmaster,privacy,registrar,registry,root,routing-registry,rr,sales,security,spam,support,sysadmin,tech,undisclosed-recipients,unsubscribe,usenet,uucp,webmaster,www",+ '__version__': '3.3',+ '__database': 'spiderfoot.test.db', # note: test database file+ '__modules__': None, # List of modules. Will be set after start-up.+ '_socks1type': '',+ '_socks2addr': '',+ '_socks3port': '',+ '_socks4user': '',+ '_socks5pwd': '',+ '_torctlport': 9051,+ '__logstdout': False+ }++ def test_opts(self):+ module = sfp_trashpanda()+ self.assertEqual(len(module.opts), len(module.optdescs))++ def test_setup(self):+ """+ Test setup(self, sfc, userOpts=dict())+ """+ sf = SpiderFoot(self.default_options)++ module = sfp_trashpanda()+ module.setup(sf, dict())++ def test_watchedEvents_should_return_list(self):+ module = sfp_trashpanda()+ self.assertIsInstance(module.watchedEvents(), list)++ def test_producedEvents_should_return_list(self):+ module = sfp_trashpanda()+ self.assertIsInstance(module.producedEvents(), list)++ def test_handleEvent(self):+ """+ Test handleEvent(self, event)+ """+ sf = SpiderFoot(self.default_options)++ module = sfp_trashpanda()+ module.setup(sf, dict())++ target_value = 'example target value'+ target_type = 'EMAILADDR'+ target = SpiderFootTarget(target_value, target_type)+ module.setTarget(target)++ event_type = 'ROOT'+ event_data = 'example data'+ event_module = ''+ source_event = ''+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)++ result = module.handleEvent(evt)++ self.assertIsNone(result)