Skip to content

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

Updated xref plugin to perform base URL checking, and make it more configurable.

Steve Micallef109b51dc62e4
diff --git a/modules/sfp_xref.py b/modules/sfp_xref.py
index d3c7a99f..4a10e919 100644
--- a/modules/sfp_xref.py
+++ b/modules/sfp_xref.py
@@ -25,12 +25,16 @@ class sfp_xref(SpiderFootPlugin):
# These must always be set
'_debug': True,
'_debugfilter': '',
- 'checkbase': True # Also check the base URL for a relationship if
- # the link contains no xref
+ '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
+ # the link provided contains no xref
+ 'checksimilar': True # Check similar domains for an xref
}
# Internal results tracking
results = dict()
+ fetched = list()
# URL this instance is working on
seedUrl = None
@@ -52,37 +56,60 @@ class sfp_xref(SpiderFootPlugin):
# What events is this module interested in for input
def watchedEvents(self):
- return ["URL", "SIMILARDOMAIN"]
+ arr = list("URL")
+ if self.opts['checksimilar']:
+ arr.append("SIMILARDOMAIN")
+ return arr
# Handle events sent to this module
+ # In this module's case, eventData will be the URL or a domain which
+ # was found in some content somewhere.
def handleEvent(self, srcModuleName, eventName, eventSource, eventData):
sf.debug("Received event, " + eventName + ", from " + srcModuleName)
- # In this module's case, eventData will be the URL
+
+ if eventData in self.fetched:
+ sf.debug("Ignoring " + eventData + " as already tested")
+ return
+
+ # The SIMILARDOMAIN event supplies domains, not URLs. Assume HTTP.
+ if eventName == 'SIMILARDOMAIN':
+ eventData = 'http://'+ eventData
# We are only interested in external sites for the xref
if sf.urlBaseDom(eventData) == self.baseDomain:
sf.debug("Ignoring " + eventData + " as not external")
return None
- res = sf.fetchUrl(eventData)
+ # If forcebase is set, we don't bother checking the URL from the event,
+ # just it's base URL.
+ if self.opts['forcebase']:
+ url = sf.urlBaseUrl(eventData)
+ else:
+ url = eventData
+
+ sf.debug("Testing for affiliation: " + url)
+ res = sf.fetchUrl(url)
+
if res['content'] == None:
- sf.debug("Ignoring " + eventData + " as no data returned")
+ sf.debug("Ignoring " + url + " as no data returned")
return None
- matches = re.findall("(" + self.baseDomain + ")", res['content'],
- re.IGNORECASE)
- if matches != None:
- for match in matches:
- if results.has_key(eventData):
- continue
+ # Search for mentions of our domain in the external site's data
+ matches = re.findall("(" + self.baseDomain + ")", res['content'], re.IGNORECASE)
- results[eventData] = True
- sf.debug("Found affiliate: " + eventData)
- self.notifyListeners("AFFILIATE", eventSource, eventData)
- else:
- # As no xref was found on the main link, check the base url
- if this.opts['checkbase']:
- res = sf.fetchUrl(sf.urlBaseUrl(eventData))
+ if not self.opts['forcebase'] and len(matches) > 0 and self.opts['checkbase']:
+ # Check the base url to see if there is an affiliation
+ url = sf.urlBaseUrl(eventData)
+ res = sf.fetchUrl(url)
+ matches = re.findall("(" + self.baseDomain + ")", res['content'], re.IGNORECASE)
+
+ if len(matches) > 0:
+ if self.results.has_key(url):
+ return None
+
+ self.results[url] = True
+ sf.debug("Found affiliate: " + url)
+ self.notifyListeners("AFFILIATE", eventSource, url)
return None
diff --git a/sf.py b/sf.py
index 5403279a..748e2517 100644
--- a/sf.py
+++ b/sf.py
@@ -20,7 +20,7 @@ seedUrl = 'http://www.telstra.com.au'
# These can be overriden on a per-module basis
sfConfig = {
'_debug': True, # Debug
- '_debugfilter': '', # Filter out debug strings
+ '_debugfilter': 'xref', # Filter out debug strings
'_blocknotif': False, # Block notifications
'_useragent': 'SpiderFoot/2.0', # User-Agent to use for HTTP requests
'_fetchtimeout': 1, # number of seconds before giving up on a fetch
@@ -34,16 +34,16 @@ moduleConfig = {
'pause': 1
},
'sfp_mail': {
- 'enabled': True
+ 'enabled': False
},
'sfp_websvr': {
- 'enabled': True
+ 'enabled': False
},
'sfp_stor_print': {
- 'enabled': True
+ 'enabled': False
},
'sfp_subdomain': {
- 'enabled': True
+ 'enabled': False
},
'sfp_xref': {
'enabled': True