Skip to content

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

sfp_sorbs: Cleanup; Report blocked hosts as malicious (#1527)

bcolese7fe2b9fb01e
diff --git a/modules/sfp_sorbs.py b/modules/sfp_sorbs.py
index 66ec52ad..41949a5c 100644
--- a/modules/sfp_sorbs.py
+++ b/modules/sfp_sorbs.py
@@ -60,21 +60,39 @@ class sfp_sorbs(SpiderFootPlugin):
'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 = None
- # Whole bunch here:
- # http://en.wikipedia.org/wiki/Comparison_of_DNS_blacklists
- # Check out:
- # http://www.blocklist.de/en/rbldns.html
+ # Zones:
+ # "http.dnsbl.sorbs.net": "127.0.0.2",
+ # "socks.dnsbl.sorbs.net": "127.0.0.3",
+ # "misc.dnsbl.sorbs.net": "127.0.0.4",
+ # "smtp.dnsbl.sorbs.net": "127.0.0.5",
+ # "new.spam.dnsbl.sorbs.net": "127.0.0.6",
+ # "recent.spam.dnsbl.sorbs.net": "127.0.0.6",
+ # "old.spam.dnsbl.sorbs.net": "127.0.0.6",
+ # "spam.dnsbl.sorbs.net": "127.0.0.6",
+ # "escalations.dnsbl.sorbs.net": "127.0.0.6",
+ # "web.dnsbl.sorbs.net": "127.0.0.7",
+ # "block.dnsbl.sorbs.net": "127.0.0.8",
+ # "zombie.dnsbl.sorbs.net": "127.0.0.9",
+ # "dul.dnsbl.sorbs.net": "127.0.0.10",
+ # "badconf.rhsbl.sorbs.net": "127.0.0.11",
+ # "nomail.rhsbl.sorbs.net": "127.0.0.12",
+ # "noserver.dnsbl.sorbs.net": "127.0.0.14",
+
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"
+ "127.0.0.2": "SORBS - Open HTTP Proxy",
+ "127.0.0.3": "SORBS - Open SOCKS Proxy",
+ "127.0.0.4": "SORBS - Open Proxy",
+ "127.0.0.5": "SORBS - Open SMTP Relay",
+ "127.0.0.6": "SORBS - Spammer",
+ "127.0.0.7": "SORBS - Vulnerability exposed to spammers",
+ "127.0.0.8": "SORBS - Host ignored by SORBS",
+ "127.0.0.9": "SORBS - Hijacked host",
+ "127.0.0.10": "SORBS - Dynamic IP address range",
+ "127.0.0.11": "SORBS - Misconfigured A or MX record",
+ "127.0.0.12": "SORBS - Host does not send mail",
+ "127.0.0.14": "SORBS - Network does not contain servers",
}
def setup(self, sfc, userOpts=dict()):
@@ -84,85 +102,85 @@ class sfp_sorbs(SpiderFootPlugin):
for opt in list(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']
+ 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"]
+ return [
+ "BLACKLISTED_IPADDR",
+ "BLACKLISTED_AFFILIATE_IPADDR",
+ "BLACKLISTED_SUBNET",
+ "BLACKLISTED_NETBLOCK",
+ "MALICIOUS_IPADDR",
+ "MALICIOUS_AFFILIATE_IPADDR",
+ "MALICIOUS_NETBLOCK",
+ "MALICIOUS_SUBNET",
+ "PROXY_HOST"
+ ]
# Swap 1.2.3.4 to 4.3.2.1
def reverseAddr(self, ipaddr):
+ if not self.sf.validIP(ipaddr):
+ self.debug(f"Invalid IPv4 address {ipaddr}")
+ return None
return '.'.join(reversed(ipaddr.split('.')))
- def queryAddr(self, qaddr, parentEvent):
- eventName = parentEvent.eventType
+ def queryAddr(self, qaddr):
+ """Query SORBS DNS for an IPv4 address.
- for domain in self.checks:
- if self.checkForStop():
- return
-
- try:
- lookup = self.reverseAddr(qaddr) + "." + domain
- self.debug("Checking Blacklist: " + lookup)
- addrs = self.sf.resolveHost(lookup)
- if not addrs:
- continue
+ Args:
+ qaddr (str): IPv4 address.
- self.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 list(self.checks[domain].keys()):
- self.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)
+ Returns:
+ list: SORBS DNS entries
+ """
+ if not self.sf.validIP(qaddr):
+ self.debug(f"Invalid IPv4 address {qaddr}")
+ return None
- except Exception as e:
- self.debug("Unable to resolve " + qaddr + " / " + lookup + ": " + str(e))
+ try:
+ lookup = self.reverseAddr(qaddr) + '.dnsbl.sorbs.net'
+ self.debug(f"Checking SORBS blacklist: {lookup}")
+ return self.sf.resolveHost(lookup)
+ except Exception as e:
+ self.debug(f"SORBS did not resolve {qaddr} / {lookup}: {e}")
- return
+ return None
- # Handle events sent to this module
def handleEvent(self, event):
eventName = event.eventType
- srcModuleName = event.module
eventData = event.data
- parentEvent = event
- self.debug(f"Received event, {eventName}, from {srcModuleName}")
+ self.debug(f"Received event, {eventName}, from {event.module}")
if eventData in self.results:
return
self.results[eventData] = True
- if eventName == 'NETBLOCK_OWNER':
+ if eventName == "AFFILIATE_IPADDR":
+ malicious_type = "MALICIOUS_AFFILIATE_IPADDR"
+ blacklist_type = "BLACKLISTED_AFFILIATE_IPADDR"
+ elif eventName == "IP_ADDRESS":
+ malicious_type = "MALICIOUS_IPADDR"
+ blacklist_type = "BLACKLISTED_IPADDR"
+ elif eventName == 'NETBLOCK_MEMBER':
+ if not self.opts['subnetlookup']:
+ return
+
+ max_subnet = self.opts['maxsubnet']
+ if IPNetwork(eventData).prefixlen < max_subnet:
+ self.debug(f"Network size bigger than permitted: {IPNetwork(eventData).prefixlen} > {max_subnet}")
+ return
+
+ malicious_type = "MALICIOUS_SUBNET"
+ blacklist_type = "BLACKLISTED_SUBNET"
+ elif eventName == 'NETBLOCK_OWNER':
if not self.opts['netblocklookup']:
return
@@ -171,21 +189,59 @@ class sfp_sorbs(SpiderFootPlugin):
self.debug(f"Network size bigger than permitted: {IPNetwork(eventData).prefixlen} > {max_netblock}")
return
- if eventName == 'NETBLOCK_MEMBER':
- if not self.opts['subnetlookup']:
- return
-
- max_subnet = self.opts['maxsubnet']
- if IPNetwork(eventData).prefixlen < max_subnet:
- self.debug(f"Network size bigger than permitted: {IPNetwork(eventData).prefixlen} > {max_subnet}")
- return
+ malicious_type = "MALICIOUS_NETBLOCK"
+ blacklist_type = "BLACKLISTED_NETBLOCK"
+ else:
+ self.debug(f"Unexpected event type {eventName}, skipping")
+ return
+ addrs = list()
if eventName.startswith("NETBLOCK_"):
for addr in IPNetwork(eventData):
- if self.checkForStop():
- return
- self.queryAddr(str(addr), parentEvent)
+ addrs.append(str(addr))
else:
- self.queryAddr(eventData, parentEvent)
+ addrs.append(eventData)
+
+ for addr in addrs:
+ if self.checkForStop():
+ return
+
+ res = self.queryAddr(addr)
+
+ self.results[addr] = True
+
+ if not res:
+ continue
+
+ self.debug(f"{addr} found in SORBS DNS")
+
+ for result in res:
+ k = str(result)
+ if k not in self.checks:
+ if not result.endswith('.dnsbl.sorbs.net'):
+ # This is an error. The "checks" dict may need to be updated.
+ self.error(f"SORBS resolved address {addr} to unknown IP address {result} not found in SORBS list.")
+ continue
+
+ evt = SpiderFootEvent(blacklist_type, f"{self.checks[k]} [{addr}]", self.__name__, event)
+ self.notifyListeners(evt)
+
+ if k in [
+ "127.0.0.2",
+ "127.0.0.3",
+ "127.0.0.4",
+ ]:
+ evt = SpiderFootEvent("PROXY_HOST", eventData, self.__name__, event)
+ self.notifyListeners(evt)
+
+ if k not in [
+ "127.0.0.8",
+ "127.0.0.10",
+ "127.0.0.11",
+ "127.0.0.12",
+ "127.0.0.14",
+ ]:
+ evt = SpiderFootEvent(malicious_type, f"{self.checks[k]} [{addr}]", self.__name__, event)
+ self.notifyListeners(evt)
# End of sfp_sorbs class
diff --git a/test/unit/modules/test_sfp_sorbs.py b/test/unit/modules/test_sfp_sorbs.py
index 737a9b42..47817ced 100644
--- a/test/unit/modules/test_sfp_sorbs.py
+++ b/test/unit/modules/test_sfp_sorbs.py
@@ -34,26 +34,34 @@ class TestModulesorbs(unittest.TestCase):
module = sfp_sorbs()
self.assertIsInstance(module.producedEvents(), list)
- def test_handleEvent(self):
- """
- Test handleEvent(self, event)
- """
+ def test_handleEvent_event_data_safe_ip_address_not_blocked_should_not_return_event(self):
sf = SpiderFoot(self.default_options)
module = sfp_sorbs()
module.setup(sf, dict())
- target_value = '1.1.1.1'
- target_type = 'IP_ADDRESS'
+ target_value = 'spiderfoot.net'
+ target_type = 'INTERNET_NAME'
target = SpiderFootTarget(target_value, target_type)
module.setTarget(target)
+ def new_notifyListeners(self, event):
+ raise Exception(f"Raised event {event.eventType}: {event.data}")
+
+ module.notifyListeners = new_notifyListeners.__get__(module, sfp_sorbs)
+
event_type = 'ROOT'
- event_data = '1.1.1.1'
+ event_data = 'example data'
event_module = ''
source_event = ''
evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
+ event_type = 'IP_ADDRESS'
+ event_data = '1.1.1.1'
+ event_module = 'example module'
+ source_event = evt
+
+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
result = module.handleEvent(evt)
self.assertIsNone(result)