Skip to content

SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.

sfp_tool_snallygaster: New module for the snallygaster tool.

smicallef395da7d52260
diff --git a/modules/sfp_tool_snallygaster.py b/modules/sfp_tool_snallygaster.py
new file mode 100644
index 00000000..5043c35b
--- /dev/null
+++ b/modules/sfp_tool_snallygaster.py
@@ -0,0 +1,156 @@
+# -*- coding: utf-8 -*-
+# -------------------------------------------------------------------------------
+# Name: sfp_tool_snallygaster
+# Purpose: SpiderFoot plug-in for using the snallygaster tool.
+# Tool: https://github.com/hannob/snallygaster
+#
+# Author: <[email protected]>
+#
+# Created: 2022-04-02
+# Copyright: (c) Steve Micallef 2022
+# Licence: GPL
+# -------------------------------------------------------------------------------
+
+import sys
+import json
+import os.path
+from subprocess import PIPE, Popen
+
+from spiderfoot import SpiderFootPlugin, SpiderFootEvent, SpiderFootHelpers
+
+
+class sfp_tool_snallygaster(SpiderFootPlugin):
+
+ meta = {
+ "name": "Tool - snallygaster",
+ "summary": "Finds file leaks and other security problems on HTTP servers.",
+ "flags": ["tool"],
+ "useCases": ["Footprint", "Investigate"],
+ "categories": ["Crawling and Scanning"],
+ "toolDetails": {
+ "name": "snallygaster",
+ "description": "snallygaster is a tool that looks for files accessible on "
+ "web servers that shouldn't be public and can pose a security "
+ "risk. Typical examples include publicly accessible git "
+ "repositories, backup files potentially containing passwords "
+ " or database dumps. In addition, it contains a few checks "
+ " for other security vulnerabilities.",
+ "website": "https://github.com/hannob/snallygaster",
+ "repository": "https://github.com/hannob/snallygaster"
+ }
+ }
+
+ opts = {
+ 'snallygaster_path': ''
+ }
+
+ optdescs = {
+ "snallygaster_path": "Path to your snallygaster binary. 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 [
+ 'VULNERABILITY_GENERAL',
+ 'VULNERABILITY_CVE_CRITICAL',
+ 'VULNERABILITY_CVE_HIGH',
+ 'VULNERABILITY_CVE_MEDIUM',
+ 'VULNERABILITY_CVE_LOW'
+ ]
+
+ 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 eventData in self.results:
+ self.debug(f"Skipping {eventData} as already scanned.")
+ return
+
+ self.results[eventData] = True
+
+ if not self.opts['snallygaster_path']:
+ self.error("You enabled sfp_tool_snallygaster but did not set a path to the tool!")
+ self.errorState = True
+ return
+
+ exe = self.opts["snallygaster_path"]
+ if self.opts["snallygaster_path"].endswith("/"):
+ exe = f"{exe}snallygaster"
+
+ if not os.path.isfile(exe):
+ self.error(f"File does not exist: {exe}")
+ self.errorState = True
+ return
+
+ if not SpiderFootHelpers.sanitiseInput(eventData):
+ self.error("Invalid input, refusing to run.")
+ return
+
+ args = [
+ exe,
+ '--nowww',
+ '-j',
+ eventData
+ ]
+ try:
+ p = Popen(args, stdout=PIPE, stderr=PIPE)
+ out, stderr = p.communicate(input=None)
+ stdout = out.decode(sys.stdin.encoding)
+ except Exception as e:
+ self.error(f"Unable to run snallygaster: {e}")
+ return
+
+ if p.returncode != 0:
+ self.error(f"Unable to read onesixtyone output\nstderr: {stderr}\nstdout: {stdout}")
+ return
+
+ if not stdout:
+ self.debug(f"snallygaster returned no output for {eventData}")
+ return
+
+ try:
+ result_json = json.loads(stdout)
+ except Exception as e:
+ self.error(f"Could not parse snallygaster output as JSON: {e}\nstderr: {stderr}\nstdout: {stdout}")
+ return
+
+ if not result_json:
+ self.debug(f"snallygaster returned no output for {eventData}")
+ return
+
+ for res in result_json:
+ if "cause" not in res:
+ continue
+
+ text = f"Cause: {res['cause']}\nURL: {res['url']}"
+ if res["misc"]:
+ text += f"\nAdditional Info: {res['misc']}"
+ evt = SpiderFootEvent(
+ "VULNERABILITY_GENERAL",
+ text,
+ self.__name__,
+ event,
+ )
+ self.notifyListeners(evt)
+
+# End of sfp_tool_snallygaster class
diff --git a/test/unit/modules/test_sfp_tool_snallygaster.py b/test/unit/modules/test_sfp_tool_snallygaster.py
new file mode 100644
index 00000000..aa5e20f5
--- /dev/null
+++ b/test/unit/modules/test_sfp_tool_snallygaster.py
@@ -0,0 +1,60 @@
+# test_sfp_tool_snallygaster.py
+import pytest
+import unittest
+
+from modules.sfp_tool_snallygaster import sfp_tool_snallygaster
+from sflib import SpiderFoot
+from spiderfoot import SpiderFootEvent, SpiderFootTarget
+
+
+class TestModuleSnallygaster(unittest.TestCase):
+ """
+ Test modules.sfp_tool_snallygaster
+ """
+
+ def test_opts(self):
+ module = sfp_tool_snallygaster()
+ 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_snallygaster()
+ module.setup(sf, dict())
+
+ def test_watchedEvents_should_return_list(self):
+ module = sfp_tool_snallygaster()
+ self.assertIsInstance(module.watchedEvents(), list)
+
+ def test_producedEvents_should_return_list(self):
+ module = sfp_tool_snallygaster()
+ 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_snallygaster()
+ 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)