SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Implement Bitcoin Who's Who functionality (#1006)
Leo Trubach852775b3b0c9
diff --git a/modules/sfp_bitcoinwhoswho.py b/modules/sfp_bitcoinwhoswho.pynew file mode 100644index 00000000..a3d793dd--- /dev/null+++ b/modules/sfp_bitcoinwhoswho.py@@ -0,0 +1,132 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_bitcoinwhoswho+# Purpose: Bitcoin Who's Who database lookup module+#+# Author: Leo Trubach <[email protected]>+#+# Created: 2020-09-09+# Copyright: (c) Steve Micallef+# Licence: GPL+# -------------------------------------------------------------------------------++import json+import urllib.parse++from spiderfoot import SpiderFootEvent, SpiderFootPlugin+++class sfp_bitcoinwhoswho(SpiderFootPlugin):+ meta = {+ 'name': "Bitcoin Who's Who",+ 'summary': "Check for malicious Bitcoin address against Bitcoin Who's Who database",+ 'flags': ["apikey"],+ 'useCases': ["Passive"],+ 'categories': ["Reputation Systems"],+ 'dataSource': {+ 'website': "https://bitcoinwhoswho.com/",+ 'model': "FREE_AUTH_LIMITED",+ 'references': [+ "https://bitcoinwhoswho.com/api"+ ],+ 'apiKeyInstructions': [+ "Visit https://bitcoinwhoswho.com/signup",+ "Register a free account",+ "Verify your email and sign into your account",+ "Visit https://bitcoinwhoswho.com/api/register and request an API Key",+ "Wait for a few days, you'll receive it to your email"+ ],+ 'favIcon': "https://bitcoinwhoswho.com/public/images/ico/favicon.ico",+ 'logo': "https://bitcoinwhoswho.com/public/images/logo2.png",+ 'description': (+ "Bitcoin Who's Who is dedicated to profiling the extraordinary members of the bitcoin "+ "ecosystem.Our goal is to help you verify a bitcoin address owner and avoid a bitcoin "+ "scam or fraud."+ ),+ }+ }++ opts = {+ 'api_key': '',+ }++ optdescs = {+ "api_key": "Bitcoin Who's Who API Key."+ }++ results = None++ errorState = False++ def setup(self, sfc, userOpts=None):+ self.sf = sfc+ self.results = self.tempStorage()++ if userOpts:+ self.opts.update(userOpts)++ def watchedEvents(self):+ return ["BITCOIN_ADDRESS"]++ def producedEvents(self):+ return ["MALICIOUS_BITCOIN_ADDRESS"]++ def query(self, qry):+ qs = urllib.parse.urlencode({"address": qry})+ res = self.sf.fetchUrl(+ f"https://bitcoinwhoswho.com/api/scam/{self.opts['api_key']}?{qs}",+ timeout=self.opts["_fetchtimeout"],+ useragent="SpiderFoot",+ )++ if res["content"] is None:+ self.sf.info(f"No {self.meta['name']} info found for {qry}")+ return None++ try:+ info = json.loads(res["content"])+ except Exception as e:+ self.sf.error(+ f"Error processing JSON response from {self.meta['name']}: {e}", False+ )+ return None++ return info++ def emit(self, etype, data, pevent, notify=True):+ evt = SpiderFootEvent(etype, data, self.__name__, pevent)+ if notify:+ self.notifyListeners(evt)+ return evt++ def generate_events(self, data, pevent):+ if not isinstance(data, dict):+ return++ scams = data.get("scams", [])+ if scams:+ self.emit("MALICIOUS_BITCOIN_ADDRESS", f"Bitcoin Who's Who[{pevent.data}]")++ def handleEvent(self, event):+ if self.errorState:+ return None++ self.sf.debug(f"Received event, {event.eventType}, from {event.module}")++ if self.opts["api_key"] == "":+ self.sf.error(f"You enabled {self.__class__.__name__} but did not set an API key!", False)+ self.errorState = True+ return None++ if event.data in self.results:+ self.sf.debug(f"Skipping {event.data}, already checked.")+ return None+ self.results[event.data] = True++ if event.eventType == "BITCOIN_ADDRESS":+ data = self.query(event.data)+ self.generate_events(data, event)++ self.emit("RAW_RIR_DATA", json.dumps(data), event)++# End of sfp_bitcoinwhoswho classdiff --git a/test/unit/modules/test_sfp_bitcoinwhoswho.py b/test/unit/modules/test_sfp_bitcoinwhoswho.pynew file mode 100644index 00000000..7bfb69e4--- /dev/null+++ b/test/unit/modules/test_sfp_bitcoinwhoswho.py@@ -0,0 +1,79 @@+# test_sfp_bitcoinwhoswho.py+import unittest++from modules.sfp_bitcoinwhoswho import sfp_bitcoinwhoswho+from sflib import SpiderFoot+from spiderfoot import SpiderFootEvent, SpiderFootTarget+++class TestModuletemplate(unittest.TestCase):+ """+ Test modules.sfp_bitcoinwhoswho+ """++ 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-DEV',+ '__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_bitcoinwhoswho()+ 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_bitcoinwhoswho()+ module.setup(sf, dict())++ def test_watchedEvents_should_return_list(self):+ module = sfp_bitcoinwhoswho()+ self.assertIsInstance(module.watchedEvents(), list)++ def test_producedEvents_should_return_list(self):+ module = sfp_bitcoinwhoswho()+ self.assertIsInstance(module.producedEvents(), list)++ def test_handleEvent(self):+ """+ Test handleEvent(self, event)+ """+ sf = SpiderFoot(self.default_options)++ module = sfp_bitcoinwhoswho()+ module.setup(sf, dict())++ target_value = 'example target value'+ target_type = 'IP_ADDRESS'+ 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)