SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Implement BitcoinAbuse functionality
Leo Trubachb924abd676f0
diff --git a/modules/sfp_bitcoinabuse.py b/modules/sfp_bitcoinabuse.pynew file mode 100644index 00000000..ebc37c7e--- /dev/null+++ b/modules/sfp_bitcoinabuse.py@@ -0,0 +1,131 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_bitcoinabuse+# Purpose: Example module to use for new modules.+#+# Author: Leo Trubach <[email protected]>+#+# Created: 2020-09-01+# Copyright: (c) Steve Micallef+# Licence: GPL+# -------------------------------------------------------------------------------++import json+from urllib.parse import urlencode++from sflib import SpiderFootEvent, SpiderFootPlugin+++class sfp_bitcoinabuse(SpiderFootPlugin):+ # The module descriptor dictionary contains all the meta data about a module necessary+ # for users to understand...+ meta = {+ "name": "BitcoinAbuse",+ "summary": "Check bitcoin address against bitcoinabuse.com database",+ "flags": ["apikey"],+ "useCases": ["Passive", "Investigate"],+ "categories": ["Reputation Systems"],+ "dataSource": {+ "website": "https://www.bitcoinabuse.com/",+ "model": "FREE_AUTH_UNLIMITED",+ "references": ["https://www.bitcoinabuse.com/api-docs"],+ "apiKeyInstructions": [+ "Visit https://www.bitcoinabuse.com/register",+ "Register a free account",+ "Click on account icon and click on 'Your Settings'",+ "Click on 'API'",+ "Enter token name and press 'Create'",+ ],+ "favIcon": "https://www.bitcoinabuse.com/favicon-32x32.png",+ "logo": "https://www.bitcoinabuse.com/img/logo-sm.png",+ "description": "BitcoinAbuse.com is a public database of bitcoin "+ "addresses used by scammers, hackers, and criminals."+ "Bitcoin is anonymous if used perfectly. Luckily, no "+ "one is perfect. Even hackers make mistakes. It only "+ "takes one slip to link stolen bitcoin to a hacker's "+ "their real identity. It is our hope that by making a "+ "public database of bitcoin addresses used by criminals it "+ "will be harder for criminals to convert the digital currency"+ " back into fiat money.",+ },+ }+ opts = {+ "api_key": "",+ }+ optdescs = {+ "api_key": "BitcoinAbuse 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"]++ # What events this module produces+ def producedEvents(self):+ return ["MALICIOUS_BITCOIN_ADDRESS"]++ def query(self, address):+ params = {"address": address, "api_token": self.opts["api_key"]}+ qry = urlencode(params)+ res = self.sf.fetchUrl(+ f"https://www.bitcoinabuse.com/api/reports/check?{qry}",+ timeout=self.opts["_fetchtimeout"],+ useragent="SpiderFoot",+ )+ if res["code"] != "200":+ self.sf.info(f"Failed to get results for {address}, code {res['code']}")+ return None++ if res["content"] is None:+ self.sf.info(f"Failed to get results for {address}, empty content")+ return None++ try:+ info = json.loads(res["content"])+ except Exception as e:+ self.sf.error("Error processing JSON response from BitcoinAbuse.", False)+ return None++ return info++ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data++ if self.errorState:+ return None++ self.sf.debug(f"Received event, {eventName}, from {srcModuleName}")++ if self.opts["api_key"] == "":+ self.sf.error("You enabled sfp_template but did not set an API key!", False)+ self.errorState = True+ return None++ if eventData in self.results:+ self.sf.debug(f"Skipping {eventData}, already checked.")+ return None+ else:+ self.results[eventData] = True++ if eventName == "BITCOIN_ADDRESS":+ rec = self.query(eventData)+ if rec["count"] != 0:+ evt = SpiderFootEvent(+ "MALICIOUS_BITCOIN_ADDRESS", rec["address"], self.__name__, event+ )+ self.notifyListeners(evt)++ rirevt = SpiderFootEvent(+ "RAW_RIR_DATA", json.dumps(rec), self.__name__, event+ )+ self.notifyListeners(rirevt)diff --git a/sfdb.py b/sfdb.pyindex f00374ab..f0d8868b 100644--- a/sfdb.py+++ b/sfdb.py@@ -167,6 +167,7 @@ class SpiderFootDb:"INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('LINKED_URL_INTERNAL', 'Linked URL - Internal', 0, 'SUBENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('LINKED_URL_EXTERNAL', 'Linked URL - External', 0, 'SUBENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('MALICIOUS_ASN', 'Malicious AS', 0, 'DESCRIPTOR')",+ "INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('MALICIOUS_BITCOIN_ADDRESS', 'Malicious Bitcoin Address', 0, 'DESCRIPTOR')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('MALICIOUS_IPADDR', 'Malicious IP Address', 0, 'DESCRIPTOR')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('MALICIOUS_COHOST', 'Malicious Co-Hosted Site', 0, 'DESCRIPTOR')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('MALICIOUS_EMAILADDR', 'Malicious E-mail Address', 0, 'DESCRIPTOR')",diff --git a/test/unit/modules/test_sfp_bitcoinabuse.py b/test/unit/modules/test_sfp_bitcoinabuse.pynew file mode 100644index 00000000..da8bd29e--- /dev/null+++ b/test/unit/modules/test_sfp_bitcoinabuse.py@@ -0,0 +1,86 @@+# test_sfp_bitcoinabuse.py+from sflib import SpiderFoot, SpiderFootEvent+from spiderfoot import SpiderFootTarget+import unittest+from modules.sfp_bitcoinabuse import sfp_bitcoinabuse+++class TestModuleBitcoinAbuse(unittest.TestCase):+ """+ Test modules.sfp_bitcoinabuse+ """++ default_options = {+ '_debug': False, # Debug+ '__logging': True, # Logging in general+ '__outputfilter': None, # Event types to filter from modules' output+ '__blocknotif': False, # Block notifications+ '_fatalerrors': False,+ '_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+ '__webaddr': '127.0.0.1',+ '__webport': 5001,+ '__docroot': '', # don't put trailing /+ '__modules__': None, # List of modules. Will be set after start-up.+ '_socks1type': '',+ '_socks2addr': '',+ '_socks3port': '',+ '_socks4user': '',+ '_socks5pwd': '',+ '_socks6dns': True,+ '_torctlport': 9051,+ '__logstdout': False+ }++ @unittest.skip("todo")+ def test_opts(self):+ module = sfp_bitcoinabuse()+ 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_bitcoinabuse()+ module.setup(sf, dict())++ def test_watchedEvents_should_return_list(self):+ module = sfp_bitcoinabuse()+ self.assertIsInstance(module.watchedEvents(), list)++ def test_producedEvents_should_return_list(self):+ module = sfp_bitcoinabuse()+ self.assertIsInstance(module.producedEvents(), list)++ @unittest.skip("todo")+ def test_handleEvent(self):+ """+ Test handleEvent(self, event)+ """+ sf = SpiderFoot(self.default_options)++ module = sfp_bitcoinabuse()+ 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)