SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
New module: PunkSpider
smicallefcbc71afec771
diff --git a/modules/sfp_punkspider.py b/modules/sfp_punkspider.pynew file mode 100644index 00000000..02aa66c7--- /dev/null+++ b/modules/sfp_punkspider.py@@ -0,0 +1,113 @@+# -------------------------------------------------------------------------------+# Name: sfp_punkspider+# Purpose: Query the QOMPLX PunkSpider API to see if our target appears.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 07/08/2021+# Copyright: (c) Steve Micallef+# Licence: GPL+# -------------------------------------------------------------------------------++import hashlib+import json++from spiderfoot import SpiderFootEvent, SpiderFootPlugin+++class sfp_punkspider(SpiderFootPlugin):++ meta = {+ 'name': "PunkSpider",+ 'summary': "Check the QOMPLX punkspider.io service to see if the target is listed as vulnerable.",+ 'flags': [""],+ 'useCases': ["Footprint", "Investigate", "Passive"],+ 'categories': ["Leaks, Dumps and Breaches"],+ 'dataSource': {+ 'website': "https://punkspider.io/",+ 'model': "FREE_NOAUTH_UNLIMITED",+ 'logo': "https://punkspider.io/img/logo.svg",+ 'description': "The idea behind Punkspider is very simple - we're doing a bunch "+ "of complicated stuff to find insecurities in massive amounts of websites, with "+ "the goal of scanning the entire Internet."+ }+ }+ # Default options+ opts = {+ }++ # Option descriptions+ optdescs = {+ }++ # Be sure to completely clear any class variables in setup()+ # or you run the risk of data persisting between scan runs.++ results = None++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc+ self.results = self.tempStorage()++ # 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 input+ def watchedEvents(self):+ return ["INTERNET_NAME"]++ # What events this module produces+ def producedEvents(self):+ ret = ["VULNERABILITY"]++ return ret++ def query(self, qry):+ ret = None+ qryhash = hashlib.md5(qry.encode('utf-8', errors='replace').lower()).hexdigest()+ url = f"https://api.punkspider.org/api/partial-hash/{qryhash}"++ res = self.sf.fetchUrl(url, timeout=30, useragent=self.opts['_useragent'])+ if res['content'] is None:+ self.sf.debug("No content returned from PunkSpider")+ return None++ try:+ ret = json.loads(res['content'])+ except Exception as e:+ self.sf.error(f"Error processing response from PunkSpider: {e}")+ return None+ return ret++ # 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 eventData in self.results:+ self.sf.debug(f"Skipping {eventData}, already checked.")+ return None++ self.results[eventData] = True++ res = self.query(eventData)+ if not res:+ return None++ for rec in res:+ if 'vulns' not in res[rec]:+ continue++ for vuln in res[rec]['vulns']:+ if res[rec]['vulns'][vuln] == 0:+ continue+ e = SpiderFootEvent("VULNERABILITY", f"{vuln}: {res[rec]['vulns'][vuln]}", self.__name__, event)+ self.notifyListeners(e)++# End of sfp_punkspider classdiff --git a/test/unit/modules/test_sfp_punkspider.py b/test/unit/modules/test_sfp_punkspider.pynew file mode 100644index 00000000..c5b9417a--- /dev/null+++ b/test/unit/modules/test_sfp_punkspider.py@@ -0,0 +1,60 @@+# test_sfp_punkspider.py+import pytest+import unittest++from modules.sfp_punkspider import sfp_punkspider+from sflib import SpiderFoot+from spiderfoot import SpiderFootEvent, SpiderFootTarget+++class TestModulepunkspider(unittest.TestCase):+ """+ Test modules.sfp_punkspider+ """++ def test_opts(self):+ module = sfp_punkspider()+ 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_punkspider()+ module.setup(sf, dict())++ def test_watchedEvents_should_return_list(self):+ module = sfp_punkspider()+ self.assertIsInstance(module.watchedEvents(), list)++ def test_producedEvents_should_return_list(self):+ module = sfp_punkspider()+ self.assertIsInstance(module.producedEvents(), list)++ @unittest.skip("todo")+ def test_handleEvent(self):+ """+ Test handleEvent(self, event)+ """+ sf = SpiderFoot(self.default_options)++ module = sfp_punkspider()+ module.setup(sf, dict())++ target_value = 'example target value'+ target_type = 'INTERNET_NAME'+ 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)