Skip to content

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

First module for consuming data from an external tool: DNSTwist.

Steve Micallef2864f17459a4
diff --git a/modules/sfp_tool_dnstwist.py b/modules/sfp_tool_dnstwist.py
new file mode 100644
index 00000000..c1c2a2d4
--- /dev/null
+++ b/modules/sfp_tool_dnstwist.py
@@ -0,0 +1,115 @@
+# -*- coding: utf-8 -*-
+# -------------------------------------------------------------------------------
+# Name: sfp_tool_dnstwist
+# Purpose: SpiderFoot plug-in for using the 'dnstwist' tool.
+# Tool: https://github.com/elceef/dnstwist
+#
+# Author: Steve Micallef <[email protected]>
+#
+# Created: 12/11/2018
+# Copyright: (c) Steve Micallef 2018
+# Licence: GPL
+# -------------------------------------------------------------------------------
+
+from subprocess import Popen, PIPE
+import time
+import re
+import json
+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
+
+class sfp_tool_dnstwist(SpiderFootPlugin):
+ """Tool - DNSTwist:Footprint,Investigate:DNS:tool:Identify bit-squatting, typo and other similar domains to the target using a local DNSTwist installation."""
+
+
+ # Default options
+ opts = {
+ # Commonly used ports on external-facing systems
+ 'dnstwistpath': "",
+ }
+
+ # Option descriptions
+ optdescs = {
+ 'dnstwistpath': "Path to the where the dnstwist.py file lives. Must be set.",
+ }
+
+ results = None
+ errorState = False
+
+ def setup(self, sfc, userOpts=dict()):
+ self.sf = sfc
+ self.results = dict()
+ self.errorState = False
+ self.__dataSource__ = "DNS"
+
+ for opt in userOpts.keys():
+ self.opts[opt] = userOpts[opt]
+
+ # What events is this module interested in for input
+ def watchedEvents(self):
+ return ['DOMAIN_NAME']
+
+ # What events this module produces
+ # This is to support the end user in selecting modules based on events
+ # produced.
+ def producedEvents(self):
+ return ["SIMILARDOMAIN"]
+
+ # Handle events sent to this module
+ def handleEvent(self, event):
+ eventName = event.eventType
+ srcModuleName = event.module
+ eventData = event.data
+
+ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
+
+ if self.errorState:
+ return None
+
+ # Don't look up stuff twice, check IP == IP here
+ if eventData in self.results:
+ self.sf.debug("Skipping " + eventData + " as already scanned.")
+ return None
+
+ if not self.opts['dnstwistpath']:
+ self.sf.error("You enabled sfp_tool_dnstwist but did not set a path to the tool!", False)
+ self.errorState = True
+ return None
+
+ # If tool is not found, abort
+ if self.opts['dnstwistpath'].endswith('dnstwist.py'):
+ exe = self.opts['dnstwistpath']
+ elif self.opts['dnstwistpath'].endswith('/'):
+ exe = self.opts['dnstwistpath'] + "dnstwist.py"
+ else:
+ exe = self.opts['dnstwistpath'] + "/dnstwist.py"
+
+ # Sanitize domain name.
+ if not self.sf.sanitiseInput(eventData):
+ self.sf.error("Invalid input, refusing to run.", False)
+ return None
+
+ try:
+ p = Popen(["python", exe, "-f", "json", "-r", eventData], stdout=PIPE, stderr=PIPE)
+ stdout, stderr = p.communicate(input=None)
+ if p.returncode == 0:
+ content = stdout
+ else:
+ self.sf.error("Unable to read DNSTwist content.", False)
+ self.sf.debug("Error running DNSTwist: " + stderr + ", " + stdout)
+ return None
+
+ # For each line in output, generate a SIMILARDOMAIN event
+ try:
+ j = json.loads(content)
+ for r in j:
+ evt = SpiderFootEvent("SIMILARDOMAIN", r['domain-name'],
+ self.__name__, event)
+ self.notifyListeners(evt)
+ except BaseException as e:
+ self.sf.error("Couldn't parse the JSON output of DNSTwist: " + str(e), False)
+ return None
+ except BaseException as e:
+ self.sf.error("Unable to run DNSTwist: " + str(e), False)
+ return None
+
+# End of sfp_tool_dnstwist class
diff --git a/sflib.py b/sflib.py
index ab7ab7e6..8974177b 100644
--- a/sflib.py
+++ b/sflib.py
@@ -34,6 +34,10 @@ import threading
from bs4 import BeautifulSoup, SoupStrainer
from copy import deepcopy, copy
+# For hiding the SSL warnings coming from the requests lib
+import urllib3
+urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
+
class SpiderFoot:
dbh = None
GUID = None
@@ -290,6 +294,9 @@ class SpiderFoot:
return self.dbh.scanLogEvent(self.GUID, level, message, component)
def error(self, error, exception=True):
+ if not self.opts['__logging']:
+ return None
+
if self.dbh is None:
print '[Error] ' + error
else:
@@ -308,6 +315,9 @@ class SpiderFoot:
sys.exit(-1)
def status(self, message):
+ if not self.opts['__logging']:
+ return None
+
if self.dbh is None:
print "[Status] " + message
else:
@@ -316,6 +326,9 @@ class SpiderFoot:
print "[*] " + message
def info(self, message):
+ if not self.opts['__logging']:
+ return None
+
frm = inspect.stack()[1]
mod = inspect.getmodule(frm[0])
@@ -343,6 +356,8 @@ class SpiderFoot:
def debug(self, message):
if not self.opts['_debug']:
return
+ if not self.opts['__logging']:
+ return None
frm = inspect.stack()[1]
mod = inspect.getmodule(frm[0])
@@ -749,6 +764,16 @@ class SpiderFoot:
ret.append(unicode(addr, 'utf-8', errors='replace'))
return ret
+ # Verify input is OK to execute
+ def sanitiseInput(self, cmd):
+ chars = ['a','b','c','d','e','f','g','h','i','j','k','l','m',
+ 'n','o','p','q','r','s','t','u','v','w','x','y','z',
+ '0','1','2','3','4','5','6','7','8','9','-','.']
+ for c in cmd:
+ if c.lower() not in chars:
+ return False
+ return True
+
# Return dictionary words and/or names
def dictwords(self):
wd = dict()