Skip to content

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

Logging support.

smicallefb247877a4be5
diff --git a/modules/sfp_dns.py b/modules/sfp_dns.py
index d6658dac..c170a7ce 100644
--- a/modules/sfp_dns.py
+++ b/modules/sfp_dns.py
@@ -25,9 +25,6 @@ class sfp_dns(SpiderFootPlugin):
# Default options
opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': '',
'resolveaffiliate': True, # Get IPs for affiliate domains
'reverselookup': True # Reverse-resolve IPs to names for
# more clues.
@@ -44,20 +41,18 @@ class sfp_dns(SpiderFootPlugin):
baseDomain = None # calculated from the URL in setup
results = dict()
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
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):
diff --git a/modules/sfp_geoip.py b/modules/sfp_geoip.py
index 715651ee..69ce235e 100644
--- a/modules/sfp_geoip.py
+++ b/modules/sfp_geoip.py
@@ -23,31 +23,25 @@ class sfp_geoip(SpiderFootPlugin):
"""Identifies the physical location of IP addresses identified."""
# Default options
- opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': ''
- }
+ opts = { }
# URL this instance is working on
seedUrl = None
baseDomain = None # calculated from the URL in setup
results = dict()
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
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):
diff --git a/modules/sfp_googlesearch.py b/modules/sfp_googlesearch.py
index 3e9252b7..ea30973e 100644
--- a/modules/sfp_googlesearch.py
+++ b/modules/sfp_googlesearch.py
@@ -23,9 +23,6 @@ class sfp_googlesearch(SpiderFootPlugin):
# Default options
opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': '',
'useragent': 'Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0',
'fetchlinks': True, # Should we fetch links on the base domain?
'pages': 20 # Number of google results pages to iterate
@@ -43,20 +40,18 @@ class sfp_googlesearch(SpiderFootPlugin):
baseDomain = None # calculated from the URL in setup
results = list()
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
self.seedUrl = url
self.results = list()
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):
diff --git a/modules/sfp_mail.py b/modules/sfp_mail.py
index d8ae8edb..54b244ed 100644
--- a/modules/sfp_mail.py
+++ b/modules/sfp_mail.py
@@ -22,9 +22,6 @@ class sfp_mail(SpiderFootPlugin):
# Default options
opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': '',
# options specific to this module
'includesubdomains': False, # Include e-mail addresses on sub-domains of
# the target domain
@@ -42,20 +39,18 @@ class sfp_mail(SpiderFootPlugin):
baseDomain = None # calculated from the URL in setup
results = dict()
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
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):
diff --git a/modules/sfp_pageinfo.py b/modules/sfp_pageinfo.py
index 97656cb9..c071ae71 100644
--- a/modules/sfp_pageinfo.py
+++ b/modules/sfp_pageinfo.py
@@ -34,31 +34,25 @@ class sfp_pageinfo(SpiderFootPlugin):
etc.)"""
# Default options
- opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': ''
- }
+ opts = { }
# URL this instance is working on
seedUrl = None
baseDomain = None # calculated from the URL in setup
results = dict()
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
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):
diff --git a/modules/sfp_portscan_basic.py b/modules/sfp_portscan_basic.py
index c8f3fcc5..3f8db8d2 100644
--- a/modules/sfp_portscan_basic.py
+++ b/modules/sfp_portscan_basic.py
@@ -24,9 +24,6 @@ class sfp_portscan_basic(SpiderFootPlugin):
# 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,
@@ -48,20 +45,18 @@ class sfp_portscan_basic(SpiderFootPlugin):
baseDomain = None # calculated from the URL in setup
results = dict()
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
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)
if self.opts['randomize']:
random.shuffle(self.opts['ports'])
diff --git a/modules/sfp_ripe.py b/modules/sfp_ripe.py
index c74f1e06..2d937587 100644
--- a/modules/sfp_ripe.py
+++ b/modules/sfp_ripe.py
@@ -23,31 +23,25 @@ class sfp_ripe(SpiderFootPlugin):
"""Queries RIPE to identify netblocks and other info."""
# Default options
- opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': ''
- }
+ opts = { }
# URL this instance is working on
seedUrl = None
baseDomain = None # calculated from the URL in setup
results = dict()
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
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):
diff --git a/modules/sfp_similar.py b/modules/sfp_similar.py
index c3e4c9f2..f0026cd3 100644
--- a/modules/sfp_similar.py
+++ b/modules/sfp_similar.py
@@ -46,8 +46,6 @@ class sfp_similar(SpiderFootPlugin):
# Default options
opts = {
- '__debug': True,
- '__debugfilter': '',
# Domaintools will 403 you without a browser-like useragent
'useragent': 'Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0',
'source': 'ALL', # whois, domaintools, namedroppers or ALL
@@ -70,20 +68,18 @@ class sfp_similar(SpiderFootPlugin):
seedUrl = None
baseDomain = None # calculated from the URL in setup
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
self.seedUrl = url
self.results = list()
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)
def findDomains(self, keyword, content):
matches = re.findall("([a-z0-9\-]*" + keyword + "[a-z0-9\-]*\.[a-z]+)", content)
diff --git a/modules/sfp_spider.py b/modules/sfp_spider.py
index 366278bb..15a62cc6 100644
--- a/modules/sfp_spider.py
+++ b/modules/sfp_spider.py
@@ -23,10 +23,6 @@ class sfp_spider(SpiderFootPlugin):
# Default options
opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': '',
- # options specific to this module
'robotsonly': False, # only follow links specified by robots.txt
'pause': 1, # number of seconds to pause between fetches
'maxpages': 10000, # max number of pages to fetch
@@ -66,26 +62,26 @@ class sfp_spider(SpiderFootPlugin):
# >> Not all of these will be populated at the same time <<
results = dict()
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
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)
-
if '://' not in self.seedUrl:
- sf.fatal("Please specify a full URL starting point, prefixed with http:// or https://")
+ sf.error("Please specify a full URL starting point, prefixed with http:// or https://")
+ return None
if re.match('.*\d+\.\d+\.\d+\.\d+.*', self.seedUrl):
- sf.fatal("Need a named URL to start with, not an IP.")
+ sf.error("Need a named URL to start with, not an IP.")
+ return None
# Extract the 'meaningful' part of the FQDN from the URL
self.baseDomain = sf.urlBaseDom(self.seedUrl)
- sf.debug('Base Domain: ' + self.baseDomain)
# Are we respecting robots.txt?
if self.opts['robotsonly']:
@@ -93,6 +89,9 @@ class sfp_spider(SpiderFootPlugin):
if robotsTxt['content'] != None:
sf.debug('robots.txt contents: ' + robotsTxt['content'])
self.robotsRules = sf.parseRobotsTxt(robotsTxt['content'])
+ else:
+ sf.error("Unable to fetch robots.txt and you've asked to abide by its contents.")
+ return None
# This module listens to no events
def watchedEvents(self):
diff --git a/modules/sfp_stor_db.py b/modules/sfp_stor_db.py
index 058ecd35..b2333c8f 100644
--- a/modules/sfp_stor_db.py
+++ b/modules/sfp_stor_db.py
@@ -23,9 +23,6 @@ class sfp_stor_db(SpiderFootPlugin):
# Default options
opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': '',
'maxstorage': 1024 # max bytes for any piece of info stored (0 = unlimited)
}
@@ -37,16 +34,16 @@ class sfp_stor_db(SpiderFootPlugin):
# URL this instance is working on
seedUrl = None
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
global sfdb
+
+ sf = sfc
self.seedUrl = url
for opt in userOpts.keys():
self.opts[opt] = userOpts[opt]
- # For error reporting, debug, etc.
- sf = SpiderFoot(self.opts)
# Use the database handle passed to us
sfdb = userOpts['__sfdb__']
diff --git a/modules/sfp_stor_print.py b/modules/sfp_stor_print.py
index 21e17275..335c8a80 100644
--- a/modules/sfp_stor_print.py
+++ b/modules/sfp_stor_print.py
@@ -20,9 +20,6 @@ sf = None
class sfp_stor_print(SpiderFootPlugin):
# Default options
opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': '',
'datasize': 100 # Number of characters to print from event data
}
@@ -34,16 +31,15 @@ class sfp_stor_print(SpiderFootPlugin):
# URL this instance is working on
seedUrl = None
- def __init__(self, url, userOpts=dict()):
+ def __init__(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
self.seedUrl = url
for opt in userOpts.keys():
self.opts[opt] = userOpts[opt]
- # For error reporting, debug, etc.
- sf = SpiderFoot(self.opts)
-
# Module description
def descr(self):
return "Debugging module for printing results instead of storing them."
diff --git a/modules/sfp_subdomain.py b/modules/sfp_subdomain.py
index 096eae48..6f337e23 100644
--- a/modules/sfp_subdomain.py
+++ b/modules/sfp_subdomain.py
@@ -20,31 +20,25 @@ sf = None
class sfp_subdomain(SpiderFootPlugin):
""" Identify hostnames / sub-domain names in URLs and obtained content. """
# Default options
- opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': ''
- }
+ opts = { }
# URL this instance is working on
seedUrl = None
baseDomain = None # calculated from the URL in __init__
results = dict()
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
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):
diff --git a/modules/sfp_template.py b/modules/sfp_template.py
index a6c939ce..1dfb8d5a 100644
--- a/modules/sfp_template.py
+++ b/modules/sfp_template.py
@@ -22,11 +22,7 @@ class sfp_XXX(SpiderFootPlugin):
"""About me here.."""
# Default options
- opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': ''
- }
+ opts = { }
# Option descriptions
optdescs = {
@@ -43,20 +39,18 @@ class sfp_XXX(SpiderFootPlugin):
baseDomain = None # calculated from the URL in setup
results = dict() # track results for duplicates
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
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):
diff --git a/modules/sfp_websvr.py b/modules/sfp_websvr.py
index 9d28abcf..015a842c 100644
--- a/modules/sfp_websvr.py
+++ b/modules/sfp_websvr.py
@@ -21,31 +21,25 @@ class sfp_websvr(SpiderFootPlugin):
"""Obtain web server banners to identify versions of web servers being used."""
# Default options
- opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': ''
- }
+ opts = { }
# URL this instance is working on
seedUrl = None
baseDomain = None # calculated from the URL in setup
results = dict()
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
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):
diff --git a/modules/sfp_xref.py b/modules/sfp_xref.py
index 759c3eea..eced494b 100644
--- a/modules/sfp_xref.py
+++ b/modules/sfp_xref.py
@@ -24,9 +24,6 @@ class sfp_xref(SpiderFootPlugin):
# Default options
opts = {
- # These must always be set
- '__debug': True,
- '__debugfilter': '',
'forcebase': True, # Check the base URL for a link back to the seed
# domain in order to be considered a valid xref
'checkbase': True, # Only check the base URL for a relationship if
@@ -50,20 +47,18 @@ class sfp_xref(SpiderFootPlugin):
seedUrl = None
baseDomain = None # calculated from the URL in setup
- def setup(self, url, userOpts=dict()):
+ def setup(self, sfc, url, userOpts=dict()):
global sf
+
+ sf = sfc
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):
diff --git a/sf.py b/sf.py
index 37743edb..f218db42 100755
--- a/sf.py
+++ b/sf.py
@@ -22,7 +22,6 @@ from sfwebui import SpiderFootWebUi, SpiderFootWebUiMini
# be overridden from saved configuration settings stored in the DB.
sfConfig = {
'_debug': True, # Debug
- '__debugfilter': '', # Filter out debug strings
'__blocknotif': False, # Block notifications
'_useragent': 'SpiderFoot/2.0', # User-Agent to use for HTTP requests
'_fetchtimeout': 5, # number of seconds before giving up on a fetch
diff --git a/sfdb.py b/sfdb.py
index 8df8c098..c4ca0600 100644
--- a/sfdb.py
+++ b/sfdb.py
@@ -55,6 +55,24 @@ class SpiderFootDb:
def close(self):
self.dbh.close()
+ # Log an event to the database
+ def scanLogEvent(self, instanceId, classification, message, component=None):
+ if component == None:
+ component = "SpiderFoot"
+
+ qry = "INSERT INTO tbl_scan_log \
+ (scan_instance_id, generated, component, type, message) \
+ VALUES (?, ?, ?, ?, ?)"
+ try:
+ self.dbh.execute(qry, (
+ instanceId, time.time() * 1000, component, classification, message
+ ))
+ self.conn.commit()
+ except sqlite3.Error as e:
+ sf.fatal("Unable to log event in DB: " + e.args[0])
+
+ return True
+
# Generate an globally unique ID for this scan
def scanInstanceGenGUID(self, scanName):
hashStr = hashlib.sha256(
@@ -62,7 +80,6 @@ class SpiderFootDb:
str(time.time() * 1000) +
str(random.randint(100000, 999999))
).hexdigest()
- sf.debug("Using GUID of: " + hashStr)
return hashStr
# Store a scan instance
diff --git a/sfdbsetup.py b/sfdbsetup.py
index 1c7d4f38..9038dbf2 100644
--- a/sfdbsetup.py
+++ b/sfdbsetup.py
@@ -52,6 +52,13 @@ class SpiderFootDbInit:
ended INT DEFAULT 0, \
status VARCHAR NOT NULL \
)",
+ "CREATE TABLE tbl_scan_log ( \
+ scan_instance_id VARCHAR NOT NULL REFERENCES tbl_scan_instance(guid), \
+ generated INT NOT NULL, \
+ component VARCHAR, \
+ type VARCHAR NOT NULL, \
+ message VARCHAR \
+ )",
"CREATE TABLE tbl_scan_config ( \
scan_instance_id VARCHAR NOT NULL REFERENCES tbl_scan_instance(guid), \
component VARCHAR NOT NULL, \
diff --git a/sflib.py b/sflib.py
index 0b92808b..5e36d053 100644
--- a/sflib.py
+++ b/sflib.py
@@ -16,10 +16,11 @@ import sys
import urllib2
class SpiderFoot:
+ dbh = None
+ scanGUID = None
+
# 'options' is a dictionary of options which changes the behaviour
# of how certain things are done in this module
- # - debug: enable debugging
- # - debugfilter: filter debug messages for a string
# 'handle' will be supplied if the module is being used within the
# SpiderFoot GUI, in which case all feedback should be fed back
def __init__(self, options, handle=None):
@@ -30,44 +31,49 @@ class SpiderFoot:
# Debug, error message and logging functions
#
+ # Called usually some time after instantiation
+ # to set up a database handle and scan GUID, used
+ # for logging events to the database about a scan.
+ def setDbh(self, handle):
+ self.dbh = handle
+
+ def setScanId(self, id):
+ self.scanGUID = id
+
+ def _dblog(self, level, message, component=None):
+ return self.dbh.scanLogEvent(self.scanGUID, level, message, component)
+
def error(self, error):
- if self.handle == None:
+ if self.dbh == None:
print '[Error] ' + error
- raise BaseException(error)
else:
- #self.handle.error(error)
- print 'should not be here'
- return
+ self._dblog("ERROR", error)
+ raise BaseException("Internal Error Encountered: " + error)
def fatal(self, error):
- if self.handle == None:
+ if self.dbh == None:
print '[Fatal] ' + error
- raise BaseException("Fatal Error Encountered: " + error)
- exit(-1)
else:
- #self.handle.error(error)
- print 'should not be here'
- return
+ self._dblog("FATAL", error)
+ raise BaseException("Fatal Error Encountered: " + error)
+ exit(-1)
def status(self, message):
- print "[Status] " + message
+ if self.dbh == None:
+ print "[Status] " + message
+ else:
+ self._dblog("STATUS", message)
def debug(self, message):
if self.opts['_debug'] == False:
return
- if self.handle == None:
- frm = inspect.stack()[1]
- mod = inspect.getmodule(frm[0])
-
- msg = '[d:' + mod.__name__ + '] ' + message
- if self.opts['__debugfilter'] != None and self.opts['__debugfilter'] not in msg:
- return
-
- print msg
+ frm = inspect.stack()[1]
+ mod = inspect.getmodule(frm[0])
+ if self.dbh == None:
+ print '[' + mod.__name__ + '] ' + message
else:
- #self.handle.debug(message)
- print 'should not be here'
+ self._dblog("DEBUG", message, mod.__name__)
return
#
@@ -80,6 +86,7 @@ class SpiderFoot:
storeopts = dict()
for opt in opts.keys():
+ # Filter out system temporary variables like GUID and others
if opt.startswith('__') and filterSystem:
continue
@@ -439,7 +446,7 @@ class SpiderFootPlugin(object):
self._stopScanning = False
# Will always be overriden by the implementer.
- def setup(self, url, userOpts=dict()):
+ def setup(self, sf, url, userOpts=dict()):
pass
# Listener modules which will get notified once we have data for them to
diff --git a/sfscan.py b/sfscan.py
index 68502643..13192d58 100644
--- a/sfscan.py
+++ b/sfscan.py
@@ -49,17 +49,19 @@ class SpiderFootScanner:
return None
for modName in self.moduleInstances.keys():
- print "Signalling module " + modName + " to stop."
+ self.sf.status("Signalling module " + modName + " to stop.")
self.moduleInstances[modName].stopScanning()
# Start running a scan
def startScan(self):
self.moduleInstances = dict()
dbh = SpiderFootDb(self.config)
+ self.sf.setDbh(dbh)
aborted = False
# Create a unique ID for this scan and create it in the back-end DB.
self.config['__guid__'] = dbh.scanInstanceGenGUID(self.target)
+ self.sf.setScanId(self.config['__guid__'])
self.myId = self.config['__guid__']
dbh.scanInstanceCreate(self.config['__guid__'], self.name, self.target)
dbh.scanInstanceSet(self.config['__guid__'], time.time() * 1000, None, 'STARTING')
@@ -69,7 +71,7 @@ class SpiderFootScanner:
self.config['_modulesenabled'] = self.moduleList
dbh.scanConfigSet(self.config['__guid__'], self.sf.configSerialize(self.config))
- print "Scan [" + self.config['__guid__'] + "] initiated."
+ self.sf.status("Scan [" + self.config['__guid__'] + "] initiated.")
# moduleList = list of modules the user wants to run
try:
for modName in self.moduleList:
@@ -94,9 +96,9 @@ class SpiderFootScanner:
modConfig[opt] = self.config[opt]
mod.clearListeners() # clear any listener relationships from the past
- mod.setup(self.target, modConfig)
+ mod.setup(self.sf, self.target, modConfig)
self.moduleInstances[modName] = mod
- print modName + " module loaded."
+ self.sf.status(modName + " module loaded.")
# Register listener modules and then start all modules sequentially
for module in self.moduleInstances.values():
@@ -136,10 +138,12 @@ class SpiderFootScanner:
dbh.scanInstanceSet(self.config['__guid__'], None, time.time() * 1000, 'FINISHED')
self.status = "FINISHED"
except Exception as e:
- self.sf.status("Scan [" + self.config['__guid__'] + "] failed: " + str(e))
+ self.sf.error("Scan [" + self.config['__guid__'] + "] failed: " + str(e))
dbh.scanInstanceSet(self.config['__guid__'], None, time.time() * 1000, 'ERROR-FAILED')
self.status = "ERROR-FAILED"
self.moduleInstances = None
dbh.close()
+ self.sf.setDbh(None)
+ self.sf.setScanId(None)
diff --git a/sfwebui.py b/sfwebui.py
index f61b129c..a5413ef5 100644
--- a/sfwebui.py
+++ b/sfwebui.py
@@ -190,7 +190,6 @@ class SpiderFootWebUi:
return templ.render(modules=self.config['__modules__'], alreadyRunning=True, runningScan=thread.name[3:])
# Start running a new scan
- print "Spawning thread for new scan..."
self.scanner = SpiderFootScanner(scanname, scantarget, modlist, self.config, modopts)
t = threading.Thread(name="SF_" + scanname, target=self.scanner.startScan)
t.start()
diff --git a/spiderfoot.schema b/spiderfoot.schema
index a78b4bb8..501fbcb5 100644
--- a/spiderfoot.schema
+++ b/spiderfoot.schema
@@ -48,6 +48,18 @@ CREATE TABLE tbl_scan_instance (
status VARCHAR NOT NULL
);
+--
+-- Scan events: Log messages generated during the scan.
+--
+DROP TABLE tbl_scan_log;
+CREATE TABLE tbl_scan_log (
+ scan_instance_id VARCHAR NOT NULL REFERENCES tbl_scan_instance(guid),
+ generated INT NOT NULL,
+ component VARCHAR,
+ type VARCHAR NOT NULL,
+ message VARCHAR
+);
+
--
-- Scan configs: The configuration used for a scan run.
--