Skip to content

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

Bug fixes for improved affiliate detection, search engine usage and identification of DNS TXT records.

smicallef23dff4e9c61e
diff --git a/dyn/scaninfo.tmpl b/dyn/scaninfo.tmpl
index 56ddb57a..07353e7c 100644
--- a/dyn/scaninfo.tmpl
+++ b/dyn/scaninfo.tmpl
@@ -9,7 +9,7 @@
</div>
<button class='btn btn-info disabled' id='scanreminder'>This page automatically reloads data every 5 seconds.</button>
<div id='btn-search' class='btn-group pull-right input-append'>
- <input class=span2 id=searchvalue type=text placeholder='Search...' data-toggle='popover' data-html=true data-animation=true data-title='Usage' data-content="Supply a regular expression encapsulated in '/', e.g. <i>/searchregex/</i> or a simple wildcard search, e.g. <i>*string*</i> or an exact value, e.g. <i>string</i>.">
+ <input class=span2 id=searchvalue type=text placeholder='Search...' data-toggle='popover' data-html=true data-animation=true data-title='Usage' data-content="Supply a regular expression encapsulated in '/', e.g. <i>/searchregex/</i> or a simple wildcard search, e.g. <i>*string*</i> or an exact value, e.g. <i>string</i>.<br><br><b>Note</b> that the current scope is what's searched.">
<button class='btn btn-primary' id=searchbutton type=button onClick=$('#btn-search').popover('toggle');searchDirector('${id}')>
<i class='icon-search icon-white'></i>
</button>
@@ -258,6 +258,7 @@
function viewScanLog(instanceId) {
$("#scansummary-content").remove();
$("#loader").show();
+ $("#btn-search").hide();
$("#btn-export").hide();
$("#scanreminder").hide();
navTo("btn-log");
diff --git a/dyn/scanlist.tmpl b/dyn/scanlist.tmpl
index 0d12d10b..5785384a 100644
--- a/dyn/scanlist.tmpl
+++ b/dyn/scanlist.tmpl
@@ -25,6 +25,11 @@
$("#mainbody").append(welcome);
return;
}
+ var buttons = "<div class='btn-toolbar'><div class='btn-group'><a id='btn-status' class='btn' onClick='scanStatusView(\"${id}\")'>";
+ buttons += "<i class='icon-eye-open'></i>&nbsp;Status</a>";
+ buttons += "<a id='btn-browse' class='btn' onClick='browseEventList(\"${id}\")'><i class='icon-th-list'></i>&nbsp;Browse</a>";
+ buttons += "<a id='btn-info' class='btn' onClick='viewScanConfig(\"${id}\")'><i class='icon-cog'></i>&nbsp;Scan Settings</a>";
+ buttons += "<a id='btn-log' class='btn' onClick='viewScanLog(\"${id}\")'><i class='icon-book'></i>&nbsp;Log</a></div></div>";
var table = "<table id='scanlist' class='table table-bordered table-striped tablesorter'>";
table += "<thead><tr> <th>Name</th> <th>Target</th> <th>Started</th> <th >Finished</th> <th style='text-align: center'>Status</th> <th style='text-align: center'>Elements</th><th style='text-align: center'>Action</th> </tr></thead><tbody>";
for (var i = 0; i < data.length; i++) {
diff --git a/evtypes.sql b/evtypes.sql
index dd2f0bd0..27fbefd4 100644
--- a/evtypes.sql
+++ b/evtypes.sql
@@ -11,7 +11,6 @@ INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('BLACKLISTED
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('BLACKLISTED_AFFILIATE_IPADDR', 'Blacklisted Affiliate IP Address', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('BLACKLISTED_SUBNET', 'Blacklisted IP on Same Subnet', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('BLACKLISTED_NETBLOCK', 'Blacklisted IP on Owned Netblock', 0);
-INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('EMAILADDR', 'Email Address', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('CO_HOSTED_SITE', 'Co-Hosted Site', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_INTERNET_NAME', 'Defaced', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_IPADDR', 'Defaced IP Address', 0)
@@ -19,13 +18,16 @@ INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_AFF
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_COHOST', 'Defaced Co-Hosted Site', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_AFFILIATE_IPADDR', 'Defaced Affiliate IP Address', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEVICE_TYPE', 'Device Type', 0);
+INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DNS_TEXT', 'DNS TXT Record', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DOMAIN_NAME', 'Domain Name', 0);
+INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('EMAILADDR', 'Email Address', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('GEOINFO', 'Physical Location', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('HTTP_CODE', 'HTTP Status Code', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('HUMAN_NAME', 'Human Name', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('INTERESTING_FILE', 'Interesting File', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('INTERNET_NAME', 'Internet Name', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('IP_ADDRESS', 'IP Address', 0);
+INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('IPV6_ADDRESS', 'IPv6 Address', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('LINKED_URL_INTERNAL', 'Linked URL - Internal', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('LINKED_URL_EXTERNAL', 'Linked URL - External', 0);
INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('MALICIOUS_ASN', 'Malicious AS', 0);
diff --git a/modules/sfp_bingsearch.py b/modules/sfp_bingsearch.py
index 4edcbe68..10beb25d 100644
--- a/modules/sfp_bingsearch.py
+++ b/modules/sfp_bingsearch.py
@@ -78,7 +78,8 @@ class sfp_bingsearch(SpiderFootPlugin):
return None
# Submit the bing results for analysis
- evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", pages[page], self.__name__)
+ evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", pages[page],
+ self.__name__, event)
self.notifyListeners(evt)
# We can optionally fetch links to our domain found in the search
@@ -98,7 +99,8 @@ class sfp_bingsearch(SpiderFootPlugin):
if self.checkForStop():
return None
- evt = SpiderFootEvent("LINKED_URL_INTERNAL", link, self.__name__)
+ evt = SpiderFootEvent("LINKED_URL_INTERNAL", link,
+ self.__name__, event)
self.notifyListeners(evt)
# End of sfp_bingsearch class
diff --git a/modules/sfp_dns.py b/modules/sfp_dns.py
index e7dbaea3..a1b8115d 100644
--- a/modules/sfp_dns.py
+++ b/modules/sfp_dns.py
@@ -121,7 +121,7 @@ class sfp_dns(SpiderFootPlugin):
def watchedEvents(self):
arr = ['RAW_DNS_RECORDS', 'SEARCH_ENGINE_WEB_CONTENT', 'RAW_RIR_DATA',
'TARGET_WEB_CONTENT', 'LINKED_URL_INTERNAL', 'INTERNET_NAME',
- 'IP_ADDRESS', 'NETBLOCK_OWNER']
+ 'IP_ADDRESS', 'NETBLOCK_OWNER', "DNS_TEXT" ]
return arr
# What events this module produces
@@ -129,7 +129,8 @@ class sfp_dns(SpiderFootPlugin):
# produced.
def producedEvents(self):
return [ "IP_ADDRESS", "INTERNET_NAME", "PROVIDER_MAIL", "DOMAIN_NAME",
- "PROVIDER_DNS", "AFFILIATE_INTERNET_NAME", "RAW_DNS_RECORDS" ]
+ "PROVIDER_DNS", "AFFILIATE_INTERNET_NAME", "RAW_DNS_RECORDS",
+ "DNS_TEXT", "IPV6_ADDRESS" ]
# Handle events sent to this module
def handleEvent(self, event):
@@ -148,7 +149,7 @@ class sfp_dns(SpiderFootPlugin):
# Identify potential sub-domains/hostnames
if eventName in [ "SEARCH_ENGINE_WEB_CONTENT", "TARGET_WEB_CONTENT",
- "LINKED_URL_INTERNAL", "RAW_RIR_DATA", "RAW_DNS_RECORDS" ]:
+ "LINKED_URL_INTERNAL", "RAW_RIR_DATA", "RAW_DNS_RECORDS", "DNS_TEXT" ]:
# If we've received a link or some raw data, extract potential sub-domains
# from the data for resolving later.
for name in self.getTarget().getNames():
@@ -158,7 +159,7 @@ class sfp_dns(SpiderFootPlugin):
matches = re.findall(pat, eventData)
if matches != None:
for match in matches:
- self.processHost(match, parentEvent)
+ self.processHost(match, parentEvent, affiliate=False)
# Nothing left to do with internal links and raw data
return None
@@ -188,56 +189,60 @@ class sfp_dns(SpiderFootPlugin):
# Generate an event for the IP, then
# let the handling by this module take
# care of follow-up processing.
- self.processHost(ipaddr, parentEvent)
+ self.processHost(ipaddr, parentEvent, affiliate=False)
return None
# Handling INTERNET_NAME and IP_ADDRESS events..
-
- if eventName != 'IP_ADDRESS':
- if '://' in eventData:
- addrs = self.resolveHost(self.sf.urlFQDN(eventData))
+ if eventName in [ "IP_ADDRESS", "INTERNET_NAME" ]:
+ if eventName != 'IP_ADDRESS':
+ if '://' in eventData:
+ addrs = self.resolveHost(self.sf.urlFQDN(eventData))
+ else:
+ addrs = self.resolveHost(eventData)
else:
- addrs = self.resolveHost(eventData)
- else:
- addrs = self.resolveIP(eventData)
-
- for addr in addrs:
- self.processHost(addr, parentEvent)
-
- # Try to reverse-resolve IPs 'near' the identified IP
- if self.opts['lookaside'] and eventName == 'IP_ADDRESS':
- ip = IPAddress(eventData)
- minip = IPAddress(int(ip) - self.opts['lookasidecount'])
- maxip = IPAddress(int(ip) + self.opts['lookasidecount'])
- self.sf.debug("Lookaside max: " + str(maxip) + ", min: " + str(minip))
- s = int(minip)
- c = int(maxip)
- while s <= c:
- sip = str(IPAddress(s))
- if self.checkForStop():
- return None
-
- if self.hostresults.has_key(sip):
- s = s + 1
- continue
-
- addrs = self.resolveIP(sip)
- if len(addrs) == 0:
- self.sf.debug("Look-aside resolve for " + sip + " failed.")
+ addrs = self.resolveIP(eventData)
+
+ for addr in addrs:
+ self.processHost(addr, parentEvent, affiliate=False)
+
+ # Try to reverse-resolve IPs 'near' the identified IP
+ if self.opts['lookaside'] and eventName == 'IP_ADDRESS':
+ ip = IPAddress(eventData)
+ minip = IPAddress(int(ip) - self.opts['lookasidecount'])
+ maxip = IPAddress(int(ip) + self.opts['lookasidecount'])
+ self.sf.debug("Lookaside max: " + str(maxip) + ", min: " + str(minip))
+ s = int(minip)
+ c = int(maxip)
+ while s <= c:
+ sip = str(IPAddress(s))
+ self.sf.debug("Attempting look-aside lookup of: " + sip)
+ if self.checkForStop():
+ return None
+
+ if self.hostresults.has_key(sip):
+ s = s + 1
+ continue
+
+ addrs = self.resolveIP(sip)
+ if len(addrs) == 0:
+ self.sf.debug("Look-aside resolve for " + sip + " failed.")
+ s = s + 1
+ continue
+
+ # Report addresses that resolve to hostnames on the same
+ # domain or sub-domain as the target.
+ for addr in addrs:
+ if addr == sip:
+ continue
+ if self.getTarget().matches(addr):
+ # Generate an event for the IP, then
+ # let the handling by this module take
+ # care of follow-up processing.
+ self.processHost(sip, parentEvent, affiliate=False)
+ else:
+ self.processHost(sip, parentEvent, affiliate=False)
s = s + 1
- continue
-
- # Report addresses that resolve to hostnames on the same
- # domain or sub-domain as the target.
- for addr in addrs:
- if self.getTarget().matches(addr):
- # Generate an event for the IP, then
- # let the handling by this module take
- # care of follow-up processing.
- self.processHost(sip, parentEvent)
- s = s + 1
-
- return None
+ return None
# Resolve an IP
def resolveIP(self, ipaddr):
@@ -252,6 +257,7 @@ class sfp_dns(SpiderFootPlugin):
try:
addrs = self.sf.normalizeDNS(socket.gethostbyaddr(ipaddr))
self.resolveCache[ipaddr] = addrs
+ self.sf.debug("Resolved " + ipaddr + " to: " + str(addrs))
return addrs
except BaseException as e:
self.sf.info("Unable to resolve " + ipaddr + " (" + str(e) + ")")
@@ -268,16 +274,18 @@ class sfp_dns(SpiderFootPlugin):
try:
addrs = self.sf.normalizeDNS(socket.gethostbyname_ex(hostname))
self.resolveCache[hostname] = addrs
+ self.sf.debug("Resolved " + hostname + " to: " + str(addrs))
return addrs
except BaseException as e:
self.sf.info("Unable to resolve " + hostname + " (" + str(e) + ")")
return list()
- def processHost(self, host, parentEvent):
+ # Process a host/IP, parentEvent is the event that represents this entity
+ def processHost(self, host, parentEvent, affiliate=None):
if not self.hostresults.has_key(host):
self.hostresults[host] = list(parentEvent.data)
else:
- if parentEvent.data in self.hostresults[host]:
+ if parentEvent.data in self.hostresults[host] or parentEvent.data == host:
self.sf.debug("Skipping host, " + host + ", already processed.")
return None
else:
@@ -286,15 +294,18 @@ class sfp_dns(SpiderFootPlugin):
self.sf.debug("Found host: " + host)
# If the returned hostname is aliaseed to our
# target in some way, flag it as an affiliate
- affil = True
- if self.getTarget().matches(host):
- affil = False
- # If the IP the host resolves to is in our
- # list of aliases,
- if not self.sf.validIP(host):
- for hostip in self.resolveHost(host):
- if self.getTarget().matches(hostip):
- affil = False
+ if affiliate == None:
+ affil = True
+ if self.getTarget().matches(host):
+ affil = False
+ # If the IP the host resolves to is in our
+ # list of aliases,
+ if not self.sf.validIP(host):
+ for hostip in self.resolveHost(host):
+ if self.getTarget().matches(hostip):
+ affil = False
+ else:
+ affil = affiliate
if affil:
if self.sf.validIP(host):
@@ -307,11 +318,6 @@ class sfp_dns(SpiderFootPlugin):
else:
htype = "INTERNET_NAME"
- # Don't report back the same thing that was provided
- #if htype == parentEvent.eventType and host == parentEvent.data:
- # print "X: " + htype + " / " + host
- # return None
-
if htype.endswith("INTERNET_NAME") and self.opts['onlyactive']:
if len(self.resolveHost(host)) == 0:
return None
@@ -341,8 +347,9 @@ class sfp_dns(SpiderFootPlugin):
# Process the raw data alone
recdata = dict()
recs = {
- 'MX': ['\S+ \d+ IN MX \d+ (\S+)\.', 'PROVIDER_MAIL'],
- 'NS': ['\S+ \d+ IN NS (\S+)\.', 'PROVIDER_DNS']
+ 'MX': ['\S+\s+(?:\d+)?\s+IN\s+MX\s+\d+\s+(\S+)\.', 'PROVIDER_MAIL'],
+ 'NS': ['\S+\s+(?:\d+)?\s+IN\s+NS\s+(\S+)\.', 'PROVIDER_DNS'],
+ 'TXT': ['\S+\s+TXT\s+\"(.[^\"]*)"', 'DNS_TEXT']
}
for rec in recs.keys():
@@ -366,16 +373,16 @@ class sfp_dns(SpiderFootPlugin):
self.sf.debug("Matched: " + m)
strdata = unicode(m, 'utf-8', errors='replace')
evt = SpiderFootEvent(recs[rx][1], strdata,
- self.__name__)
+ self.__name__, domevt)
self.notifyListeners(evt)
- if not strdata.endswith(domainName):
+ if rec != "TXT" and not strdata.endswith(domainName):
evt = SpiderFootEvent("AFFILIATE_INTERNET_NAME",
- strdata, self.__name__)
+ strdata, self.__name__, domevt)
self.notifyListeners(evt)
else:
strdata = unicode(str(x), 'utf-8', errors='replace')
evt = SpiderFootEvent("RAW_DNS_RECORDS", strdata,
- self.__name__)
+ self.__name__, domevt)
self.notifyListeners(evt)
except BaseException as e:
self.sf.error("Failed to obtain DNS response for " + domainName + \
@@ -404,6 +411,6 @@ class sfp_dns(SpiderFootPlugin):
continue
if len(self.resolveHost(name)) > 0:
- self.processHost(name, domevt)
+ self.processHost(name, domevt, affiliate=False)
# End of sfp_dns class
diff --git a/modules/sfp_googlesearch.py b/modules/sfp_googlesearch.py
index 9ece57cb..e75743b3 100644
--- a/modules/sfp_googlesearch.py
+++ b/modules/sfp_googlesearch.py
@@ -80,7 +80,8 @@ class sfp_googlesearch(SpiderFootPlugin):
return None
# Submit the google results for analysis
- evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", pages[page], self.__name__)
+ evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", pages[page],
+ self.__name__, event)
self.notifyListeners(evt)
# We can optionally fetch links to our domain found in the search
@@ -100,7 +101,8 @@ class sfp_googlesearch(SpiderFootPlugin):
if self.checkForStop():
return None
- evt = SpiderFootEvent("LINKED_URL_INTERNAL", link, self.__name__)
+ evt = SpiderFootEvent("LINKED_URL_INTERNAL", link,
+ self.__name__, event)
self.notifyListeners(evt)
# End of sfp_googlesearch class
diff --git a/modules/sfp_intfiles.py b/modules/sfp_intfiles.py
index ebaad4c5..80659b9b 100644
--- a/modules/sfp_intfiles.py
+++ b/modules/sfp_intfiles.py
@@ -82,7 +82,8 @@ class sfp_intfiles(SpiderFootPlugin):
continue
else:
self.results.append(eventData)
- evt = SpiderFootEvent("INTERESTING_FILE", eventData, self.__name__)
+ evt = SpiderFootEvent("INTERESTING_FILE", eventData,
+ self.__name__, event)
self.notifyListeners(evt)
return None
@@ -123,7 +124,8 @@ class sfp_intfiles(SpiderFootPlugin):
return None
# Submit the gresults for analysis
- evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", pages[page], self.__name__)
+ evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", pages[page],
+ self.__name__, event)
self.notifyListeners(evt)
if self.opts['searchengine'].lower() == "yahoo":
@@ -145,7 +147,8 @@ class sfp_intfiles(SpiderFootPlugin):
if self.sf.urlFQDN(link).endswith(eventData) and \
"." + fileExt.lower() in link.lower():
self.sf.info("Found an interesting file: " + link)
- evt = SpiderFootEvent("INTERESTING_FILE", link, self.__name__)
+ evt = SpiderFootEvent("INTERESTING_FILE", link,
+ self.__name__, event)
self.notifyListeners(evt)
# End of sfp_intfiles class
diff --git a/modules/sfp_names.py b/modules/sfp_names.py
index 1f48c8fc..5e161c36 100644
--- a/modules/sfp_names.py
+++ b/modules/sfp_names.py
@@ -1,3 +1,4 @@
+# coding: utf-8
#-------------------------------------------------------------------------------
# Name: sfp_names
# Purpose: Identify human names in content fetched.
@@ -82,7 +83,7 @@ class sfp_names(SpiderFootPlugin):
self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
# Stage 1: Find things that look (very vaguely) like names
- rx = re.compile("([A-Z][a-z]+)\s+.?.?\s?([A-Z][a-zA-Z\'\-]+)")
+ rx = re.compile("([A-Z][a-z�������������]+)\s+.?.?\s?([A-Z][�������������a-zA-Z\'\-]+)")
m = re.findall(rx, eventData)
for r in m:
# Start off each match as 0 points.
diff --git a/modules/sfp_pastebin.py b/modules/sfp_pastebin.py
index 67d2fe09..e2cae527 100644
--- a/modules/sfp_pastebin.py
+++ b/modules/sfp_pastebin.py
@@ -78,7 +78,8 @@ class sfp_pastebin(SpiderFootPlugin):
return None
# Submit the google results for analysis
- evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", pages[page], self.__name__)
+ evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", pages[page],
+ self.__name__, event)
self.notifyListeners(evt)
# Fetch the PasteBin page
@@ -105,7 +106,7 @@ class sfp_pastebin(SpiderFootPlugin):
continue
evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT",
- res['content'], self.__name__)
+ res['content'], self.__name__, event)
self.notifyListeners(evt)
# Sometimes pastebin search results false positives
@@ -124,7 +125,7 @@ class sfp_pastebin(SpiderFootPlugin):
evt = SpiderFootEvent("PASTEBIN_CONTENT",
"<SFURL>" + link + "</SFURL>\n" + "\"... " + data + " ...\"",
- self.__name__)
+ self.__name__, event)
self.notifyListeners(evt)
diff --git a/modules/sfp_similar.py b/modules/sfp_similar.py
index 7d3be815..c2e53221 100644
--- a/modules/sfp_similar.py
+++ b/modules/sfp_similar.py
@@ -85,7 +85,7 @@ class sfp_similar(SpiderFootPlugin):
# Fetch and loop through Whois.com results, updating our results data. Stop
# once we've reached the end.
- def scrapeWhois(self, keyword):
+ def scrapeWhois(self, keyword, sourceEvent):
reachedEnd = False
i = 0
while not reachedEnd:
@@ -111,7 +111,7 @@ class sfp_similar(SpiderFootPlugin):
if result in self.results:
continue
- self.storeResult(fetchPage, result)
+ self.storeResult(sourceEvent, result)
if not whoisLastPageIndicator in whois['content']:
reachedEnd = True
@@ -120,7 +120,7 @@ class sfp_similar(SpiderFootPlugin):
i += 1
- def scrapeDomaintools(self, keyword, position):
+ def scrapeDomaintools(self, keyword, position, sourceEvent):
reachedEnd = False
i = 1 # Using 0 will cause the first page to appear twice
while not reachedEnd:
@@ -146,7 +146,7 @@ class sfp_similar(SpiderFootPlugin):
if '.jpg' in result:
continue
- self.storeResult(fetchPage, result)
+ self.storeResult(sourceEvent, result)
if not domtoolLastPageIndicator in domtool['content']:
reachedEnd = True
@@ -155,7 +155,7 @@ class sfp_similar(SpiderFootPlugin):
i += 1
- def scrapeNamedroppers(self, keyword, position):
+ def scrapeNamedroppers(self, keyword, position, sourceEvent):
reachedEnd = False
i = 1 # Using 0 will cause the first page to appear twice
while not reachedEnd:
@@ -178,7 +178,7 @@ class sfp_similar(SpiderFootPlugin):
if result in self.results:
continue
- self.storeResult(fetchPage, result)
+ self.storeResult(sourceEvent, result)
if not namedropLastPageIndicator in namedrop['content']:
reachedEnd = True
@@ -200,10 +200,10 @@ class sfp_similar(SpiderFootPlugin):
pageContent = self.sf.fetchUrl('http://' + result,
timeout=self.opts['_fetchtimeout'], useragent=self.opts['_useragent'])
if pageContent['content'] != None:
- evt = SpiderFootEvent("SIMILARDOMAIN", result, self.__name__)
+ evt = SpiderFootEvent("SIMILARDOMAIN", result, self.__name__, source)
self.notifyListeners(evt)
else:
- evt = SpiderFootEvent("SIMILARDOMAIN", result, self.__name__)
+ evt = SpiderFootEvent("SIMILARDOMAIN", result, self.__name__, source)
self.notifyListeners(evt)
@@ -228,15 +228,15 @@ class sfp_similar(SpiderFootPlugin):
# Check popular Internet repositories for domains containing our target keyword
if "domtools" in self.opts['source'] or "ALL" in self.opts['source']:
if "left" in self.opts['method']:
- self.scrapeDomaintools(keyword, "LEFT")
+ self.scrapeDomaintools(keyword, "LEFT", event)
if "right" in self.opts['method']:
- self.scrapeDomaintools(keyword, "RIGHT")
+ self.scrapeDomaintools(keyword, "RIGHT", event)
if "namedroppers" in self.opts['source'] or "ALL" in self.opts['source']:
if "left" in self.opts['method']:
- self.scrapeNamedroppers(keyword, "LEFT")
+ self.scrapeNamedroppers(keyword, "LEFT", event)
if "right" in self.opts['method']:
- self.scrapeNamedroppers(keyword, "RIGHT")
+ self.scrapeNamedroppers(keyword, "RIGHT", event)
return None
diff --git a/modules/sfp_tldsearch.py b/modules/sfp_tldsearch.py
index e5142dfd..fe557001 100644
--- a/modules/sfp_tldsearch.py
+++ b/modules/sfp_tldsearch.py
@@ -65,7 +65,7 @@ class sfp_tldsearch(SpiderFootPlugin):
except BaseException as e:
self.tldResults[target] = False
- def tryTldWrapper(self, tldList):
+ def tryTldWrapper(self, tldList, sourceEvent):
self.tldResults = dict()
running = True
i = 0
@@ -91,7 +91,7 @@ class sfp_tldsearch(SpiderFootPlugin):
for res in self.tldResults.keys():
if self.tldResults[res]:
- self.sendEvent(None, res)
+ self.sendEvent(sourceEvent, res)
# Store the result internally and notify listening modules
def sendEvent(self, source, result):
@@ -106,10 +106,10 @@ class sfp_tldsearch(SpiderFootPlugin):
pageContent = self.sf.fetchUrl('http://' + result,
timeout=self.opts['_fetchtimeout'], useragent=self.opts['_useragent'])
if pageContent['content'] != None:
- evt = SpiderFootEvent("SIMILARDOMAIN", result, self.__name__)
+ evt = SpiderFootEvent("SIMILARDOMAIN", result, self.__name__, source)
self.notifyListeners(evt)
else:
- evt = SpiderFootEvent("SIMILARDOMAIN", result, self.__name__)
+ evt = SpiderFootEvent("SIMILARDOMAIN", result, self.__name__, source)
self.notifyListeners(evt)
# Search for similar sounding domains
@@ -154,12 +154,12 @@ class sfp_tldsearch(SpiderFootPlugin):
if len(targetList) <= self.opts['maxthreads']:
targetList.append(tryDomain)
else:
- self.tryTldWrapper(targetList)
+ self.tryTldWrapper(targetList, event)
targetList = list()
# Scan whatever may be left over.
if len(targetList) > 0:
- self.tryTldWrapper(targetList)
+ self.tryTldWrapper(targetList, event)
return None
diff --git a/modules/sfp_yahoosearch.py b/modules/sfp_yahoosearch.py
index 68f29c89..cea45690 100644
--- a/modules/sfp_yahoosearch.py
+++ b/modules/sfp_yahoosearch.py
@@ -84,7 +84,8 @@ class sfp_yahoosearch(SpiderFootPlugin):
content = re.sub("RU=(.[^\/]+)\/RK=", self.yahooCleaner, pages[page])
# Submit the yahoo results for analysis
- evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", content, self.__name__)
+ evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", content,
+ self.__name__, event)
self.notifyListeners(evt)
# We can optionally fetch links to our domain found in the search
@@ -104,7 +105,8 @@ class sfp_yahoosearch(SpiderFootPlugin):
if self.checkForStop():
return None
- evt = SpiderFootEvent("LINKED_URL_INTERNAL", link, self.__name__)
+ evt = SpiderFootEvent("LINKED_URL_INTERNAL", link,
+ self.__name__, event)
self.notifyListeners(evt)
# End of sfp_yahoosearch class
diff --git a/sfdb.py b/sfdb.py
index 986c5008..505b4b6e 100644
--- a/sfdb.py
+++ b/sfdb.py
@@ -98,6 +98,7 @@ class SpiderFootDb:
"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_AFFILIATE_IPADDR', 'Defaced Affiliate IP Address', 0)",
"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_COHOST', 'Defaced Co-Hosted Site', 0)",
"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEVICE_TYPE', 'Device Type', 0)",
+ "INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DNS_TEXT', 'DNS TXT Record', 0)",
"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DOMAIN_NAME', 'Domain Name', 0)",
"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('EMAILADDR', 'Email Address', 0)",
"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('GEOINFO', 'Physical Location', 0)",
@@ -106,6 +107,7 @@ class SpiderFootDb:
"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('INTERESTING_FILE', 'Interesting File', 0)",
"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('INTERNET_NAME', 'Internet Name', 0)",
"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('IP_ADDRESS', 'IP Address', 0)",
+ "INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('IPV6_ADDRESS', 'IPv6 Address', 0)",
"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('NETBLOCK_OWNER', 'Netblock Ownership', 0)",
"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('NETBLOCK_MEMBER', 'Netblock Membership', 0)",
"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('MALICIOUS_ASN', 'Malicious AS', 0)",
@@ -347,6 +349,26 @@ class SpiderFootDb:
self.sf.error("SQL error encountered when fetching result summary: " +
e.args[0])
+ # Obtain the ROOT event for a scan: Must be same output as scanResultEvent!
+ def scanRootEvent(self, instanceId):
+ qry = "SELECT ROUND(c.generated) AS generated, c.data, \
+ s.data as 'source_data', \
+ c.module, c.type, c.confidence, c.visibility, c.risk, c.hash, \
+ c.source_event_hash, t.event_descr \
+ FROM tbl_scan_results c, tbl_scan_results s, tbl_event_types t \
+ WHERE c.scan_instance_id = ? AND c.source_event_hash = s.hash AND \
+ s.scan_instance_id = c.scan_instance_id AND \
+ t.event = c.type AND c.source_event_hash = 'ROOT'"
+
+ qvars = [instanceId]
+
+ try:
+ self.dbh.execute(qry, qvars)
+ return self.dbh.fetchone()
+ except sqlite3.Error as e:
+ self.sf.error("SQL error encountered when fetching ROOT event: " +
+ e.args[0])
+
# Obtain the data for a scan and event type
def scanResultEvent(self, instanceId, eventType='ALL'):
qry = "SELECT ROUND(c.generated) AS generated, c.data, \
@@ -562,6 +584,9 @@ class SpiderFootDb:
if truncateSize > 0:
storeData = storeData[0:truncateSize]
+ if sfEvent.sourceEventHash in [ "", None]:
+ self.sf.fatal("UNABLE TO CREATE RECORD WITH EMPTY SOURCE EVENT HASH!")
+
qry = "INSERT INTO tbl_scan_results \
(scan_instance_id, hash, type, generated, confidence, \
visibility, risk, module, data, source_event_hash) \
diff --git a/sflib.py b/sflib.py
index 8080a734..6af57d72 100644
--- a/sflib.py
+++ b/sflib.py
@@ -1279,7 +1279,7 @@ class SpiderFootEvent(object):
sourceEventHash = None
__id = None
- def __init__(self, eventType, data, module, sourceEvent=None,
+ def __init__(self, eventType, data, module, sourceEvent,
confidence=100, visibility=100, risk=0):
self.eventType = eventType
self.generated = time.time()
@@ -1292,19 +1292,16 @@ class SpiderFootEvent(object):
# "ROOT" is a special "hash" reserved for elements with no
# actual parent (e.g. the first page spidered.)
- if sourceEvent != None:
- self.sourceEventHash = sourceEvent.getHash()
- else:
+ if self.sourceEvent == None:
self.sourceEventHash = "ROOT"
+ else:
+ self.sourceEventHash = sourceEvent.getHash()
self.__id = self.eventType + str(self.generated) + self.module + \
str(random.randint(0, 99999999))
# Unique hash of this event
def getHash(self):
- if self.module == "SpiderFoot UI":
- return "ROOT"
-
digestStr = self.__id.encode('raw_unicode_escape')
return hashlib.sha256(digestStr).hexdigest()
diff --git a/sfscan.py b/sfscan.py
index e5fc0890..0b25cf5a 100644
--- a/sfscan.py
+++ b/sfscan.py
@@ -23,7 +23,8 @@ import random
from netaddr import IPNetwork
from copy import deepcopy, copy
from sfdb import SpiderFootDb
-from sflib import SpiderFoot, SpiderFootEvent, SpiderFootTarget, globalScanStatus
+from sflib import SpiderFoot, SpiderFootEvent, SpiderFootTarget, \
+ SpiderFootPlugin, globalScanStatus
# Eventually change this to be able to control multiple scan instances
class SpiderFootScanner(threading.Thread):
@@ -212,9 +213,19 @@ class SpiderFootScanner(threading.Thread):
# Now we are ready to roll..
self.setStatus("RUNNING")
+ # Create a pseudo module for the root event to originate from
+ psMod = SpiderFootPlugin()
+ psMod.__name__ = "SpiderFoot UI"
+ psMod.setTarget(target)
+ psMod.clearListeners()
+ for mod in self.ts.moduleInstances.values():
+ if mod.watchedEvents() != None:
+ psMod.registerListener(mod)
+
# Create the "ROOT" event which un-triggered modules will link events to
- rootEvent = SpiderFootEvent(self.ts.targetType, self.ts.targetValue, "SpiderFoot UI")
- self.ts.dbh.scanEventStore(self.ts.scanId, rootEvent)
+ firstEvent = SpiderFootEvent(self.ts.targetType, self.ts.targetValue,
+ "SpiderFoot UI", None)
+ psMod.notifyListeners(firstEvent)
# Start the modules sequentially.
for module in self.ts.moduleInstances.values():
@@ -224,15 +235,6 @@ class SpiderFootScanner(threading.Thread):
aborted = True
break
- # Notify modules with the root event
- if self.ts.targetType in module.watchedEvents():
- module.handleEvent(rootEvent)
-
- # Check if any of the modules ended due to being stopped
- for module in self.ts.moduleInstances.values():
- if module.checkForStop():
- aborted = True
-
if aborted:
self.ts.sf.status("Scan [" + self.ts.scanId + "] aborted.")
self.setStatus("ABORTED", None, time.time() * 1000)
diff --git a/sfwebui.py b/sfwebui.py
index 42cd0d22..b6640307 100644
--- a/sfwebui.py
+++ b/sfwebui.py
@@ -497,7 +497,6 @@ class SpiderFootWebUi:
nextIds.append(parentId)
while keepGoing:
- #print "Next IDs: " + str(nextIds)
parentSet = dbh.scanElementSources(id, nextIds)
nextIds = list()
keepGoing = False
@@ -506,11 +505,7 @@ class SpiderFootWebUi:
parentId = row[9]
childId = row[8]
datamap[childId] = row
-
- # Prevent us from looping at root
- # 0 = event_hash and 3 = source_event_hash
- if row[8] == "ROOT" and row[9] == "ROOT":
- continue
+ print childId + " = " + str(row)
if pc.has_key(parentId):
if childId not in pc[parentId]:
@@ -519,11 +514,13 @@ class SpiderFootWebUi:
pc[parentId] = [ childId ]
if parentId not in nextIds:
nextIds.append(parentId)
- # Stop until we've found ROOT
- # 3 = source_event_hash
- if row[3] != "ROOT":
+
+ # Prevent us from looping at root
+ if parentId != "ROOT":
keepGoing = True
+ datamap[parentId] = row
+
#print pc
retdata = dict()
retdata['tree'] = sf.dataParentChildToTree(pc)