SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Add sfp_tool_wafw00f (#1263)
bcoles172e0be80cd0
diff --git a/modules/sfp_tool_wafw00f.py b/modules/sfp_tool_wafw00f.pynew file mode 100644index 00000000..bb930e07--- /dev/null+++ b/modules/sfp_tool_wafw00f.py@@ -0,0 +1,153 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_tool_wafw00f+# Purpose: SpiderFoot plug-in for using the WAFW00F tool.+# Tool: https://github.com/EnableSecurity/wafw00f+#+# Author: <[email protected]>+#+# Created: 2021-03-10+# Copyright: (c) bcoles 2021+# Licence: GPL+# -------------------------------------------------------------------------------++import json+import os.path+from subprocess import PIPE, Popen++from spiderfoot import SpiderFootEvent, SpiderFootPlugin+++class sfp_tool_wafw00f(SpiderFootPlugin):+ meta = {+ 'name': "Tool - WAFW00F",+ 'summary': "Identify what web application firewall (WAF) is in use on the specified website.",+ 'flags': ["tool"],+ 'useCases': ["Footprint", "Investigate"],+ 'categories': ["Crawling and Scanning"],+ 'toolDetails': {+ 'name': "WAFW00F",+ 'description': "WAFW00F allows one to identify and fingerprint Web Application Firewall (WAF) products protecting a website.",+ 'website': 'https://github.com/EnableSecurity/wafw00f',+ 'repository': 'https://github.com/EnableSecurity/wafw00f'+ },+ }++ opts = {+ 'python_path': 'python3',+ 'wafw00f_path': ''+ }++ optdescs = {+ 'python_path': "Path to Python 3 interpreter to use for wafw00f. If just 'python3' then it must be in your $PATH.",+ 'wafw00f_path': "Path to the wafw00f executable file. Must be set."+ }++ results = None+ errorState = False++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc+ self.results = dict()+ self.errorState = False+ self.__dataSource__ = "Target Website"++ for opt in userOpts.keys():+ self.opts[opt] = userOpts[opt]++ def watchedEvents(self):+ return ['INTERNET_NAME']++ def producedEvents(self):+ return ['RAW_RIR_DATA', 'WEBSERVER_TECHNOLOGY']++ 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++ if eventData in self.results:+ self.sf.debug(f"Skipping {eventData} as already scanned.")+ return++ self.results[eventData] = True++ if not self.opts['wafw00f_path']:+ self.sf.error("You enabled sfp_tool_wafw00f but did not set a path to the tool!")+ self.errorState = True+ return++ exe = self.opts['wafw00f_path']+ if self.opts['wafw00f_path'].endswith('/'):+ exe = exe + 'wafw00f'++ if not os.path.isfile(exe):+ self.sf.error(f"File does not exist: {exe}")+ self.errorState = True+ return++ url = eventData++ if not self.sf.sanitiseInput(url):+ self.sf.error("Invalid input, refusing to run.")+ return++ args = [+ self.opts['python_path'],+ exe,+ '-a',+ '-o-',+ '-f',+ 'json',+ url+ ]+ try:+ p = Popen(args, stdout=PIPE, stderr=PIPE)+ stdout, stderr = p.communicate(input=None)+ except Exception as e:+ self.sf.error(f"Unable to run wafw00f: {e}")+ return++ if p.returncode != 0:+ self.sf.error(f"Unable to read wafw00f output\nstderr: {stderr}\nstdout: {stdout}")+ return++ if not stdout:+ self.sf.debug(f"wafw00f returned no output for {eventData}")+ return++ try:+ result_json = json.loads(stdout)+ except Exception as e:+ self.sf.error(f"Could not parse wafw00f output as JSON: {e}\nstdout: {stdout}")+ return++ evt = SpiderFootEvent('RAW_RIR_DATA', json.dumps(result_json), self.__name__, event)+ self.notifyListeners(evt)++ for waf in result_json:+ if not waf:+ continue++ firewall = waf.get('firewall')+ if not firewall:+ continue+ if firewall == 'Generic':+ continue++ manufacturer = waf.get('manufacturer')+ if not manufacturer:+ continue++ software = ' '.join(filter(None, [manufacturer, firewall]))++ if software:+ evt = SpiderFootEvent('WEBSERVER_TECHNOLOGY', software, self.__name__, event)+ self.notifyListeners(evt)++# End of sfp_tool_wafw00f classdiff --git a/test/unit/modules/test_sfp_tool_wafw00f.py b/test/unit/modules/test_sfp_tool_wafw00f.pynew file mode 100644index 00000000..f5046eb7--- /dev/null+++ b/test/unit/modules/test_sfp_tool_wafw00f.py@@ -0,0 +1,60 @@+# test_sfp_tool_wafw00f.py+import pytest+import unittest++from modules.sfp_tool_wafw00f import sfp_tool_wafw00f+from sflib import SpiderFoot+from spiderfoot import SpiderFootEvent, SpiderFootTarget+++class TestModuleWafw00f(unittest.TestCase):+ """+ Test modules.sfp_tool_wafw00f+ """++ def test_opts(self):+ module = sfp_tool_wafw00f()+ 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_tool_wafw00f()+ module.setup(sf, dict())++ def test_watchedEvents_should_return_list(self):+ module = sfp_tool_wafw00f()+ self.assertIsInstance(module.watchedEvents(), list)++ def test_producedEvents_should_return_list(self):+ module = sfp_tool_wafw00f()+ self.assertIsInstance(module.producedEvents(), list)++ def test_handleEvent_no_tool_path_configured_should_set_errorState(self):+ """+ Test handleEvent(self, event)+ """+ sf = SpiderFoot(self.default_options)++ module = sfp_tool_wafw00f()+ 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)+ self.assertTrue(module.errorState)