Skip to content

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

sfp_cleantalk: Report blocked hosts as blacklisted (#1534)

bcolesf2a3acdf1bac
diff --git a/modules/sfp_cleantalk.py b/modules/sfp_cleantalk.py
index 092774de..96feefa5 100644
--- a/modules/sfp_cleantalk.py
+++ b/modules/sfp_cleantalk.py
@@ -47,7 +47,6 @@ class sfp_cleantalk(SpiderFootPlugin):
}
}
- # Default options
opts = {
'checkaffiliates': True,
'cacheperiod': 18,
@@ -55,7 +54,6 @@ class sfp_cleantalk(SpiderFootPlugin):
'checksubnets': True
}
- # Option descriptions
optdescs = {
'checkaffiliates': "Apply checks to affiliate IP addresses?",
'cacheperiod': "Hours to cache list data before re-fetching.",
@@ -74,15 +72,25 @@ class sfp_cleantalk(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_MEMBER", "NETBLOCK_OWNER"]
+ return [
+ 'IP_ADDRESS',
+ 'AFFILIATE_IPADDR',
+ 'NETBLOCK_OWNER',
+ 'NETBLOCK_MEMBER'
+ ]
- # What events this module produces
def producedEvents(self):
- return ["MALICIOUS_IPADDR", "MALICIOUS_AFFILIATE_IPADDR",
- "MALICIOUS_SUBNET", "MALICIOUS_NETBLOCK"]
+ return [
+ "BLACKLISTED_IPADDR",
+ "BLACKLISTED_AFFILIATE_IPADDR",
+ "BLACKLISTED_SUBNET",
+ "BLACKLISTED_NETBLOCK",
+ "MALICIOUS_IPADDR",
+ "MALICIOUS_AFFILIATE_IPADDR",
+ "MALICIOUS_NETBLOCK",
+ "MALICIOUS_SUBNET",
+ ]
def query(self, qry, targetType):
cid = "_cleantalk"
@@ -128,13 +136,11 @@ class sfp_cleantalk(SpiderFootPlugin):
return None
- # Handle events sent to this module
def handleEvent(self, event):
eventName = event.eventType
- srcModuleName = event.module
eventData = event.data
- self.debug(f"Received event, {eventName}, from {srcModuleName}")
+ self.debug(f"Received event, {eventName}, from {event.module}")
if eventData in self.results:
self.debug(f"Skipping {eventData}, already checked.")
@@ -147,23 +153,28 @@ class sfp_cleantalk(SpiderFootPlugin):
if eventName == 'IP_ADDRESS':
targetType = 'ip'
- evtType = 'MALICIOUS_IPADDR'
+ malicious_type = "MALICIOUS_IPADDR"
+ blacklist_type = "BLACKLISTED_IPADDR"
elif eventName == 'AFFILIATE_IPADDR':
if not self.opts.get('checkaffiliates', False):
return
targetType = 'ip'
- evtType = 'MALICIOUS_AFFILIATE_IPADDR'
+ malicious_type = "MALICIOUS_AFFILIATE_IPADDR"
+ blacklist_type = "BLACKLISTED_AFFILIATE_IPADDR"
elif eventName == 'NETBLOCK_OWNER':
if not self.opts.get('checknetblocks', False):
return
targetType = 'netblock'
- evtType = 'MALICIOUS_NETBLOCK'
+ malicious_type = "MALICIOUS_NETBLOCK"
+ blacklist_type = "BLACKLISTED_NETBLOCK"
elif eventName == 'NETBLOCK_MEMBER':
if not self.opts.get('checksubnets', False):
return
targetType = 'netblock'
- evtType = 'MALICIOUS_SUBNET'
+ malicious_type = "MALICIOUS_SUBNET"
+ blacklist_type = "BLACKLISTED_SUBNET"
else:
+ self.debug(f"Unexpected event type {eventName}, skipping")
return
self.debug(f"Checking maliciousness of {eventData} with CleanTalk Spam List")
@@ -173,8 +184,14 @@ class sfp_cleantalk(SpiderFootPlugin):
if not url:
return
+ self.debug(f"{eventData} found in Cleantalk Spam List")
+
text = f"CleanTalk Spam List [{eventData}]\n<SFURL>{url}</SFURL>"
- evt = SpiderFootEvent(evtType, text, self.__name__, event)
+
+ evt = SpiderFootEvent(blacklist_type, text, self.__name__, event)
+ self.notifyListeners(evt)
+
+ evt = SpiderFootEvent(malicious_type, text, self.__name__, event)
self.notifyListeners(evt)
# End of sfp_cleantalk class
diff --git a/test/unit/modules/test_sfp_cleantalk.py b/test/unit/modules/test_sfp_cleantalk.py
index 97dc47a5..e16b32e4 100644
--- a/test/unit/modules/test_sfp_cleantalk.py
+++ b/test/unit/modules/test_sfp_cleantalk.py
@@ -34,27 +34,39 @@ class TestModulecleantalk(unittest.TestCase):
module = sfp_cleantalk()
self.assertIsInstance(module.producedEvents(), list)
- @unittest.skip("todo")
- 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_cleantalk()
module.setup(sf, dict())
- target_value = 'example target value'
- target_type = 'IP_ADDRESS'
+ target_value = 'spiderfoot.net'
+ target_type = 'INTERNET_NAME'
target = SpiderFootTarget(target_value, target_type)
module.setTarget(target)
+ module.opts['_fetchtimeout'] = 15
+ module.optdescs['_fetchtimeout'] = ''
+ module.opts['_useragent'] = ''
+ module.optdescs['_useragent'] = ''
+
+ def new_notifyListeners(self, event):
+ raise Exception(f"Raised event {event.eventType}: {event.data}")
+
+ module.notifyListeners = new_notifyListeners.__get__(module, sfp_cleantalk)
+
event_type = 'ROOT'
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.0.0.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)