SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
sfp_tool_wappalyzer: New module for the wappalyzer tool.
smicallef58c7fcbaf654
diff --git a/modules/sfp_tool_wappalyzer.py b/modules/sfp_tool_wappalyzer.pynew file mode 100644index 00000000..3aed05fe--- /dev/null+++ b/modules/sfp_tool_wappalyzer.py@@ -0,0 +1,157 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_tool_wappalyzer+# Purpose: SpiderFoot plug-in for using the 'Wappalyzer' tool.+# Tool: https://github.com/EnableSecurity/wappalyzer+#+# Author: Steve Micallef <[email protected]>+#+# Created: 2022-04-02+# Copyright: (c) Steve Micallef 2022+# Licence: GPL+# -------------------------------------------------------------------------------++import os+import sys+import json+from subprocess import Popen, PIPE, TimeoutExpired++from spiderfoot import SpiderFootPlugin, SpiderFootEvent, SpiderFootHelpers+++class sfp_tool_wappalyzer(SpiderFootPlugin):++ meta = {+ "name": "Tool - Wappalyzer",+ "summary": "Wappalyzer indentifies technologies on websites.",+ "flags": ["tool"],+ "useCases": [+ "Footprint",+ "Investigate"+ ],+ "categories": ["Content Analysis"],+ "toolDetails": {+ "name": "Wappalyzer",+ "description": "Wappalyzer identifies technologies on websites, including content management systems, ecommerce platforms, JavaScript frameworks, analytics tools and much more.",+ "website": "https://www.wappalyzer.com/",+ "repository": "https://github.com/AliasIO/Wappalyzer"+ }+ }++ # Default options+ opts = {+ "node_path": "/usr/bin/node",+ "wappalyzer_path": ""+ }++ # Option descriptions+ optdescs = {+ "node_path": "Path to your NodeJS binary. Must be set.",+ "wappalyzer_path": "Path to your wappalyzer cli.js file. Must be set.",+ }++ # Target+ results = None+ errorState = False++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc+ self.results = self.tempStorage()++ for opt in userOpts.keys():+ self.opts[opt] = userOpts[opt]++ def watchedEvents(self):+ return ["INTERNET_NAME"]++ def producedEvents(self):+ return ["OPERATING_SYSTEM", "SOFTWARE_USED", "WEBSERVER_TECHNOLOGY"]++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data++ self.debug(f"Received event, {eventName}, from {srcModuleName}")++ if self.errorState:+ return++ if not self.opts['wappalyzer_path']:+ self.error("You enabled sfp_tool_wappalyzer but did not set a path to the tool!")+ self.errorState = True+ return++ exe = self.opts['wappalyzer_path']+ if self.opts['wappalyzer_path'].endswith('/'):+ exe = f"{exe}cli.js"++ if not os.path.isfile(exe):+ self.error(f"File does not exist: {exe}")+ self.errorState = True+ return++ if not SpiderFootHelpers.sanitiseInput(eventData):+ self.debug("Invalid input, skipping.")+ return++ # Don't look up stuff twice+ if eventData in self.results:+ self.debug(f"Skipping {eventData} as already scanned.")+ return+ self.results[eventData] = True++ try:+ args = [self.opts["node_path"], exe, f"https://{eventData}"]+ p = Popen(args, stdout=PIPE, stderr=PIPE)+ try:+ stdout, stderr = p.communicate(input=None, timeout=60)+ if p.returncode == 0:+ content = stdout.decode(sys.stdin.encoding)+ else:+ self.error("Unable to read Wappalyzer content.")+ self.error(f"Error running Wappalyzer: {stderr}, {stdout}")+ return+ except TimeoutExpired:+ p.kill()+ stdout, stderr = p.communicate()+ self.debug("Timed out waiting for Wappalyzer to finish")+ return+ except BaseException as e:+ self.error(f"Unable to run Wappalyzer: {e}")+ return++ try:+ data = json.loads(content)+ for item in data["technologies"]:+ for cat in item["categories"]:+ if cat["name"] == "Operating systems":+ evt = SpiderFootEvent(+ "OPERATING_SYSTEM",+ item["name"],+ self.__name__,+ event,+ )+ elif cat["name"] == "Web servers":+ evt = SpiderFootEvent(+ "WEBSERVER_TECHNOLOGY",+ item["name"],+ self.__name__,+ event,+ )+ else:+ evt = SpiderFootEvent(+ "SOFTWARE_USED",+ item["name"],+ self.__name__,+ event,+ )+ self.notifyListeners(evt)+ except (KeyError, ValueError) as e:+ self.error(f"Couldn't parse the JSON output of Wappalyzer: {e}")+ self.error(f"Wappalyzer content: {content}")+ return+++# End of sfp_tool_wappalyzer classdiff --git a/test/unit/modules/test_sfp_tool_wappalyzer.py b/test/unit/modules/test_sfp_tool_wappalyzer.pynew file mode 100644index 00000000..32d5a6d9--- /dev/null+++ b/test/unit/modules/test_sfp_tool_wappalyzer.py@@ -0,0 +1,60 @@+# test_sfp_tool_wappalyzer.py+import pytest+import unittest++from modules.sfp_tool_wappalyzer import sfp_tool_wappalyzer+from sflib import SpiderFoot+from spiderfoot import SpiderFootEvent, SpiderFootTarget+++class TestModuleWappalyzer(unittest.TestCase):+ """+ Test modules.sfp_tool_wappalyzer+ """++ def test_opts(self):+ module = sfp_tool_wappalyzer()+ 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_wappalyzer()+ module.setup(sf, dict())++ def test_watchedEvents_should_return_list(self):+ module = sfp_tool_wappalyzer()+ self.assertIsInstance(module.watchedEvents(), list)++ def test_producedEvents_should_return_list(self):+ module = sfp_tool_wappalyzer()+ 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_wappalyzer()+ 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)+ self.assertTrue(module.errorState)