Skip to content

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

Less false positives for co-host reporting and DNS brute-forcing updates.

Steve Micallef3d534f7a0115
diff --git a/modules/sfp_bingsharedip.py b/modules/sfp_bingsharedip.py
index 5315bd2f..72db0b24 100644
--- a/modules/sfp_bingsharedip.py
+++ b/modules/sfp_bingsharedip.py
@@ -24,21 +24,25 @@ class sfp_bingsharedip(SpiderFootPlugin):
opts = {
'cohostsamedomain': False,
'pages': 20,
- 'verify': True
+ 'verify': True,
+ 'maxcohost': 100
}
# Option descriptions
optdescs = {
'cohostsamedomain': "Treat co-hosted sites on the same target domain as co-hosting?",
'pages': "How many pages of results to iterate through.",
- 'verify': "Verify co-hosts are valid by checking if they still resolve to the shared IP."
+ 'verify': "Verify co-hosts are valid by checking if they still resolve to the shared IP.",
+ 'maxcohost': "Stop reporting co-hosted sites after this many are found, as it would likely indicate web hosting."
}
- results = list()
+ results = dict()
+ cohostcount = 0
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
- self.results = list()
+ self.results = dict()
+ self.cohostcount = 0
self.__dataSource__ = "Bing"
for opt in userOpts.keys():
@@ -77,7 +81,6 @@ class sfp_bingsharedip(SpiderFootPlugin):
srcModuleName = event.module
eventData = event.data
self.currentEventSrc = event
-
self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
# Don't look up stuff twice
@@ -85,15 +88,18 @@ class sfp_bingsharedip(SpiderFootPlugin):
self.sf.debug("Skipping " + eventData + " as already mapped.")
return None
+ if self.cohostcount > self.opts['maxcohost']:
+ return None
+
qrylist = list()
if eventName.startswith("NETBLOCK_"):
for ipaddr in IPNetwork(eventData):
if str(ipaddr) not in self.results:
qrylist.append(str(ipaddr))
- self.results.append(str(ipaddr))
+ self.results[str(ipaddr)] = True
else:
qrylist.append(eventData)
- self.results.append(eventData)
+ self.results[eventData] = True
myres = list()
@@ -125,6 +131,7 @@ class sfp_bingsharedip(SpiderFootPlugin):
continue
evt = SpiderFootEvent("CO_HOSTED_SITE", site, self.__name__, event)
self.notifyListeners(evt)
+ self.cohostcount += 1
myres.append(site)
# Submit the bing results for analysis
diff --git a/modules/sfp_circllu.py b/modules/sfp_circllu.py
index 8ab51a47..2bb9ec32 100644
--- a/modules/sfp_circllu.py
+++ b/modules/sfp_circllu.py
@@ -27,7 +27,8 @@ class sfp_circllu(SpiderFootPlugin):
"api_key_password": "",
"age_limit_days": 0,
"verify": True,
- "cohostsamedomain": False
+ "cohostsamedomain": False,
+ "maxcohost": 100
}
# Option descriptions
@@ -36,7 +37,8 @@ class sfp_circllu(SpiderFootPlugin):
"api_key_password": "CIRCL.LU password.",
"age_limit_days": "Ignore any Passive DNS records older than this many days. 0 = unlimited.",
"verify": "Verify co-hosts are valid by checking if they still resolve to the shared IP.",
- "cohostsamedomain": "Treat co-hosted sites on the same target domain as co-hosting?"
+ "cohostsamedomain": "Treat co-hosted sites on the same target domain as co-hosting?",
+ 'maxcohost': "Stop reporting co-hosted sites after this many are found, as it would likely indicate web hosting."
}
# Be sure to completely clear any class variables in setup()
@@ -44,10 +46,12 @@ class sfp_circllu(SpiderFootPlugin):
results = dict()
errorState = False
+ cohostcount = 0
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
self.results = dict()
+ self.cohostcount = 0
# Clear / reset any other class member variables here
# or you risk them persisting between threads.
@@ -222,7 +226,9 @@ class sfp_circllu(SpiderFootPlugin):
self.sf.debug("Skipping " + co + " because it is on the same domain.")
continue
- e = SpiderFootEvent("CO_HOSTED_SITE", co, self.__name__, event)
- self.notifyListeners(e)
+ if self.cohostcount < self.opts['maxcohost']:
+ e = SpiderFootEvent("CO_HOSTED_SITE", co, self.__name__, event)
+ self.notifyListeners(e)
+ self.cohostcount += 1
# End of sfp_circllu class
diff --git a/modules/sfp_cymon.py b/modules/sfp_cymon.py
index b496927d..73af54e2 100644
--- a/modules/sfp_cymon.py
+++ b/modules/sfp_cymon.py
@@ -28,7 +28,8 @@ class sfp_cymon(SpiderFootPlugin):
'netblocklookup': True,
'maxnetblock': 24,
'subnetlookup': True,
- 'maxsubnet': 24
+ 'maxsubnet': 24,
+ 'maxcohost': 100
}
# Option descriptions
@@ -38,7 +39,8 @@ class sfp_cymon(SpiderFootPlugin):
'netblocklookup': "Look up all IPs on netblocks deemed to be owned by your target for possible blacklisted hosts on the same target subdomain/domain?",
'maxnetblock': "If looking up owned netblocks, the maximum netblock size to look up all IPs within (CIDR value, 24 = /24, 16 = /16, etc.)",
'subnetlookup': "Look up all IPs on subnets which your target is a part of for blacklisting?",
- 'maxsubnet': "If looking up subnets, the maximum subnet size to look up all the IPs within (CIDR value, 24 = /24, 16 = /16, etc.)"
+ 'maxsubnet': "If looking up subnets, the maximum subnet size to look up all the IPs within (CIDR value, 24 = /24, 16 = /16, etc.)",
+ 'maxcohost': "Stop reporting co-hosted sites after this many are found, as it would likely indicate web hosting."
}
# Be sure to completely clear any class variables in setup()
@@ -46,10 +48,12 @@ class sfp_cymon(SpiderFootPlugin):
results = dict()
errorState = False
+ cohostcount = 0
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
self.results = dict()
+ self.cohostcount = 0
# Clear / reset any other class member variables here
# or you risk them persisting between threads.
@@ -179,8 +183,10 @@ class sfp_cymon(SpiderFootPlugin):
self.sf.debug("Record found but too old, skipping.")
continue
else:
- e = SpiderFootEvent(evtType, host, self.__name__, event)
- self.notifyListeners(e)
+ if self.cohostcount < self.opts['maxcohost']:
+ e = SpiderFootEvent(evtType, host, self.__name__, event)
+ self.notifyListeners(e)
+ self.cohostcount += 1
for addr in qrylist:
if self.checkForStop():
diff --git a/modules/sfp_dnsbrute.py b/modules/sfp_dnsbrute.py
index b4fcb9f0..e5873774 100644
--- a/modules/sfp_dnsbrute.py
+++ b/modules/sfp_dnsbrute.py
@@ -14,37 +14,46 @@
import socket
import re
import dns
+import random
+import threading
import urllib2
+import time
from netaddr import IPAddress, IPNetwork
from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
class sfp_dnsbrute(SpiderFootPlugin):
- """DNS Brute-force:Footprint,Investigate:DNS::Attempts to identify hostnames through brute-forcing common names."""
+ """DNS Brute-force:Footprint,Investigate:DNS::Attempts to identify hostnames through brute-forcing common names and iterations."""
# Default options
opts = {
"skipcommonwildcard": True,
"domainonly": True,
- "commonsubs": ["www", "web", "ns", "mail", "dns", "mx", "gw", "proxy",
- "ssl", "fw", "gateway", "firewall", "www1", "www2",
- "ns0", "ns1", "ns2", "dns0", "dns1", "dns2", "mx1", "mx2"
- ] # Common sub-domains to try.
-
+ "commons": True,
+ "top10000": False,
+ "numbersuffix": True,
+ "numbersuffixlimit": True,
+ "maxthreads": 20
}
# Option descriptions
optdescs = {
'skipcommonwildcard': "If wildcard DNS is detected, only attempt to look up the first common sub-domain from the common sub-domain list.",
'domainonly': "Only attempt to brute-force names on domain names, not hostnames (some hostnames are also sub-domains).",
- 'commonsubs': "Common sub-domains to try to resolve on the target subdomain/domain. Prefix with an '@' to iterate through a file containing sub-domains to try (one per line), e.g. @C:\subdomains.txt or @/home/bob/subdomains.txt. Or supply a URL to load the list from there."
+ 'commons': "Try a list of about 750 common hostnames/sub-domains.",
+ 'top10000': "Try a further 10,000 common hostnames/sub-domains. Will make the scan much slower.",
+ 'numbersuffix': "For any host found, try appending 1, 01, 001, -1, -01, -001, 2, 02, etc. (up to 10)",
+ 'numbersuffixlimit': "Limit using the number suffixes for hosts that have already been resolved? If disabled this will significantly extend the duration of scans.",
+ 'maxthreads': "Maximum number of concurrent resolution attempts."
}
events = dict()
resolveCache = dict()
+ sublist = dict()
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
+ self.sublist = dict()
self.events = dict()
self.resolveCache = dict()
self.__dataSource__ = "DNS"
@@ -52,17 +61,28 @@ class sfp_dnsbrute(SpiderFootPlugin):
for opt in userOpts.keys():
self.opts[opt] = userOpts[opt]
- self.sublist = self.opts['commonsubs']
- # User may have supplied a file or URL containing the subdomains
- if self.opts['commonsubs'][0].startswith("http://") or \
- self.opts['commonsubs'][0].startswith("https://") or \
- self.opts['commonsubs'][0].startswith("@"):
- self.sublist = self.sf.optValueToData(self.opts['commonsubs'][0])
-
+ cslines = list()
+ if self.opts['commons']:
+ cs = open(self.sf.myPath() + "/ext/subdomains.txt", 'r')
+ cslines = cs.readlines()
+ for s in cslines:
+ s = s.strip()
+ self.sublist[s] = True
+
+ ttlines = list()
+ if self.opts['top10000']:
+ tt = open(self.sf.myPath() + "/ext/subdomains-10000.txt", 'r')
+ ttlines = tt.readlines()
+ for s in ttlines:
+ s = s.strip()
+ self.sublist[s] = True
# What events is this module interested in for input
def watchedEvents(self):
- return ['INTERNET_NAME', 'DOMAIN_NAME']
+ ret = ['DOMAIN_NAME']
+ if not self.opts['domainonly'] or self.opts['numbersuffix']:
+ ret.append('INTERNET_NAME')
+ return ret
# What events this module produces
# This is to support the end user in selecting modules based on events
@@ -86,6 +106,55 @@ class sfp_dnsbrute(SpiderFootPlugin):
self.sf.debug("Unable to resolve " + hostname + " (" + str(e) + ")")
return list()
+ def tryHost(self, name):
+ resolver = dns.resolver.Resolver()
+ resolver.timeout = 2
+ resolver.lifetime = 2
+ resolver.search = list()
+
+ try:
+ addrs = resolver.query(name)
+ self.hostResults[name] = True
+ except BaseException as e:
+ self.hostResults[name] = False
+
+ def tryHostWrapper(self, hostList, sourceEvent):
+ self.hostResults = dict()
+ running = True
+ i = 0
+ t = []
+
+ # Spawn threads for scanning
+ self.sf.info("Spawning threads to check hosts: " + str(hostList))
+ for name in hostList:
+ tn = 'sfp_dnsbrute_' + str(random.randint(0, 999999999))
+ t.append(threading.Thread(name=tn, target=self.tryHost, args=(name,)))
+ t[i].start()
+ i += 1
+
+ # Block until all threads are finished
+ while running:
+ found = False
+ for rt in threading.enumerate():
+ if rt.name.startswith("sfp_dnsbrute_"):
+ found = True
+
+ if not found:
+ running = False
+
+ time.sleep(0.25)
+
+ for res in self.hostResults:
+ if self.hostResults.get(res, False):
+ self.sendEvent(sourceEvent, res)
+
+ # Store the result internally and notify listening modules
+ def sendEvent(self, source, result):
+ self.sf.info("Found a brute-forced host: " + result)
+ # Report the host
+ evt = SpiderFootEvent("INTERNET_NAME", result, self.__name__, source)
+ self.notifyListeners(evt)
+
# Handle events sent to this module
def handleEvent(self, event):
eventName = event.eventType
@@ -96,38 +165,83 @@ class sfp_dnsbrute(SpiderFootPlugin):
self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
- if self.opts['domainonly'] and eventName == "INTERNET_NAME":
+ if eventDataHash in self.events:
return None
+ self.events[eventDataHash] = True
- if eventDataHash in self.events:
+ if eventName == "INTERNET_NAME" and not self.getTarget().matches(eventData, includeChildren=False):
+ if not self.opts['numbersuffix']:
+ return None
+
+ if self.checkForStop():
+ return None
+
+ h, dom = eventData.split(".", 1)
+ dom = "." + dom
+ nextsubs = dict()
+ for i in range(0, 9):
+ nextsubs[h + str(i) + dom] = True
+ nextsubs[h + "0" + str(i) + dom] = True
+ nextsubs[h + "00" + str(i) + dom] = True
+ nextsubs[h + "-" + str(i) + dom] = True
+ nextsubs[h + "-0" + str(i) + dom] = True
+ nextsubs[h + "-00" + str(i) + dom] = True
+
+ self.tryHostWrapper(nextsubs.keys(), event)
+
+ # The rest of the module is for handling targets only
return None
- self.events[eventDataHash] = True
+ # Only for the target, from this point forward...
+ if not self.getTarget().matches(eventData, includeChildren=False):
+ return None
+ # Try resolving common names
self.sf.debug("Iterating through possible sub-domains.")
wildcard = self.sf.checkDnsWildcard(eventData)
if self.opts['skipcommonwildcard'] and wildcard:
self.sf.debug("Wildcard DNS detected.")
return None
- # Try resolving common names
+ targetList = list()
for sub in self.sublist:
if self.checkForStop():
return None
- if sub == "":
- continue
- else:
- name = sub + "." + eventData
+ name = sub + "." + eventData
- # Skip hosts we've processed already
- if self.sf.hashstring(name) in self.events.keys():
- continue
+ if len(targetList) <= self.opts['maxthreads']:
+ targetList.append(name)
+ else:
+ self.tryHostWrapper(targetList, event)
+ targetList = list()
+
+ # Scan whatever may be left over.
+ if len(targetList) > 0:
+ self.tryHostWrapper(targetList, event)
+
+ if self.opts['numbersuffix'] and not self.opts['numbersuffixlimit']:
+ nextsubs = dict()
+ dom = "." + eventData
+ for s in self.sublist:
+ if self.checkForStop():
+ return None
+
+ for i in range(0, 9):
+ nextsubs[s + str(i) + dom] = True
+ nextsubs[s + "0" + str(i) + dom] = True
+ nextsubs[s + "00" + str(i) + dom] = True
+ nextsubs[s + "-" + str(i) + dom] = True
+ nextsubs[s + "-0" + str(i) + dom] = True
+ nextsubs[s + "-00" + str(i) + dom] = True
+
+ if len(nextsubs.keys()) >= self.opts['maxthreads']:
+ self.tryHostWrapper(nextsubs.keys(), event)
+ nextsubs = dict()
+
+ # Scan whatever may be left over.
+ if len(nextsubs) > 0:
+ self.tryHostWrapper(nextsubs.keys(), event)
- if len(self.resolveHost(name)) > 0:
- # Report the host
- evt = SpiderFootEvent("INTERNET_NAME", name,
- self.__name__, parentEvent)
- self.notifyListeners(evt)
# End of sfp_dnsbrute class
diff --git a/modules/sfp_riskiq.py b/modules/sfp_riskiq.py
index 08ae1378..f4daefe9 100644
--- a/modules/sfp_riskiq.py
+++ b/modules/sfp_riskiq.py
@@ -27,7 +27,8 @@ class sfp_riskiq(SpiderFootPlugin):
"api_key_login": "",
"api_key_password": "",
"verify": True,
- "cohostsamedomain": False
+ "cohostsamedomain": False,
+ 'maxcohost': 100
}
# Option descriptions
@@ -35,7 +36,8 @@ class sfp_riskiq(SpiderFootPlugin):
"api_key_login": "RiskIQ login.",
"api_key_password": "RiskIQ API Key.",
"verify": "Verify co-hosts are valid by checking if they still resolve to the shared IP.",
- "cohostsamedomain": "Treat co-hosted sites on the same target domain as co-hosting?"
+ "cohostsamedomain": "Treat co-hosted sites on the same target domain as co-hosting?",
+ 'maxcohost': "Stop reporting co-hosted sites after this many are found, as it would likely indicate web hosting."
}
# Be sure to completely clear any class variables in setup()
@@ -43,10 +45,12 @@ class sfp_riskiq(SpiderFootPlugin):
results = dict()
errorState = False
+ cohostcount = 0
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
self.results = dict()
+ self.cohostcount = 0
# Clear / reset any other class member variables here
# or you risk them persisting between threads.
@@ -216,7 +220,9 @@ class sfp_riskiq(SpiderFootPlugin):
self.notifyListeners(e)
continue
- e = SpiderFootEvent("CO_HOSTED_SITE", co, self.__name__, event)
- self.notifyListeners(e)
+ if self.cohostcount < self.opts['maxcohost']:
+ e = SpiderFootEvent("CO_HOSTED_SITE", co, self.__name__, event)
+ self.notifyListeners(e)
+ self.cohostcount += 1
# End of sfp_riskiq class
diff --git a/modules/sfp_robtex.py b/modules/sfp_robtex.py
index 05e746c7..c8e186bc 100644
--- a/modules/sfp_robtex.py
+++ b/modules/sfp_robtex.py
@@ -29,7 +29,8 @@ class sfp_robtex(SpiderFootPlugin):
'maxnetblock': 24,
'subnetlookup': True,
'maxsubnet': 24,
- 'cohostsamedomain': False
+ 'cohostsamedomain': False,
+ 'maxcohost': 100
}
# Option descriptions
@@ -39,14 +40,17 @@ class sfp_robtex(SpiderFootPlugin):
'maxnetblock': "If looking up owned netblocks, the maximum netblock size to look up all IPs within (CIDR value, 24 = /24, 16 = /16, etc.)",
'subnetlookup': "Look up all IPs on subnets which your target is a part of for identifying co-hosts?",
'maxsubnet': "If looking up subnets, the maximum subnet size to look up all the IPs within (CIDR value, 24 = /24, 16 = /16, etc.)",
- 'cohostsamedomain': "Treat co-hosted sites on the same target domain as co-hosting?"
+ 'cohostsamedomain': "Treat co-hosted sites on the same target domain as co-hosting?",
+ 'maxcohost': "Stop reporting co-hosted sites after this many are found, as it would likely indicate web hosting."
}
- results = list()
+ results = dict()
+ cohostcount = 0
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
- self.results = list()
+ self.results = dict()
+ self.cohostcount = 0
for opt in userOpts.keys():
self.opts[opt] = userOpts[opt]
@@ -87,6 +91,9 @@ class sfp_robtex(SpiderFootPlugin):
self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
+ if self.cohostcount > self.opts['maxcohost']:
+ return None
+
# Don't look up stuff twice
if eventData in self.results:
self.sf.debug("Skipping " + eventData + " as already mapped.")
@@ -116,10 +123,10 @@ class sfp_robtex(SpiderFootPlugin):
if eventName.startswith("NETBLOCK_"):
for ipaddr in IPNetwork(eventData):
qrylist.append(str(ipaddr))
- self.results.append(str(ipaddr))
+ self.results[str(ipaddr)] = True
else:
qrylist.append(eventData)
- self.results.append(eventData)
+ self.results[eventData] = True
myres = list()
@@ -165,5 +172,6 @@ class sfp_robtex(SpiderFootPlugin):
continue
evt = SpiderFootEvent("CO_HOSTED_SITE", r['o'], self.__name__, event)
self.notifyListeners(evt)
+ self.cohostcount += 1
# End of sfp_robtex class
diff --git a/modules/sfp_xforce.py b/modules/sfp_xforce.py
index 129e717f..cdc4dffd 100644
--- a/modules/sfp_xforce.py
+++ b/modules/sfp_xforce.py
@@ -21,7 +21,6 @@ from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
class sfp_xforce(SpiderFootPlugin):
"""XForce Exchange:Investigate,Passive:Reputation Systems:apikey:Obtain information from IBM X-Force Exchange"""
-
# Default options
opts = {
"xforce_api_key": "",
@@ -30,7 +29,8 @@ class sfp_xforce(SpiderFootPlugin):
'netblocklookup': True,
'maxnetblock': 24,
'subnetlookup': True,
- 'maxsubnet': 24
+ 'maxsubnet': 24,
+ 'maxcohost': 100
}
# Option descriptions
@@ -41,7 +41,8 @@ class sfp_xforce(SpiderFootPlugin):
'netblocklookup': "Look up all IPs on netblocks deemed to be owned by your target for possible blacklisted hosts on the same target subdomain/domain?",
'maxnetblock': "If looking up owned netblocks, the maximum netblock size to look up all IPs within (CIDR value, 24 = /24, 16 = /16, etc.)",
'subnetlookup': "Look up all IPs on subnets which your target is a part of for blacklisting?",
- 'maxsubnet': "If looking up subnets, the maximum subnet size to look up all the IPs within (CIDR value, 24 = /24, 16 = /16, etc.)"
+ 'maxsubnet': "If looking up subnets, the maximum subnet size to look up all the IPs within (CIDR value, 24 = /24, 16 = /16, etc.)",
+ 'maxcohost': "Stop reporting co-hosted sites after this many are found, as it would likely indicate web hosting."
}
# Be sure to completely clear any class variables in setup()
@@ -49,10 +50,12 @@ class sfp_xforce(SpiderFootPlugin):
results = dict()
errorState = False
+ cohostcount = 0
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
self.results = dict()
+ self.cohostcount = 0
# Clear / reset any other class member variables here
# or you risk them persisting between threads.
@@ -161,6 +164,9 @@ class sfp_xforce(SpiderFootPlugin):
# For IP Addresses, do the additional passive DNS lookup
if eventName == "IP_ADDRESS":
evtType = "CO_HOSTED_SITE"
+ if self.cohostcount > self.opts['maxcohost']:
+ return None
+
ret = self.query(eventData, "resolve")
if ret is None:
self.sf.info("No Passive DNS info for " + eventData)
@@ -182,6 +188,7 @@ class sfp_xforce(SpiderFootPlugin):
else:
e = SpiderFootEvent(evtType, host, self.__name__, event)
self.notifyListeners(e)
+ self.cohostcount += 1
for addr in qrylist:
if self.checkForStop():