SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
No more DNS leaks, bug fixes.
smicallef0b096258069b
diff --git a/modules/sfp_alienvault.py b/modules/sfp_alienvault.pyindex 099d065c..879614c0 100644--- a/modules/sfp_alienvault.py+++ b/modules/sfp_alienvault.py@@ -19,7 +19,6 @@ from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEventclass sfp_alienvault(SpiderFootPlugin):"""AlienVault OTX:Investigate,Passive:Reputation Systems:apikey:Obtain information from AlienVault Open Threat Exchange (OTX)"""-# Default optionsopts = {"api_key": "",diff --git a/modules/sfp_digitaloceanspace.py b/modules/sfp_digitaloceanspace.pyindex 517f7586..a2b60355 100644--- a/modules/sfp_digitaloceanspace.py+++ b/modules/sfp_digitaloceanspace.py@@ -56,7 +56,7 @@ class sfp_digitaloceanspace(SpiderFootPlugin):return ["CLOUD_STORAGE_BUCKET", "CLOUD_STORAGE_BUCKET_OPEN"]def checkSite(self, url):- res = self.sf.fetchUrl(url, timeout=10, useragent="SpiderFoot")+ res = self.sf.fetchUrl(url, timeout=10, useragent="SpiderFoot", noLog=True)if res['code'] not in [ "301", "302", "200" ] and \(res['content'] is None or "NoSuchBucket" in res['content']):diff --git a/modules/sfp_dnsbrute.py b/modules/sfp_dnsbrute.pyindex 017f82bb..4072174d 100644--- a/modules/sfp_dnsbrute.py+++ b/modules/sfp_dnsbrute.py@@ -11,7 +11,6 @@# Licence: GPL# --------------------------------------------------------------------------------import dnsimport randomimport threadingimport time@@ -86,19 +85,8 @@ class sfp_dnsbrute(SpiderFootPlugin):return ["INTERNET_NAME"]def tryHost(self, name):- resolver = dns.resolver.Resolver()- resolver.timeout = 2- resolver.lifetime = 2- resolver.search = list()-try:- # IDNA-encode the hostname in case it contains unicode- if type(name) != unicode:- name = unicode(name, "utf-8", errors='replace').encode("idna")- else:- name = name.encode("idna")-- addrs = resolver.query(name)+ addrs = self.sf.resolveHost(name)with self.lock:self.hostResults[name] = Trueexcept BaseException as e:diff --git a/modules/sfp_dnscommonsrv.py b/modules/sfp_dnscommonsrv.pyindex 47d04149..c01a8691 100644--- a/modules/sfp_dnscommonsrv.py+++ b/modules/sfp_dnscommonsrv.py@@ -14,7 +14,6 @@import dns.resolverfrom sflib import SpiderFootPlugin, SpiderFootEvent-class sfp_dnscommonsrv(SpiderFootPlugin):"""DNS Common SRV:Footprint,Investigate,Passive:DNS::Attempts to identify hostnames through common SRV."""@@ -70,6 +69,9 @@ class sfp_dnscommonsrv(SpiderFootPlugin):self.events = self.tempStorage()self.__dataSource__ = "DNS"+ for opt in userOpts.keys():+ self.opts[opt] = userOpts[opt]+# What events is this module interested in for inputdef watchedEvents(self):return ['INTERNET_NAME', 'DOMAIN_NAME']@@ -101,6 +103,10 @@ class sfp_dnscommonsrv(SpiderFootPlugin):self.events[eventDataHash] = True+ res = dns.resolver.Resolver()+ if self.opts.get('_dnsserver', "") != "":+ res.nameservers = [self.opts['_dnsserver']]+self.sf.debug("Iterating through possible SRV records.")# Try resolving common namesfor srv in self.commonsrv:@@ -114,7 +120,7 @@ class sfp_dnscommonsrv(SpiderFootPlugin):continuetry:- answers = dns.resolver.query(name, 'SRV')+ answers = res.query(name, 'SRV')except BaseException as e:answers = []diff --git a/modules/sfp_dnsneighbor.py b/modules/sfp_dnsneighbor.pyindex fa2aca49..07b8ecd5 100644--- a/modules/sfp_dnsneighbor.py+++ b/modules/sfp_dnsneighbor.py@@ -11,7 +11,6 @@# Licence: GPL# --------------------------------------------------------------------------------import dnsfrom netaddr import IPAddressfrom sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEventdiff --git a/modules/sfp_dnsraw.py b/modules/sfp_dnsraw.pyindex f900e754..a00dc49e 100644--- a/modules/sfp_dnsraw.py+++ b/modules/sfp_dnsraw.py@@ -16,7 +16,9 @@ try:except ImportError as e:import re-import dns+import dns.resolver+import dns.query+import dns.rdatatypefrom sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEventclass sfp_dnsraw(SpiderFootPlugin):@@ -90,7 +92,7 @@ class sfp_dnsraw(SpiderFootPlugin):try:req = dns.message.make_query(eventData, dns.rdatatype.from_text(rec))- if self.opts.get('_dnsserver', None):+ if self.opts.get('_dnsserver', "") != "":n = self.opts['_dnsserver']else:ns = dns.resolver.get_default_resolver()diff --git a/modules/sfp_dnsresolve.py b/modules/sfp_dnsresolve.pyindex d12f0ded..4aa8d664 100644--- a/modules/sfp_dnsresolve.py+++ b/modules/sfp_dnsresolve.py@@ -115,8 +115,8 @@ class sfp_dnsresolve(SpiderFootPlugin):addrs = NoneparentEvent = event- # Don't be recursive- if srcModuleName in [ "sfp_dnsresolve" ]:+ # Don't be recursive for names+ if srcModuleName in [ "sfp_dnsresolve" ] and "_NAME" in eventName:return Noneself.sf.debug("Received event, " + eventName + ", from " + srcModuleName)@@ -137,9 +137,10 @@ class sfp_dnsresolve(SpiderFootPlugin):self.notifyListeners(evt)return None- # Search for IPs/hosts in raw data, but obviously nothing this module- # already produces, as those things are already entities, not raw data.- if eventName not in self.producedEvents():+ # Search for IPs/hosts in raw data+ if eventName not in [ "CO_HOSTED_SITE", "AFFILIATE_INTERNET_NAME",+ "NETBLOCK_OWNER", "IP_ADDRESS",+ "INTERNET_NAME", "AFFILIATE_IPADDR"]:data = urllib2.unquote(eventData)for name in self.getTarget().getNames():if self.checkForStop():@@ -180,15 +181,15 @@ class sfp_dnsresolve(SpiderFootPlugin):# Nothing left to do with internal links and raw datareturn None- if eventName == 'NETBLOCK_OWNER':- if not self.opts['netblocklookup']:+ if eventName == 'NETBLOCK_OWNER':+ if not self.opts['netblocklookup']:+ return None+ else:+ if IPNetwork(eventData).prefixlen < self.opts['maxnetblock']:+ self.sf.debug("Network size bigger than permitted: " ++ str(IPNetwork(eventData).prefixlen) + " > " ++ str(self.opts['maxnetblock']))return None- else:- if IPNetwork(eventData).prefixlen < self.opts['maxnetblock']:- self.sf.debug("Network size bigger than permitted: " +- str(IPNetwork(eventData).prefixlen) + " > " +- str(self.opts['maxnetblock']))- return None# Not handling IPv6 (yet)if "::" in eventData:diff --git a/modules/sfp_dnszonexfer.py b/modules/sfp_dnszonexfer.pyindex a77cc057..84b56e29 100644--- a/modules/sfp_dnszonexfer.py+++ b/modules/sfp_dnszonexfer.py@@ -37,7 +37,6 @@ class sfp_dnszonexfer(SpiderFootPlugin):self.events = self.tempStorage()self.__dataSource__ = "DNS"-for opt in userOpts.keys():self.opts[opt] = userOpts[opt]@@ -72,11 +71,32 @@ class sfp_dnszonexfer(SpiderFootPlugin):self.events[eventDataHash] = True+ res = dns.resolver.Resolver()+ if self.opts.get('_dnsserver', "") != "":+ res.nameservers = [self.opts['_dnsserver']]++ # Get the name server's IP. This is to avoid DNS leaks+ # when attempting to resolve the name server during+ # the zone transfer.+ if not self.sf.validIP(eventData):+ nsips = self.sf.resolveHost(eventData)+ if len(nsips) > 0:+ for n in nsips:+ if self.sf.validIP(n):+ nsip = n+ break+ else:+ self.sf.error("Couldn't resolve the name server, " + \+ "so not attempting zone transfer.", False)+ return None+ else:+ nsip = eventData+for name in self.getTarget().getNames():self.sf.debug("Trying for name: " + name)try:ret = list()- z = dns.zone.from_xfr(dns.query.xfr(eventData, name))+ z = dns.zone.from_xfr(dns.query.xfr(nsip, name))names = z.nodes.keys()for n in names:ret.append(z[n].to_text(n))diff --git a/modules/sfp_s3bucket.py b/modules/sfp_s3bucket.pyindex 79796a90..4d2d0ced 100644--- a/modules/sfp_s3bucket.py+++ b/modules/sfp_s3bucket.py@@ -56,7 +56,7 @@ class sfp_s3bucket(SpiderFootPlugin):return ["CLOUD_STORAGE_BUCKET", "CLOUD_STORAGE_BUCKET_OPEN"]def checkSite(self, url):- res = self.sf.fetchUrl(url, timeout=10, useragent="SpiderFoot")+ res = self.sf.fetchUrl(url, timeout=10, useragent="SpiderFoot", noLog=True)if res['code'] not in [ "301", "302", "200" ] and \(res['content'] is None or "NoSuchBucket" in res['content']):diff --git a/modules/sfp_tldsearch.py b/modules/sfp_tldsearch.pyindex a176127c..5906cdec 100644--- a/modules/sfp_tldsearch.py+++ b/modules/sfp_tldsearch.py@@ -14,7 +14,7 @@import randomimport threadingimport time-import dns+import dns.resolverfrom sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEventclass sfp_tldsearch(SpiderFootPlugin):@@ -64,12 +64,14 @@ class sfp_tldsearch(SpiderFootPlugin):resolver.timeout = 1resolver.lifetime = 1resolver.search = list()+ if self.opts.get('_dnsserver', "") != "":+ resolver.nameservers = [self.opts['_dnsserver']]if self.opts['skipwildcards'] and self.sf.checkDnsWildcard(tld):return Nonetry:- addrs = self.sf.resolveHost(target, resolver)+ addrs = self.sf.resolveHost(target)if not addrs:with self.lock:self.tldResults[target] = False@@ -122,7 +124,9 @@ class sfp_tldsearch(SpiderFootPlugin):return NonepageContent = self.sf.fetchUrl('http://' + result,- timeout=self.opts['_fetchtimeout'], useragent=self.opts['_useragent'])+ timeout=self.opts['_fetchtimeout'],+ useragent=self.opts['_useragent'],+ noLog=True)if pageContent['content'] is not None:evt = SpiderFootEvent("SIMILARDOMAIN", result, self.__name__, source)self.notifyListeners(evt)diff --git a/sfdb.py b/sfdb.pyindex 4da83124..62c1aad3 100644--- a/sfdb.py+++ b/sfdb.py@@ -370,9 +370,11 @@ class SpiderFootDb:except sqlite3.Error as e:if "locked" in e.args[0]:# TODO: Do something smarter here to handle locked databases- self.sf.fatal("Unable to log event in DB due to lock: " + e.args[0])+ print("Couldn't log due to locking issue.")+ #self.sf.fatal("Unable to log event in DB due to lock: " + e.args[0])else:- self.sf.fatal("Unable to log event in DB: " + e.args[0])+ print("Couldn't log due to: " + str(e.args[0]))+ #self.sf.fatal("Unable to log event in DB: " + e.args[0])return Truediff --git a/sflib.py b/sflib.pyindex 44f47811..736298d9 100644--- a/sflib.py+++ b/sflib.py@@ -64,7 +64,7 @@ class SpiderFoot:if sys.version_info >= (2, 7, 9):ssl._create_default_https_context = ssl._create_unverified_context- if self.opts['_dnsserver'] != "":+ if self.opts.get('_dnsserver', "") != "":res = dns.resolver.Resolver()res.nameservers = [self.opts['_dnsserver']]dns.resolver.override_system_resolver(res)@@ -802,7 +802,7 @@ class SpiderFoot:ret.append(unicode(host, 'utf-8', errors='replace'))else:ret.append(unicode(addr, 'utf-8', errors='replace'))- return set(ret)+ return list(set(ret))# Verify input is OK to executedef sanitiseInput(self, cmd):@@ -924,7 +924,7 @@ class SpiderFoot:addrs = self.normalizeDNS(socket.gethostbyname_ex(host))if len(addrs) > 0:- return set(addrs)+ return list(set(addrs))return Noneexcept BaseException as e:self.debug("Unable to resolve " + host + ": " + str(e))@@ -937,7 +937,7 @@ class SpiderFoot:try:addrs = self.normalizeDNS(socket.gethostbyaddr(ipaddr))if len(addrs) > 0:- return set(addrs)+ return list(set(addrs))return Noneexcept BaseException as e:self.debug("Unable to resolve " + ipaddr + " (" + str(e) + ")")@@ -954,7 +954,7 @@ class SpiderFoot:if len(addrs) < 1:return Noneself.debug("Resolved " + hostname + " to IPv6: " + str(addrs))- return set(addrs)+ return list(set(addrs))except BaseException as e:self.debug("Unable to IPv6 resolve " + hostname + " (" + str(e) + ")")return None@@ -987,7 +987,7 @@ class SpiderFoot:if r:ret.extend(r)if t == "NETBLOCK_OWNER":- for addr in IPNetwork(v):+ for addr in netaddr.IPNetwork(v):ipaddr = str(addr)if ipaddr.split(".")[3] in ['255', '0']:continue@@ -1006,7 +1006,7 @@ class SpiderFoot:else:ret.extend(names)if len(ret) > 0:- return set(ret)+ return list(set(ret))return None# Create a safe socket that's using SOCKS/TOR if it was enabled@@ -1066,7 +1066,7 @@ class SpiderFoot:emails.append(match)- return set(emails)+ return list(set(emails))# Return a PEM for a DERdef sslDerToPem(self, der):