SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Merged sfp_subdomain.py into sfp_dns.py
smicallefca74077f5ccf
diff --git a/modules/sfp_dns.py b/modules/sfp_dns.pyindex ca76a678..bba61ba2 100644--- a/modules/sfp_dns.py+++ b/modules/sfp_dns.py@@ -22,7 +22,7 @@ from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEventsf = Noneclass sfp_dns(SpiderFootPlugin):- """Performs a number of DNS checks to obtain IP Addresses and Affiliates."""+ """Performs a number of DNS checks to obtain Sub-domains/Hostnames, IP Addresses and Affiliates."""# Default optionsopts = {@@ -46,12 +46,14 @@ class sfp_dns(SpiderFootPlugin):# TargetbaseDomain = Noneresults = dict()+ subresults = dict()def setup(self, sfc, target, userOpts=dict()):global sfsf = sfcself.results = dict()+ self.subresults = dict()self.baseDomain = targetfor opt in userOpts.keys():@@ -59,7 +61,7 @@ class sfp_dns(SpiderFootPlugin):# What events is this module interested in for inputdef watchedEvents(self):- arr = ['SUBDOMAIN']+ arr = ['RAW_DATA', 'LINKED_URL_INTERNAL', 'SUBDOMAIN']if self.opts['resolveaffiliate']:arr.append('AFFILIATE')if self.opts['reverselookup']:@@ -72,9 +74,36 @@ class sfp_dns(SpiderFootPlugin):srcModuleName = event.moduleeventData = event.dataaddrs = None+ if eventName == "RAW_DATA":+ parentEvent = event.sourceEvent+ else:+ parentEvent = eventsf.debug("Received event, " + eventName + ", from " + srcModuleName)+ if eventName in [ "RAW_DATA", "LINKED_URL_INTERNAL" ]:+ # If we've received a link or some raw data, extract potential sub-domains+ # from the data for resolving later.+ matches = re.findall("([a-zA-Z0-9\-\.]+\." + self.baseDomain + ")", eventData,+ re.IGNORECASE)++ if matches != None:+ for match in matches:+ if match.lower().startswith("2f"):+ continue++ sf.debug("Found sub-domain: " + match)+ if self.subresults.has_key(match):+ continue+ else:+ sf.info("New sub-domain/host found: " + match)+ self.subresults[match] = True+ evt = SpiderFootEvent("SUBDOMAIN", match, self.__name__, parentEvent)+ self.notifyListeners(evt)++ # Nothing left to do with internal links and raw data+ return None+# Don't look up stuff twiceif self.results.has_key(eventData):sf.debug("Skipping " + eventData + " as already resolved.")@@ -91,18 +120,26 @@ class sfp_dns(SpiderFootPlugin):else:addrs = socket.gethostbyaddr(eventData)except BaseException as e:- sf.info("Unable to resolve " + eventData)+ sf.info("Unable to resolve " + eventData + " (" + str(e) + ")")return Nonefor addr in addrs:if type(addr) == list:for host in addr:- self.processHost(host, event)+ self.processHost(host, parentEvent)else:- self.processHost(addr, event)+ self.processHost(addr, parentEvent)return None+ # Resolve a host+ def resolveHost(self, hostname):+ try:+ return socket.gethostbyname_ex(hostname)+ except BaseException as e:+ sf.info("Unable to resolve " + eventData + " (" + str(e) + ")")+ return None+# Simple way to verify IPs.def validIP(self, address):parts = address.split(".")@@ -127,6 +164,11 @@ class sfp_dns(SpiderFootPlugin):else:type = "SUBDOMAIN"+ if parentEvent != None:+ # Don't report back the same thing that was provided+ if type == parentEvent.eventType and host == parentEvent.data:+ return+evt = SpiderFootEvent(type, host, self.__name__, parentEvent)self.notifyListeners(evt)@@ -178,7 +220,7 @@ class sfp_dns(SpiderFootPlugin):self.processHost(addr)except BaseException as e:- sf.info("Unable to resolve " + name)+ sf.info("Unable to resolve " + name + " (" + str(e) + ")")# End of sfp_dns classdiff --git a/modules/sfp_subdomain.py b/modules/sfp_subdomain.pydeleted file mode 100644index 1ddf735f..00000000--- a/modules/sfp_subdomain.py+++ /dev/null@@ -1,76 +0,0 @@-#--------------------------------------------------------------------------------# Name: sfp_subdomain-# Purpose: SpiderFoot plug-in for scanning retreived content by other-# modules (such as sfp_spider) and identifying sub-domains-#-# Author: Steve Micallef <[email protected]>-#-# Created: 06/04/2012-# Copyright: (c) Steve Micallef 2012-# Licence: GPL-#---------------------------------------------------------------------------------import sys-import re-from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent--# SpiderFoot standard lib (must be initialized in __init__)-sf = None--class sfp_subdomain(SpiderFootPlugin):- """ Identify hostnames / sub-domain names in URLs and obtained content. """- # Default options- opts = { }-- # Target- baseDomain = None- results = dict()-- def setup(self, sfc, target, userOpts=dict()):- global sf-- sf = sfc- self.baseDomain = target- self.results = dict()-- for opt in userOpts.keys():- self.opts[opt] = userOpts[opt]-- # What events is this module interested in for input- def watchedEvents(self):- return ["RAW_DATA", "LINKED_URL_INTERNAL"]-- # Handle events sent to this module- def handleEvent(self, event):- eventName = event.eventType- srcModuleName = event.module- eventData = event.data- if eventName == "RAW_DATA":- parentEvent = event.sourceEvent- else:- parentEvent = event-- sf.debug("Received event, " + eventName + ", from " + srcModuleName)-- matches = re.findall("([a-zA-Z0-9\-\.]+\." + self.baseDomain + ")", eventData,- re.IGNORECASE)- if matches == None:- return None-- for match in matches:- # Skip URL encoded /- if match.lower().startswith("2f"):- continue-- sf.debug("Found sub-domain: " + match)- if self.results.has_key(match):- continue- else:- sf.info("New sub-domain/host found: " + match)- self.results[match] = True- evt = SpiderFootEvent("SUBDOMAIN", match, self.__name__, parentEvent)- self.notifyListeners(evt)-- return None--# End of sfp_subdomain class