Skip to content

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

Info-level logging, non-ASCII/UTF charset support, bug fixes.

smicallefb36751954885
diff --git a/modules/sfp_dns.py b/modules/sfp_dns.py
index e46f7966..96bae47b 100644
--- a/modules/sfp_dns.py
+++ b/modules/sfp_dns.py
@@ -76,14 +76,18 @@ class sfp_dns(SpiderFootPlugin):
else:
addrs = socket.gethostbyaddr(eventData)
except socket.error as e:
- sf.debug("Unable to resolve " + eventData)
+ sf.info("Unable to resolve " + eventData)
return None
# First element of tuple is primary hostname if requested name is
# a CNAME, or an IP is being reverse looked up
if len(addrs[0]) > 0:
host = addrs[0]
- sf.debug("Found host: " + host)
+ sf.info("Found host: " + host)
+
+ # Ignore cases where the IP resolves to the target domain
+ if host.lower() == self.baseDomain:
+ return None
# If the returned hostname is on a different
# domain to baseDomain, flag it as an affiliate
@@ -97,7 +101,7 @@ class sfp_dns(SpiderFootPlugin):
# Now the IP addresses..
if len(addrs[2]) > 0 and eventName != 'IP_ADDRESS':
for ipaddr in addrs[2]:
- sf.debug("Found IP Address: " + ipaddr)
+ sf.info("Found IP Address: " + ipaddr)
self.notifyListeners("IP_ADDRESS", eventData, ipaddr)
return None
diff --git a/modules/sfp_geoip.py b/modules/sfp_geoip.py
index b0014df7..e5f1aedd 100644
--- a/modules/sfp_geoip.py
+++ b/modules/sfp_geoip.py
@@ -56,9 +56,10 @@ class sfp_geoip(SpiderFootPlugin):
res = sf.fetchUrl("http://api.hostip.info/get_json.php?ip=" + eventData)
if res['content'] == None:
- sf.debug("No GeoIP info found for " + eventData)
+ sf.info("No GeoIP info found for " + eventData)
hostip = json.loads(res['content'])
- countrycity = hostip['country_name'] + " (" + hostip['city'] + ")"
+ sf.info("Found GeoIP for " + eventData + ": " + hostip['country_name'])
+ countrycity = hostip['country_name']
self.notifyListeners("GEOINFO", eventData, countrycity)
diff --git a/modules/sfp_googlesearch.py b/modules/sfp_googlesearch.py
index e7fc10ed..47cc3823 100644
--- a/modules/sfp_googlesearch.py
+++ b/modules/sfp_googlesearch.py
@@ -93,12 +93,12 @@ class sfp_googlesearch(SpiderFootPlugin):
if nextUrl == None:
sf.debug("Nothing left to scan for in Google results.")
return returnResults
- sf.debug("Next Google URL: " + nextUrl)
+ sf.info("Next Google URL: " + nextUrl)
# Wait for a random number of seconds between fetches
if not opts.has_key('nopause'):
pauseSecs = random.randint(4, 15)
- sf.debug("Pausing for " + str(pauseSecs))
+ sf.info("Pausing for " + str(pauseSecs))
time.sleep(pauseSecs)
# Check if we've been asked to stop
@@ -123,7 +123,7 @@ class sfp_googlesearch(SpiderFootPlugin):
# Sites hosted on the domain
pages = self.googleIterate("site:" + self.baseDomain, dict(limit=self.opts['pages']))
if pages == None:
- sf.debug("No results returned from Google.")
+ sf.info("No results returned from Google.")
return None
for page in pages.keys():
@@ -148,7 +148,7 @@ class sfp_googlesearch(SpiderFootPlugin):
for link in links:
if link in self.results:
continue
- sf.debug("Found a link: " + link)
+ sf.info("Found a link: " + link)
if sf.urlBaseUrl(link).endswith(self.baseDomain):
if self.checkForStop():
return None
diff --git a/modules/sfp_mail.py b/modules/sfp_mail.py
index c2f9810a..34f49632 100644
--- a/modules/sfp_mail.py
+++ b/modules/sfp_mail.py
@@ -86,6 +86,7 @@ class sfp_mail(SpiderFootPlugin):
sf.debug("Ignoring e-mail address on an external domain" + match)
continue
+ sf.info("Found e-mail address: " + match)
self.notifyListeners("EMAILADDR", eventSource, match)
return None
diff --git a/modules/sfp_pageinfo.py b/modules/sfp_pageinfo.py
index 866c1257..56faa8ae 100644
--- a/modules/sfp_pageinfo.py
+++ b/modules/sfp_pageinfo.py
@@ -74,13 +74,13 @@ etc.)"""
for regex in regexps[regexpGrp]:
matches = re.findall(regex, eventData, re.IGNORECASE)
if len(matches) > 0 and regexpGrp not in self.results[eventSource]:
- sf.debug("Matched " + regex + " in content from " + eventSource)
+ sf.info("Matched " + regexpGrp + " in content from " + eventSource)
self.notifyListeners(regexpGrp, eventSource, eventData)
self.results[eventSource].append(regexpGrp)
# If no regexps were matched, consider this a static page
if len(self.results[eventSource]) == 0:
- sf.debug("Treating " + eventSource + " as WEBCONTENT_STATIC")
+ sf.info("Treating " + eventSource + " as WEBCONTENT_STATIC")
self.notifyListeners("WEBCONTENT_STATIC", eventSource, eventData)
return None
diff --git a/modules/sfp_portscan_basic.py b/modules/sfp_portscan_basic.py
index 95c901fc..b9bb4c84 100644
--- a/modules/sfp_portscan_basic.py
+++ b/modules/sfp_portscan_basic.py
@@ -76,14 +76,14 @@ class sfp_portscan_basic(SpiderFootPlugin):
if self.checkForStop():
return None
- sf.debug("Checking port: " + str(port) + " against " + eventData)
+ sf.info("Checking port: " + str(port) + " against " + eventData)
try:
sock = socket.create_connection((eventData, port), self.opts['timeout'])
- sf.debug("TCP Port " + str(port) + " found to be OPEN.")
+ sf.info("TCP Port " + str(port) + " found to be OPEN.")
self.notifyListeners("TCP_PORT_OPEN", eventData, str(port))
sock.close()
except Exception as e:
- sf.debug("Unable to connect to " + eventData + " on port " + str(port) + \
+ sf.info("Unable to connect to " + eventData + " on port " + str(port) + \
": " + str(e))
return None
diff --git a/modules/sfp_ripe.py b/modules/sfp_ripe.py
index 70236761..0ece6e6b 100644
--- a/modules/sfp_ripe.py
+++ b/modules/sfp_ripe.py
@@ -57,7 +57,7 @@ class sfp_ripe(SpiderFootPlugin):
if eventName == 'SUBDOMAIN':
res = sf.fetchUrl("http://stat.ripe.net/data/dns-chain/data.json?resource=" + eventData)
if res['content'] == None:
- sf.debug("No RIPE info found/available for " + eventData)
+ sf.info("No RIPE info found/available for " + eventData)
return None
# Just send the content off for others to process
@@ -67,7 +67,7 @@ class sfp_ripe(SpiderFootPlugin):
# First get the netblock the IP resides on
res = sf.fetchUrl("http://stat.ripe.net/data/network-info/data.json?resource=" + eventData)
if res['content'] == None:
- sf.debug("No RIPE info found/available for " + eventData)
+ sf.info("No RIPE info found/available for " + eventData)
return None
j = json.loads(res['content'])
@@ -75,11 +75,12 @@ class sfp_ripe(SpiderFootPlugin):
# Now see who owns the prefix
res = sf.fetchUrl("http://stat.ripe.net/data/whois/data.json?resource=" + prefix)
if res['content'] == None:
- sf.debug("No RIPE info found/available for prefix: " + prefix)
+ sf.info("No RIPE info found/available for prefix: " + prefix)
return None
- # Crude..
+ # Crude and probably prone to a lot of false positives. Need to revisit.
if self.baseDomain in res['content']:
+ sf.info("Owned netblock found: " + prefix)
self.notifyListeners("NETBLOCK", eventData, prefix)
self.notifyListeners("WEBCONTENT", eventData, res['content'])
diff --git a/modules/sfp_similar.py b/modules/sfp_similar.py
index acdf26bf..c3f41577 100644
--- a/modules/sfp_similar.py
+++ b/modules/sfp_similar.py
@@ -190,7 +190,7 @@ class sfp_similar(SpiderFootPlugin):
# Store the result internally and notify listening modules
def storeResult(self, source, result):
- sf.debug("Found a similar domain: " + result)
+ sf.info("Found a similar domain: " + result)
self.results.append(result)
# Inform listening modules
diff --git a/modules/sfp_spider.py b/modules/sfp_spider.py
index 0deaef0c..a2d77f20 100644
--- a/modules/sfp_spider.py
+++ b/modules/sfp_spider.py
@@ -156,7 +156,7 @@ class sfp_spider(SpiderFootPlugin):
links = sf.parseLinks(url, fetched['content'], self.baseDomain)
if links == None or len(links) == 0:
- sf.debug("No links found at " + url)
+ sf.info("No links found at " + url)
return None
sf.debug('Links found from parsing: ' + str(links))
@@ -195,7 +195,7 @@ class sfp_spider(SpiderFootPlugin):
continue
# All tests passed, add link to be spidered
- sf.debug("Adding URL for spidering: " + link)
+ sf.info("Adding URL for spidering: " + link)
returnLinks[link] = links[link]
return returnLinks
@@ -243,7 +243,7 @@ class sfp_spider(SpiderFootPlugin):
totalFetched += 1
if totalFetched >= self.opts['maxpages']:
- sf.debug("Maximum number of pages (" + str(self.opts['maxpages']) + \
+ sf.info("Maximum number of pages (" + str(self.opts['maxpages']) + \
") reached.")
keepSpidering = False
break
@@ -257,15 +257,15 @@ class sfp_spider(SpiderFootPlugin):
# We've scanned through another layer of the site
levelsTraversed += 1
- sf.debug("Now at traversal level: " + str(levelsTraversed))
+ sf.info("Now at traversal level: " + str(levelsTraversed))
if levelsTraversed >= self.opts['maxlevels']:
- sf.debug("Maximum number of levels (" + str(self.opts['maxlevels']) + \
+ sf.info("Maximum number of levels (" + str(self.opts['maxlevels']) + \
") reached.")
keepSpidering = False
# We've reached the end of our journey..
if len(nextLinks) == 0:
- sf.debug("No more links found to spider, finishing..")
+ sf.info("No more links found to spider, finishing..")
keepSpidering = False
# We've been asked to stop scanning
diff --git a/modules/sfp_subdomain.py b/modules/sfp_subdomain.py
index fa74f594..dfc9c39a 100644
--- a/modules/sfp_subdomain.py
+++ b/modules/sfp_subdomain.py
@@ -58,6 +58,7 @@ class sfp_subdomain(SpiderFootPlugin):
if self.results.has_key(match):
continue
else:
+ sf.info("New sub-domain/host found: " + match)
self.notifyListeners("SUBDOMAIN", eventSource, match)
self.results[match] = True
diff --git a/modules/sfp_websvr.py b/modules/sfp_websvr.py
index c40769e4..320fb230 100644
--- a/modules/sfp_websvr.py
+++ b/modules/sfp_websvr.py
@@ -59,7 +59,7 @@ class sfp_websvr(SpiderFootPlugin):
# and other errors to see what the header looks like.
if eventData.has_key('server'):
self.notifyListeners("WEBSERVER_BANNER", eventSource, eventData['Server'])
- sf.debug("Found web server: " + eventData['Server'] + " (" + eventSource + ")")
+ sf.info("Found web server: " + eventData['Server'] + " (" + eventSource + ")")
if (eventData.has_key('x-powered-by')):
self.notifyListeners("WEBSERVER_TECHNOLOGY", eventSource, eventData['x-powered-by'])
diff --git a/modules/sfp_xref.py b/modules/sfp_xref.py
index 6c9c3509..4b79d3fb 100644
--- a/modules/sfp_xref.py
+++ b/modules/sfp_xref.py
@@ -82,7 +82,7 @@ class sfp_xref(SpiderFootPlugin):
else:
url = eventData
- sf.debug("Testing for affiliation: " + url)
+ sf.info("Testing for affiliation: " + url)
if url in self.fetched:
sf.debug("Ignoring " + url + " as already tested")
@@ -114,7 +114,7 @@ class sfp_xref(SpiderFootPlugin):
return None
self.results[url] = True
- sf.debug("Found affiliate: " + url)
+ sf.info("Found affiliate: " + url)
self.notifyListeners("AFFILIATE", eventSource, url)
if self.opts['checkcontent']:
self.notifyListeners("WEBCONTENT", url, res['content'])
diff --git a/sfdbsetup.py b/sfdbsetup.py
index 9038dbf2..44969a1f 100644
--- a/sfdbsetup.py
+++ b/sfdbsetup.py
@@ -74,6 +74,7 @@ class SpiderFootDbInit:
event_data_source VARCHAR NOT NULL \
)",
"CREATE INDEX idx_scan_results_event ON tbl_scan_results (scan_instance_id, event)",
+ "CREATE INDEX idx_scan_logs ON tbl_scan_log (scan_instance_id)",
"INSERT INTO tbl_event_types (event, event_descr) VALUES ('AFFILIATE', 'Affiliate')",
"INSERT INTO tbl_event_types (event, event_descr) VALUES ('EMAILADDR', 'Email Address')",
"INSERT INTO tbl_event_types (event, event_descr) VALUES ('GEOINFO', 'Physical Location')",
diff --git a/sflib.py b/sflib.py
index 8c9305af..e5d02d56 100644
--- a/sflib.py
+++ b/sflib.py
@@ -43,12 +43,13 @@ class SpiderFoot:
def _dblog(self, level, message, component=None):
return self.dbh.scanLogEvent(self.scanGUID, level, message, component)
- def error(self, error):
+ def error(self, error, exception=True):
if self.dbh == None:
print '[Error] ' + error
else:
self._dblog("ERROR", error)
- raise BaseException("Internal Error Encountered: " + error)
+ if not exception:
+ raise BaseException("Internal Error Encountered: " + error)
def fatal(self, error):
if self.dbh == None:
@@ -64,6 +65,15 @@ class SpiderFoot:
else:
self._dblog("STATUS", message)
+ def info(self, message):
+ frm = inspect.stack()[1]
+ mod = inspect.getmodule(frm[0])
+ if self.dbh == None:
+ print '[' + mod.__name__ + '] ' + message
+ else:
+ self._dblog("INFO", message, mod.__name__)
+ return
+
def debug(self, message):
if self.opts['_debug'] == False:
return
@@ -385,29 +395,29 @@ class SpiderFoot:
if not self.opts.has_key('_fetchtimeout'):
self.opts['_fetchtimeout'] = 30
req = urllib2.Request(url, None, header)
- self.debug("Fetching " + url)
+ self.info("Fetching " + url)
fullPage = urllib2.urlopen(req, None, self.opts['_fetchtimeout'])
# Prepare result to return
- result['content'] = fullPage.read()
+ result['content'] = unicode(fullPage.read(), 'utf-8', errors='ignore')
result['headers'] = fullPage.info()
result['realurl'] = fullPage.geturl()
result['code'] = fullPage.getcode()
result['status'] = 'OK'
except urllib2.HTTPError as h:
- self.debug("HTTP code " + str(h.code) + " encountered for " + url)
+ self.info("HTTP code " + str(h.code) + " encountered for " + url)
# Capture the HTTP error code
result['code'] = h.code
result['headers'] = h.info()
if fatal:
self.fatal('URL could not be fetched (' + h.code + ')')
except urllib2.URLError as e:
- self.debug("Error fetching " + url + "(" + str(e) + ")")
+ self.info("Error fetching " + url + "(" + str(e) + ")")
result['status'] = str(e)
if fatal:
self.fatal('URL could not be fetched (' + str(e) + ')')
except Exception as x:
- self.debug("Unexpected exception occurred fetching: " + url + "(" + str(x) + ")")
+ self.info("Unexpected exception occurred fetching: " + url + "(" + str(x) + ")")
result['content'] = None
result['status'] = str(x)
if fatal:
diff --git a/sfscan.py b/sfscan.py
index 8614474b..a1a05953 100644
--- a/sfscan.py
+++ b/sfscan.py
@@ -140,16 +140,11 @@ class SpiderFootScanner:
self.status = "FINISHED"
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
- self.sf.error("Scan [" + self.config['__guid__'] + "] failed: " + str(e))
+ self.sf.error("Unhandled exception encountered during scan. Please report this as a bug: " + \
+ repr(traceback.format_exception(exc_type, exc_value, exc_traceback)), False)
+ self.sf.status("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)
-
- sf.fatal("Unhandled exception encountered during scan. Please report this as a bug: " + \
- repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
self.moduleInstances = None
dbh.close()
diff --git a/spiderfoot.schema b/spiderfoot.schema
index 501fbcb5..4de8d751 100644
--- a/spiderfoot.schema
+++ b/spiderfoot.schema
@@ -85,3 +85,4 @@ CREATE TABLE tbl_scan_results (
);
CREATE INDEX idx_scan_results_event ON tbl_scan_results (scan_instance_id, event);
+CREATE INDEX idx_scan_logs ON tbl_scan_log (scan_instance_id);