SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Split blacklists into their own modules.
Steved63fa7e58e2f
diff --git a/modules/sfp_blacklist.py b/modules/sfp_dronebl.pysimilarity index 79%rename from modules/sfp_blacklist.pyrename to modules/sfp_dronebl.pyindex 399e94c1..36a35866 100644--- a/modules/sfp_blacklist.py+++ b/modules/sfp_dronebl.py@@ -1,8 +1,8 @@# -*- coding: utf-8 -*-# --------------------------------------------------------------------------------# Name: sfp_blacklist+# Name: sfp_dronebl# Purpose: SpiderFoot plug-in for looking up whether IPs/Netblocks/Domains-# appear in various block lists, indicating potential open-relays,+# appear in the DroneBL blocklist, indicating potential open-relays,# open proxies, malicious servers, vulnerable servers, etc.## Author: Steve Micallef <[email protected]>@@ -17,8 +17,8 @@ from netaddr import IPNetworkfrom sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent-class sfp_blacklist(SpiderFootPlugin):- """Blacklist:Investigate,Passive:Blacklists::Query various blacklist databases for open relays, open proxies, vulnerable servers, etc."""+class sfp_dronebl(SpiderFootPlugin):+ """DroneBL:Investigate,Passive:Blacklists::Query the DroneBL database for open relays, open proxies, vulnerable servers, etc."""# Default optionsopts = {@@ -44,13 +44,6 @@ class sfp_blacklist(SpiderFootPlugin):# Check out:# http://www.blocklist.de/en/rbldns.htmlchecks = {- "http.dnsbl.sorbs.net": "SORBS - Open HTTP Proxy",- "socks.dnsbl.sorbs.net": "SORBS - Open SOCKS Proxy",- "misc.dnsbl.sorbs.net": "SORBS - Open Proxy",- "smtp.dnsbl.sorbs.net": "SORBS - Open SMTP Relay",- "spam.dnsbl.sorbs.net": 'SORBS - Spammer',- "recent.spam.dnsbl.sorbs.net": 'SORBS - Recent Spammer',- "web.dnsbl.sorbs.net": 'SORBS - Vulnerability exposed to spammers',"dnsbl.dronebl.org": {"127.0.0.3": "dronebl.org - IRC Drone","127.0.0.5": "dronebl.org - Bottler",@@ -64,20 +57,7 @@ class sfp_blacklist(SpiderFootPlugin):"127.0.0.15": "dronebl.org - Compromised router / gateway","127.0.0.17": "dronebl.org - Automatically determined botnet IPs (experimental)","127.0.0.255": "dronebl.org - Unknown"- },- "dnsbl-1.uceprotect.net": 'UCEPROTECT - Level 1 (high likelihood)',- "dnsbl-2.uceprotect.net": 'UCEPROTECT - Level 2 (some false positives)',- 'zen.spamhaus.org': {- '127.0.0.2': "Spamhaus (Zen) - Spammer",- '127.0.0.3': "Spamhaus (Zen) - Spammer",- '127.0.0.4': "Spamhaus (Zen) - Proxies, Trojans, etc.",- '127.0.0.5': "Spamhaus (Zen) - Proxies, Trojans, etc.",- '127.0.0.6': "Spamhaus (Zen) - Proxies, Trojans, etc.",- '127.0.0.7': "Spamhaus (Zen) - Proxies, Trojans, etc.",- '127.0.0.10': "Spamhaus (Zen) - Potential Spammer",- '127.0.0.11': "Spamhaus (Zen) - Potential Spammer"- },- "bl.spamcop.net": "SpamCop Blacklist"+ }}def setup(self, sfc, userOpts=dict()):@@ -184,4 +164,4 @@ class sfp_blacklist(SpiderFootPlugin):else:self.queryAddr(eventData, parentEvent)-# End of sfp_blacklist class+# End of sfp_dronebl classdiff --git a/modules/sfp_sorbs.py b/modules/sfp_sorbs.pynew file mode 100644index 00000000..2b51fd66--- /dev/null+++ b/modules/sfp_sorbs.py@@ -0,0 +1,160 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_sorbs+# Purpose: SpiderFoot plug-in for looking up whether IPs/Netblocks/Domains+# appear in the SORBS blocklist, indicating potential open-relays,+# open proxies, malicious servers, vulnerable servers, etc.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 07/01/2014+# Copyright: (c) Steve Micallef 2014+# Licence: GPL+# -------------------------------------------------------------------------------++import socket+from netaddr import IPNetwork+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent+++class sfp_sorbs(SpiderFootPlugin):+ """SORBS:Investigate,Passive:Blacklists::Query the SORBS database for open relays, open proxies, vulnerable servers, etc."""++ # Default options+ opts = {+ 'netblocklookup': True,+ 'maxnetblock': 24,+ 'subnetlookup': True,+ 'maxsubnet': 24+ }++ # Option descriptions+ optdescs = {+ '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.)"+ }++ # Target+ results = dict()++ # Whole bunch here:+ # http://en.wikipedia.org/wiki/Comparison_of_DNS_blacklists+ # Check out:+ # http://www.blocklist.de/en/rbldns.html+ checks = {+ "http.dnsbl.sorbs.net": "SORBS - Open HTTP Proxy",+ "socks.dnsbl.sorbs.net": "SORBS - Open SOCKS Proxy",+ "misc.dnsbl.sorbs.net": "SORBS - Open Proxy",+ "smtp.dnsbl.sorbs.net": "SORBS - Open SMTP Relay",+ "spam.dnsbl.sorbs.net": "SORBS - Spammer",+ "recent.spam.dnsbl.sorbs.net": "SORBS - Recent Spammer",+ "web.dnsbl.sorbs.net": "SORBS - Vulnerability exposed to spammers"+ }++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc+ 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 ['IP_ADDRESS', 'AFFILIATE_IPADDR', 'NETBLOCK_OWNER',+ 'NETBLOCK_MEMBER']++ # What events this module produces+ # This is to support the end user in selecting modules based on events+ # produced.+ def producedEvents(self):+ return ["BLACKLISTED_IPADDR", "BLACKLISTED_AFFILIATE_IPADDR",+ "BLACKLISTED_SUBNET", "BLACKLISTED_NETBLOCK"]++ # Swap 1.2.3.4 to 4.3.2.1+ def reverseAddr(self, ipaddr):+ return '.'.join(reversed(ipaddr.split('.')))++ def queryAddr(self, qaddr, parentEvent):+ eventName = parentEvent.eventType++ for domain in self.checks:+ if self.checkForStop():+ return None++ try:+ lookup = self.reverseAddr(qaddr) + "." + domain+ self.sf.debug("Checking Blacklist: " + lookup)+ addrs = self.sf.normalizeDNS(socket.gethostbyname_ex(lookup))+ self.sf.debug("Addresses returned: " + str(addrs))++ text = None+ for addr in addrs:+ if type(self.checks[domain]) is str:+ text = self.checks[domain] + " (" + qaddr + ")"+ break+ else:+ if str(addr) not in self.checks[domain].keys():+ self.sf.debug("Return code not found in list: " + str(addr))+ continue++ k = str(addr)+ text = self.checks[domain][k] + " (" + qaddr + ")"+ break++ if text is not None:+ if eventName == "AFFILIATE_IPADDR":+ e = "BLACKLISTED_AFFILIATE_IPADDR"+ if eventName == "IP_ADDRESS":+ e = "BLACKLISTED_IPADDR"+ if eventName == "NETBLOCK_OWNER":+ e = "BLACKLISTED_NETBLOCK"+ if eventName == "NETBLOCK_MEMBER":+ e = "BLACKLISTED_SUBNET"++ evt = SpiderFootEvent(e, text, self.__name__, parentEvent)+ self.notifyListeners(evt)++ except BaseException as e:+ self.sf.debug("Unable to resolve " + qaddr + " / " + lookup + ": " + str(e))++ return None++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data+ parentEvent = event+ addrlist = list()++ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)++ if eventData in self.results:+ return None+ self.results[eventData] = True++ if eventName == 'NETBLOCK_OWNER' and self.opts['netblocklookup']:+ 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++ if eventName == 'NETBLOCK_MEMBER' and self.opts['subnetlookup']:+ if IPNetwork(eventData).prefixlen < self.opts['maxsubnet']:+ self.sf.debug("Network size bigger than permitted: " ++ str(IPNetwork(eventData).prefixlen) + " > " ++ str(self.opts['maxsubnet']))+ return None++ if eventName.startswith("NETBLOCK_"):+ for addr in IPNetwork(eventData):+ if self.checkForStop():+ return None+ self.queryAddr(str(addr), parentEvent)+ else:+ self.queryAddr(eventData, parentEvent)++# End of sfp_sorbs classdiff --git a/modules/sfp_spamcop.py b/modules/sfp_spamcop.pynew file mode 100644index 00000000..51c4e501--- /dev/null+++ b/modules/sfp_spamcop.py@@ -0,0 +1,154 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_spamcop+# Purpose: SpiderFoot plug-in for looking up whether IPs/Netblocks/Domains+# appear in the spamcop block lists, indicating potential open-relays,+# open proxies, malicious servers, vulnerable servers, etc.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 07/01/2014+# Copyright: (c) Steve Micallef 2014+# Licence: GPL+# -------------------------------------------------------------------------------++import socket+from netaddr import IPNetwork+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent+++class sfp_spamcop(SpiderFootPlugin):+ """SpamCop:Investigate,Passive:Blacklists::Query various spamcop databases for open relays, open proxies, vulnerable servers, etc."""++ # Default options+ opts = {+ 'netblocklookup': True,+ 'maxnetblock': 24,+ 'subnetlookup': True,+ 'maxsubnet': 24+ }++ # Option descriptions+ optdescs = {+ '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.)"+ }++ # Target+ results = dict()++ # Whole bunch here:+ # http://en.wikipedia.org/wiki/Comparison_of_DNS_blacklists+ # Check out:+ # http://www.blocklist.de/en/rbldns.html+ checks = {+ "bl.spamcop.net": "SpamCop Blacklist"+ }++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc+ 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 ['IP_ADDRESS', 'AFFILIATE_IPADDR', 'NETBLOCK_OWNER',+ 'NETBLOCK_MEMBER']++ # What events this module produces+ # This is to support the end user in selecting modules based on events+ # produced.+ def producedEvents(self):+ return ["BLACKLISTED_IPADDR", "BLACKLISTED_AFFILIATE_IPADDR",+ "BLACKLISTED_SUBNET", "BLACKLISTED_NETBLOCK"]++ # Swap 1.2.3.4 to 4.3.2.1+ def reverseAddr(self, ipaddr):+ return '.'.join(reversed(ipaddr.split('.')))++ def queryAddr(self, qaddr, parentEvent):+ eventName = parentEvent.eventType++ for domain in self.checks:+ if self.checkForStop():+ return None++ try:+ lookup = self.reverseAddr(qaddr) + "." + domain+ self.sf.debug("Checking Blacklist: " + lookup)+ addrs = self.sf.normalizeDNS(socket.gethostbyname_ex(lookup))+ self.sf.debug("Addresses returned: " + str(addrs))++ text = None+ for addr in addrs:+ if type(self.checks[domain]) is str:+ text = self.checks[domain] + " (" + qaddr + ")"+ break+ else:+ if str(addr) not in self.checks[domain].keys():+ self.sf.debug("Return code not found in list: " + str(addr))+ continue++ k = str(addr)+ text = self.checks[domain][k] + " (" + qaddr + ")"+ break++ if text is not None:+ if eventName == "AFFILIATE_IPADDR":+ e = "BLACKLISTED_AFFILIATE_IPADDR"+ if eventName == "IP_ADDRESS":+ e = "BLACKLISTED_IPADDR"+ if eventName == "NETBLOCK_OWNER":+ e = "BLACKLISTED_NETBLOCK"+ if eventName == "NETBLOCK_MEMBER":+ e = "BLACKLISTED_SUBNET"++ evt = SpiderFootEvent(e, text, self.__name__, parentEvent)+ self.notifyListeners(evt)++ except BaseException as e:+ self.sf.debug("Unable to resolve " + qaddr + " / " + lookup + ": " + str(e))++ return None++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data+ parentEvent = event+ addrlist = list()++ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)++ if eventData in self.results:+ return None+ self.results[eventData] = True++ if eventName == 'NETBLOCK_OWNER' and self.opts['netblocklookup']:+ 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++ if eventName == 'NETBLOCK_MEMBER' and self.opts['subnetlookup']:+ if IPNetwork(eventData).prefixlen < self.opts['maxsubnet']:+ self.sf.debug("Network size bigger than permitted: " ++ str(IPNetwork(eventData).prefixlen) + " > " ++ str(self.opts['maxsubnet']))+ return None++ if eventName.startswith("NETBLOCK_"):+ for addr in IPNetwork(eventData):+ if self.checkForStop():+ return None+ self.queryAddr(str(addr), parentEvent)+ else:+ self.queryAddr(eventData, parentEvent)++# End of sfp_spamcop classdiff --git a/modules/sfp_spamhaus.py b/modules/sfp_spamhaus.pynew file mode 100644index 00000000..ed3b1a5b--- /dev/null+++ b/modules/sfp_spamhaus.py@@ -0,0 +1,163 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_spamhaus+# Purpose: SpiderFoot plug-in for looking up whether IPs/Netblocks/Domains+# appear in the Spamhaus block lists, indicating potential open-relays,+# open proxies, malicious servers, vulnerable servers, etc.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 07/01/2014+# Copyright: (c) Steve Micallef 2014+# Licence: GPL+# -------------------------------------------------------------------------------++import socket+from netaddr import IPNetwork+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent+++class sfp_spamhaus(SpiderFootPlugin):+ """Spamhaus:Investigate,Passive:Blacklists::Query the Spamhaus databases for open relays, open proxies, vulnerable servers, etc."""++ # Default options+ opts = {+ 'netblocklookup': True,+ 'maxnetblock': 24,+ 'subnetlookup': True,+ 'maxsubnet': 24+ }++ # Option descriptions+ optdescs = {+ '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.)"+ }++ # Target+ results = dict()++ # Whole bunch here:+ # http://en.wikipedia.org/wiki/Comparison_of_DNS_blacklists+ # Check out:+ # http://www.blocklist.de/en/rbldns.html+ checks = {+ 'zen.spamhaus.org': {+ '127.0.0.2': "Spamhaus (Zen) - Spammer",+ '127.0.0.3': "Spamhaus (Zen) - Spammer",+ '127.0.0.4': "Spamhaus (Zen) - Proxies, Trojans, etc.",+ '127.0.0.5': "Spamhaus (Zen) - Proxies, Trojans, etc.",+ '127.0.0.6': "Spamhaus (Zen) - Proxies, Trojans, etc.",+ '127.0.0.7': "Spamhaus (Zen) - Proxies, Trojans, etc.",+ '127.0.0.10': "Spamhaus (Zen) - Potential Spammer",+ '127.0.0.11': "Spamhaus (Zen) - Potential Spammer"+ }+ }++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc+ 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 ['IP_ADDRESS', 'AFFILIATE_IPADDR', 'NETBLOCK_OWNER',+ 'NETBLOCK_MEMBER']++ # What events this module produces+ # This is to support the end user in selecting modules based on events+ # produced.+ def producedEvents(self):+ return ["BLACKLISTED_IPADDR", "BLACKLISTED_AFFILIATE_IPADDR",+ "BLACKLISTED_SUBNET", "BLACKLISTED_NETBLOCK"]++ # Swap 1.2.3.4 to 4.3.2.1+ def reverseAddr(self, ipaddr):+ return '.'.join(reversed(ipaddr.split('.')))++ def queryAddr(self, qaddr, parentEvent):+ eventName = parentEvent.eventType++ for domain in self.checks:+ if self.checkForStop():+ return None++ try:+ lookup = self.reverseAddr(qaddr) + "." + domain+ self.sf.debug("Checking Blacklist: " + lookup)+ addrs = self.sf.normalizeDNS(socket.gethostbyname_ex(lookup))+ self.sf.debug("Addresses returned: " + str(addrs))++ text = None+ for addr in addrs:+ if type(self.checks[domain]) is str:+ text = self.checks[domain] + " (" + qaddr + ")"+ break+ else:+ if str(addr) not in self.checks[domain].keys():+ self.sf.debug("Return code not found in list: " + str(addr))+ continue++ k = str(addr)+ text = self.checks[domain][k] + " (" + qaddr + ")"+ break++ if text is not None:+ if eventName == "AFFILIATE_IPADDR":+ e = "BLACKLISTED_AFFILIATE_IPADDR"+ if eventName == "IP_ADDRESS":+ e = "BLACKLISTED_IPADDR"+ if eventName == "NETBLOCK_OWNER":+ e = "BLACKLISTED_NETBLOCK"+ if eventName == "NETBLOCK_MEMBER":+ e = "BLACKLISTED_SUBNET"++ evt = SpiderFootEvent(e, text, self.__name__, parentEvent)+ self.notifyListeners(evt)++ except BaseException as e:+ self.sf.debug("Unable to resolve " + qaddr + " / " + lookup + ": " + str(e))++ return None++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data+ parentEvent = event+ addrlist = list()++ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)++ if eventData in self.results:+ return None+ self.results[eventData] = True++ if eventName == 'NETBLOCK_OWNER' and self.opts['netblocklookup']:+ 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++ if eventName == 'NETBLOCK_MEMBER' and self.opts['subnetlookup']:+ if IPNetwork(eventData).prefixlen < self.opts['maxsubnet']:+ self.sf.debug("Network size bigger than permitted: " ++ str(IPNetwork(eventData).prefixlen) + " > " ++ str(self.opts['maxsubnet']))+ return None++ if eventName.startswith("NETBLOCK_"):+ for addr in IPNetwork(eventData):+ if self.checkForStop():+ return None+ self.queryAddr(str(addr), parentEvent)+ else:+ self.queryAddr(eventData, parentEvent)++# End of sfp_spamhaus classdiff --git a/modules/sfp_uceprotect.py b/modules/sfp_uceprotect.pynew file mode 100644index 00000000..12b2c93d--- /dev/null+++ b/modules/sfp_uceprotect.py@@ -0,0 +1,155 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_uceprotect+# Purpose: SpiderFoot plug-in for looking up whether IPs/Netblocks/Domains+# appear in the UCEPROTECT blacklist, indicating potential open-relays,+# open proxies, malicious servers, vulnerable servers, etc.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 07/01/2014+# Copyright: (c) Steve Micallef 2014+# Licence: GPL+# -------------------------------------------------------------------------------++import socket+from netaddr import IPNetwork+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent+++class sfp_uceprotect(SpiderFootPlugin):+ """UCEPROTECT:Investigate,Passive:Blacklists::Query the UCEPROTECT databases for open relays, open proxies, vulnerable servers, etc."""++ # Default options+ opts = {+ 'netblocklookup': True,+ 'maxnetblock': 24,+ 'subnetlookup': True,+ 'maxsubnet': 24+ }++ # Option descriptions+ optdescs = {+ '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.)"+ }++ # Target+ results = dict()++ # Whole bunch here:+ # http://en.wikipedia.org/wiki/Comparison_of_DNS_blacklists+ # Check out:+ # http://www.blocklist.de/en/rbldns.html+ checks = {+ "dnsbl-1.uceprotect.net": 'UCEPROTECT - Level 1 (high likelihood)',+ "dnsbl-2.uceprotect.net": 'UCEPROTECT - Level 2 (some false positives)'+ }++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc+ 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 ['IP_ADDRESS', 'AFFILIATE_IPADDR', 'NETBLOCK_OWNER',+ 'NETBLOCK_MEMBER']++ # What events this module produces+ # This is to support the end user in selecting modules based on events+ # produced.+ def producedEvents(self):+ return ["BLACKLISTED_IPADDR", "BLACKLISTED_AFFILIATE_IPADDR",+ "BLACKLISTED_SUBNET", "BLACKLISTED_NETBLOCK"]++ # Swap 1.2.3.4 to 4.3.2.1+ def reverseAddr(self, ipaddr):+ return '.'.join(reversed(ipaddr.split('.')))++ def queryAddr(self, qaddr, parentEvent):+ eventName = parentEvent.eventType++ for domain in self.checks:+ if self.checkForStop():+ return None++ try:+ lookup = self.reverseAddr(qaddr) + "." + domain+ self.sf.debug("Checking Blacklist: " + lookup)+ addrs = self.sf.normalizeDNS(socket.gethostbyname_ex(lookup))+ self.sf.debug("Addresses returned: " + str(addrs))++ text = None+ for addr in addrs:+ if type(self.checks[domain]) is str:+ text = self.checks[domain] + " (" + qaddr + ")"+ break+ else:+ if str(addr) not in self.checks[domain].keys():+ self.sf.debug("Return code not found in list: " + str(addr))+ continue++ k = str(addr)+ text = self.checks[domain][k] + " (" + qaddr + ")"+ break++ if text is not None:+ if eventName == "AFFILIATE_IPADDR":+ e = "BLACKLISTED_AFFILIATE_IPADDR"+ if eventName == "IP_ADDRESS":+ e = "BLACKLISTED_IPADDR"+ if eventName == "NETBLOCK_OWNER":+ e = "BLACKLISTED_NETBLOCK"+ if eventName == "NETBLOCK_MEMBER":+ e = "BLACKLISTED_SUBNET"++ evt = SpiderFootEvent(e, text, self.__name__, parentEvent)+ self.notifyListeners(evt)++ except BaseException as e:+ self.sf.debug("Unable to resolve " + qaddr + " / " + lookup + ": " + str(e))++ return None++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data+ parentEvent = event+ addrlist = list()++ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)++ if eventData in self.results:+ return None+ self.results[eventData] = True++ if eventName == 'NETBLOCK_OWNER' and self.opts['netblocklookup']:+ 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++ if eventName == 'NETBLOCK_MEMBER' and self.opts['subnetlookup']:+ if IPNetwork(eventData).prefixlen < self.opts['maxsubnet']:+ self.sf.debug("Network size bigger than permitted: " ++ str(IPNetwork(eventData).prefixlen) + " > " ++ str(self.opts['maxsubnet']))+ return None++ if eventName.startswith("NETBLOCK_"):+ for addr in IPNetwork(eventData):+ if self.checkForStop():+ return None+ self.queryAddr(str(addr), parentEvent)+ else:+ self.queryAddr(eventData, parentEvent)++# End of sfp_uceprotect class