Skip to content

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

sfp_uceprotect: Cleanup; Report blocked hosts as malicious (#1520)

bcoles4af80784a524
diff --git a/modules/sfp_uceprotect.py b/modules/sfp_uceprotect.py
index 543e031e..1b81be63 100644
--- a/modules/sfp_uceprotect.py
+++ b/modules/sfp_uceprotect.py
@@ -21,7 +21,7 @@ class sfp_uceprotect(SpiderFootPlugin):
meta = {
'name': "UCEPROTECT",
- 'summary': "Query the UCEPROTECT databases for open relays, open proxies, vulnerable servers, etc.",
+ 'summary': "Check if a netblock or IP address is in the UCEPROTECT database.",
'flags': [],
'useCases': ["Investigate", "Passive"],
'categories': ["Reputation Systems"],
@@ -29,17 +29,18 @@ class sfp_uceprotect(SpiderFootPlugin):
'website': "http://www.uceprotect.net/",
'model': "FREE_NOAUTH_UNLIMITED",
'references': [
+ "http://www.uceprotect.net/en/index.php?m=3&s=3",
"http://www.uceprotect.net/en/index.php?m=6&s=0",
+ "http://www.uceprotect.net/en/index.php?m=6&s=11",
"http://www.uceprotect.net/en/index.php?m=13&s=0",
"http://www.uceprotect.net/en/rblcheck.php"
],
- 'favIcon': "https://www.google.com/s2/favicons?domain=http://www.uceprotect.net/",
- 'logo': "http://www.uceprotect.net/en/logo.gif",
- 'description': "UCE Protect is a DNS Blacklisting service whose mission is to stop mail abuse globally.",
+ 'favIcon': "https://www.uceprotect.net/favicon.ico",
+ 'logo': "https://www.uceprotect.net/en/logo.gif",
+ 'description': "UCEPROTECT is a DNS blacklisting service whose mission is to stop mail abuse globally.",
}
}
- # Default options
opts = {
'netblocklookup': True,
'maxnetblock': 24,
@@ -47,7 +48,6 @@ class sfp_uceprotect(SpiderFootPlugin):
'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.)",
@@ -55,18 +55,8 @@ class sfp_uceprotect(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
- 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 = self.tempStorage()
@@ -74,108 +64,155 @@ class sfp_uceprotect(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",
+ ]
# 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
+ def queryDnsblLevel1(self, qaddr):
+ """Query UCEPROTECT DNS Level 1 for an IPv4 address.
- for domain in self.checks:
- if self.checkForStop():
- return
+ Args:
+ qaddr (str): IPv4 address.
+
+ Returns:
+ list: UCEPROTECT DNS entries
+ """
+ if not self.sf.validIP(qaddr):
+ self.debug(f"Invalid IPv4 address {qaddr}")
+ return None
+
+ try:
+ lookup = self.reverseAddr(qaddr) + '.dnsbl-1.uceprotect.net'
+ self.debug(f"Checking UCEPROTECT blacklist: {lookup}")
+ return self.sf.resolveHost(lookup)
+ except Exception as e:
+ self.debug(f"UCEPROTECT did not resolve {qaddr} / {lookup}: {e}")
+
+ return None
+
+ def queryDnsblLevel2(self, qaddr):
+ """Query UCEPROTECT DNS Level 2 for an IPv4 address.
+
+ Args:
+ qaddr (str): IPv4 address.
+
+ Returns:
+ list: UCEPROTECT DNS entries
+ """
+ if not self.sf.validIP(qaddr):
+ self.debug(f"Invalid IPv4 address {qaddr}")
+ return None
+
+ try:
+ lookup = self.reverseAddr(qaddr) + '.dnsbl-2.uceprotect.net'
+ self.debug(f"Checking UCEPROTECT blacklist: {lookup}")
+ return self.sf.resolveHost(lookup)
+ except Exception as e:
+ self.debug(f"UCEPROTECT did not resolve {qaddr} / {lookup}: {e}")
+
+ return None
- try:
- lookup = self.reverseAddr(qaddr) + "." + domain
- self.debug("Checking Blacklist: " + lookup)
- addrs = self.sf.resolveHost(lookup)
- self.debug("Addresses returned: " + str(addrs))
-
- if not addrs:
- continue
-
- 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)
-
- except Exception as e:
- self.debug("Unable to resolve " + qaddr + " / " + lookup + ": " + str(e))
-
- # 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
- else:
- if IPNetwork(eventData).prefixlen < self.opts['maxnetblock']:
- self.debug("Network size bigger than permitted: "
- + str(IPNetwork(eventData).prefixlen) + " > "
- + str(self.opts['maxnetblock']))
- return
-
- if eventName == 'NETBLOCK_MEMBER':
- if not self.opts['subnetlookup']:
+
+ max_netblock = self.opts['maxnetblock']
+ if IPNetwork(eventData).prefixlen < max_netblock:
+ self.debug(f"Network size bigger than permitted: {IPNetwork(eventData).prefixlen} > {max_netblock}")
return
- else:
- if IPNetwork(eventData).prefixlen < self.opts['maxsubnet']:
- self.debug("Network size bigger than permitted: "
- + str(IPNetwork(eventData).prefixlen) + " > "
- + str(self.opts['maxsubnet']))
- 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
+
+ level1 = self.queryDnsblLevel1(addr)
+ level2 = self.queryDnsblLevel2(addr)
+
+ self.results[addr] = True
+
+ if not level1 and not level2:
+ continue
+
+ self.debug(f"{addr} found in UCEPROTECT DNS")
+
+ url = f"https://www.uceprotect.net/en/rblcheck.php?ipr={addr}"
+
+ if level1:
+ description = f"UCEPROTECT - Level 1 (high likelihood) [{addr}]\n<SFURL>{url}</SFURL>"
+ evt = SpiderFootEvent(blacklist_type, description, self.__name__, event)
+ self.notifyListeners(evt)
+
+ evt = SpiderFootEvent(malicious_type, description, self.__name__, event)
+ self.notifyListeners(evt)
+
+ if level2:
+ description = f"UCEPROTECT - Level 2 (some false positives) [{addr}]\n<SFURL>{url}</SFURL>"
+
+ evt = SpiderFootEvent(blacklist_type, description, self.__name__, event)
+ self.notifyListeners(evt)
+
+ evt = SpiderFootEvent(malicious_type, description, self.__name__, event)
+ self.notifyListeners(evt)
# End of sfp_uceprotect class
diff --git a/test/unit/modules/test_sfp_uceprotect.py b/test/unit/modules/test_sfp_uceprotect.py
index 84a24d04..2c717c8d 100644
--- a/test/unit/modules/test_sfp_uceprotect.py
+++ b/test/unit/modules/test_sfp_uceprotect.py
@@ -34,26 +34,34 @@ class TestModuleuceprotect(unittest.TestCase):
module = sfp_uceprotect()
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_uceprotect()
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_uceprotect)
+
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)