Skip to content

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

Port scanning module.

smicallef2d7009df2f2f
diff --git a/evtypes.sql b/evtypes.sql
index d2f1c143..249315a2 100644
--- a/evtypes.sql
+++ b/evtypes.sql
@@ -7,6 +7,7 @@ INSERT INTO tbl_event_types (event, event_descr) VALUES ('GEOINFO', 'Physical Lo
INSERT INTO tbl_event_types (event, event_descr) VALUES ('IP_ADDRESS', 'IP Address');
INSERT INTO tbl_event_types (event, event_descr) VALUES ('SUBDOMAIN', 'Sub-domain');
INSERT INTO tbl_event_types (event, event_descr) VALUES ('SIMILARDOMAIN', 'Similar Domain');
+INSERT INTO tbl_event_types (event, event_descr) VALUES ('TCP_PORT_OPEN', 'Open TCP Port');
INSERT INTO tbl_event_types (event, event_descr) VALUES ('URL', 'URL');
INSERT INTO tbl_event_types (event, event_descr) VALUES ('WEBCONTENT', 'Web Content');
INSERT INTO tbl_event_types (event, event_descr) VALUES ('WEBCONTENT_FORM', 'Web Content (Form)');
diff --git a/modules/sfp_portscan_basic.py b/modules/sfp_portscan_basic.py
new file mode 100644
index 00000000..863b0cfa
--- /dev/null
+++ b/modules/sfp_portscan_basic.py
@@ -0,0 +1,85 @@
+#-------------------------------------------------------------------------------
+# Name: sfp_portscan_basic
+# Purpose: SpiderFoot plug-in for gathering IP addresses from sub-domains
+#
+# Author: Steve Micallef <[email protected]>
+#
+# Created: 16/09/2012
+# Copyright: (c) Steve Micallef 2012
+# Licence: GPL
+#-------------------------------------------------------------------------------
+
+import sys
+import re
+import socket
+from sflib import SpiderFoot, SpiderFootPlugin
+
+# SpiderFoot standard lib (must be initialized in setup)
+sf = None
+
+class sfp_portscan_basic(SpiderFootPlugin):
+ """Scans for commonly open TCP ports on Internet-facing systems."""
+
+ # Default options
+ opts = {
+ # These must always be set
+ '__debug': True,
+ '__debugfilter': '',
+ # Commonly used ports on external-facing systems
+ 'ports': [ 21, 22, 23, 25, 53, 79, 80, 81, 88, 110, 111,
+ 113, 119, 123, 137, 138, 139, 143, 161, 179,
+ 389, 443, 445, 465, 512, 513, 514, 515, 631, 636,
+ 990, 992, 993, 995, 1080, 8080, 8888, 9000 ]
+ }
+
+ # URL this instance is working on
+ seedUrl = None
+ baseDomain = None # calculated from the URL in setup
+ results = dict()
+
+ def setup(self, url, userOpts=dict()):
+ global sf
+ self.seedUrl = url
+ self.results = dict()
+
+ for opt in userOpts.keys():
+ self.opts[opt] = userOpts[opt]
+
+ # For error reporting, debug, etc.
+ sf = SpiderFoot(self.opts)
+
+ # Extract the 'meaningful' part of the FQDN from the URL
+ self.baseDomain = sf.urlBaseDom(self.seedUrl)
+ sf.debug('Base Domain: ' + self.baseDomain)
+
+ # What events is this module interested in for input
+ def watchedEvents(self):
+ return ['IP_ADDRESS']
+
+ # Handle events sent to this module
+ def handleEvent(self, srcModuleName, eventName, eventSource, eventData):
+ sf.debug("Received event, " + eventName + ", from " + srcModuleName)
+
+ # Don't look up stuff twice
+ if self.results.has_key(eventData):
+ sf.debug("Skipping " + eventData + " as already scanned.")
+ return None
+ else:
+ self.results[eventData] = True
+
+ for port in self.opts['ports']:
+ sf.debug("Checking port: " + str(port) + " against " + eventData)
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ res = s.connect_ex((eventData, port))
+ if (res == 0):
+ sf.debug("TCP Port " + str(port) + " found to be OPEN.")
+ self.notifyListeners("TCP_PORT_OPEN", eventData, str(port))
+ s.close()
+
+ return None
+
+# End of sfp_portscan_basic class
+
+if __name__ == '__main__':
+ print "This module cannot be run stand-alone."
+ exit(-1)
diff --git a/sfdbsetup.py b/sfdbsetup.py
index 8a7f086e..f1c8b675 100644
--- a/sfdbsetup.py
+++ b/sfdbsetup.py
@@ -73,6 +73,7 @@ class SpiderFootDbInit:
"INSERT INTO tbl_event_types (event, event_descr) VALUES ('IP_ADDRESS', 'IP Address')",
"INSERT INTO tbl_event_types (event, event_descr) VALUES ('SUBDOMAIN', 'Sub-domain')",
"INSERT INTO tbl_event_types (event, event_descr) VALUES ('SIMILARDOMAIN', 'Similar Domain')",
+ "INSERT INTO tbl_event_types (event, event_descr) VALUES ('TCP_PORT_OPEN', 'Open TCP Port')",
"INSERT INTO tbl_event_types (event, event_descr) VALUES ('URL', 'URL')",
"INSERT INTO tbl_event_types (event, event_descr) VALUES ('WEBCONTENT', 'Web Content')",
"INSERT INTO tbl_event_types (event, event_descr) VALUES ('WEBCONTENT_FORM', 'Web Content (Form)')",
diff --git a/sflib.py b/sflib.py
index 088a1b13..f439318a 100644
--- a/sflib.py
+++ b/sflib.py
@@ -113,7 +113,7 @@ class SpiderFoot:
else:
storeopts[mod + ":" + opt] = 0
if type(opts['__modules__'][mod]['opts'][opt]) is list:
- storeopts[mod + ":" + opt] = ','.join(opts['__modules__'][mod]['opts'][opt])
+ storeopts[mod + ":" + opt] = ','.join(str(x) for x in opts['__modules__'][mod]['opts'][opt])
return storeopts
@@ -143,12 +143,18 @@ class SpiderFoot:
returnOpts[opt] = int(opts[opt])
if type(referencePoint[opt]) is list:
- returnOpts[opt] = str(opts[opt]).split(",")
+ if type(referencePoint[opt][0]) is int:
+ returnOpts[opt] = list()
+ for x in str(opts[opt]).split(","):
+ returnOpts[opt].append(int(x))
+ else:
+ returnOpts[opt] = str(opts[opt]).split(",")
if not referencePoint.has_key('__modules__'):
return returnOpts
# Module options
+ # A lot of mess to handle typing..
for modName in referencePoint['__modules__']:
for opt in referencePoint['__modules__'][modName]['opts']:
if opt.startswith('_') and filterSystem:
@@ -167,7 +173,12 @@ class SpiderFoot:
returnOpts['__modules__'][modName]['opts'][opt] = int(opts[modName + ":" + opt])
if type(referencePoint['__modules__'][modName]['opts'][opt]) is list:
- returnOpts['__modules__'][modName]['opts'][opt] = str(opts[modName + ":" + opt]).split(",")
+ if type(referencePoint['__modules__'][modName]['opts'][opt][0]) is int:
+ returnOpts['__modules__'][modName]['opts'][opt] = list()
+ for x in str(opts[modName + ":" + opt]).split(","):
+ returnOpts['__modules__'][modName]['opts'][opt].append(int(x))
+ else:
+ returnOpts['__modules__'][modName]['opts'][opt] = str(opts[modName + ":" + opt]).split(",")
return returnOpts
#