Skip to content

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

sfp_quad9: Report blocked hosts as blacklisted (#1505)

bcolesa83998e45552
diff --git a/modules/sfp_quad9.py b/modules/sfp_quad9.py
index f945010f..39522836 100644
--- a/modules/sfp_quad9.py
+++ b/modules/sfp_quad9.py
@@ -20,7 +20,7 @@ class sfp_quad9(SpiderFootPlugin):
meta = {
'name': "Quad9",
- 'summary': "Check if a host would be blocked by Quad9",
+ 'summary': "Check if a host would be blocked by Quad9 DNS.",
'flags': [],
'useCases': ["Investigate", "Passive"],
'categories': ["Reputation Systems"],
@@ -29,7 +29,7 @@ class sfp_quad9(SpiderFootPlugin):
'model': "FREE_NOAUTH_UNLIMITED",
'references': [
"https://www.quad9.net/faq/",
- "https://www.quad9.net/#Setup_Quad9"
+ "https://support.quad9.net/hc/en-us/categories/360002571772-Configuration",
],
'favIcon': "https://quad9.net/wp-content/uploads/2018/01/favicon-32.png",
'logo': "https://quad9.net/wp-content/uploads/2017/11/[email protected]",
@@ -58,13 +58,21 @@ class sfp_quad9(SpiderFootPlugin):
self.opts[opt] = userOpts[opt]
def watchedEvents(self):
- return ["INTERNET_NAME", "AFFILIATE_INTERNET_NAME", "CO_HOSTED_SITE"]
+ return [
+ "INTERNET_NAME",
+ "AFFILIATE_INTERNET_NAME",
+ "CO_HOSTED_SITE"
+ ]
def producedEvents(self):
return [
+ "BLACKLISTED_INTERNET_NAME",
+ "BLACKLISTED_AFFILIATE_INTERNET_NAME",
+ "BLACKLISTED_COHOST",
"MALICIOUS_INTERNET_NAME",
"MALICIOUS_AFFILIATE_INTERNET_NAME",
- "MALICIOUS_COHOST"]
+ "MALICIOUS_COHOST",
+ ]
def query(self, qry):
res = dns.resolver.Resolver()
@@ -85,7 +93,6 @@ class sfp_quad9(SpiderFootPlugin):
eventName = event.eventType
srcModuleName = event.module
eventData = event.data
- parentEvent = event
self.debug(f"Received event, {eventName}, from {srcModuleName}")
@@ -94,6 +101,18 @@ class sfp_quad9(SpiderFootPlugin):
self.results[eventData] = True
+ if eventName == "INTERNET_NAME":
+ malicious_type = "MALICIOUS_INTERNET_NAME"
+ blacklist_type = "BLACKLISTED_INTERNET_NAME"
+ elif eventName == "AFFILIATE_INTERNET_NAME":
+ malicious_type = "MALICIOUS_AFFILIATE_INTERNET_NAME"
+ blacklist_type = "BLACKLISTED_AFFILIATE_INTERNET_NAME"
+ elif eventName == "CO_HOSTED_SITE":
+ malicious_type = "MALICIOUS_COHOST"
+ blacklist_type = "BACKLISTED_COHOST"
+ else:
+ self.debug(f"Unexpected event type {eventName}, skipping")
+
# Check that it resolves first, as it becomes a valid
# malicious host only if NOT resolved by Quad9.
if not self.sf.resolveHost(eventData) and not self.sf.resolveHost6(eventData):
@@ -105,15 +124,19 @@ class sfp_quad9(SpiderFootPlugin):
if found:
return
- typ = "MALICIOUS_" + eventName
-
- if eventName == "CO_HOSTED_SITE":
- typ = "MALICIOUS_COHOST"
+ evt = SpiderFootEvent(
+ blacklist_type,
+ f"Quad9 [{eventData}]\n<SFURL>https://quad9.net/result/?url={eventData}</SFURL>",
+ self.__name__,
+ event
+ )
+ self.notifyListeners(evt)
evt = SpiderFootEvent(
- typ,
- f"Blocked by Quad9 [{eventData}]\n<SFURL>https://quad9.net/result/?url={eventData}</SFURL>",
- self.__name__, parentEvent
+ malicious_type,
+ f"Quad9 [{eventData}]\n<SFURL>https://quad9.net/result/?url={eventData}</SFURL>",
+ self.__name__,
+ event
)
self.notifyListeners(evt)
diff --git a/test/unit/modules/test_sfp_quad9.py b/test/unit/modules/test_sfp_quad9.py
index 2cacd6bb..579db784 100644
--- a/test/unit/modules/test_sfp_quad9.py
+++ b/test/unit/modules/test_sfp_quad9.py
@@ -34,10 +34,7 @@ class TestModulequad9(unittest.TestCase):
module = sfp_quad9()
self.assertIsInstance(module.producedEvents(), list)
- def test_query_should_resolve_unblocked_host(self):
- """
- Test query(self, qaddr)
- """
+ def test_handleEvent_event_data_safe_internet_name_not_blocked_should_not_return_event(self):
sf = SpiderFoot(self.default_options)
module = sfp_quad9()
@@ -48,22 +45,10 @@ class TestModulequad9(unittest.TestCase):
target = SpiderFootTarget(target_value, target_type)
module.setTarget(target)
- resolved = module.query('quad9.net')
- self.assertTrue(resolved)
+ def new_notifyListeners(self, event):
+ raise Exception(f"Raised event {event.eventType}: {event.data}")
- def test_handleEvent(self):
- """
- Test handleEvent(self, event)
- """
- sf = SpiderFoot(self.default_options)
-
- module = sfp_quad9()
- module.setup(sf, dict())
-
- target_value = 'example target value'
- target_type = 'IP_ADDRESS'
- target = SpiderFootTarget(target_value, target_type)
- module.setTarget(target)
+ module.notifyListeners = new_notifyListeners.__get__(module, sfp_quad9)
event_type = 'ROOT'
event_data = 'example data'
@@ -71,6 +56,12 @@ class TestModulequad9(unittest.TestCase):
source_event = ''
evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
+ event_type = 'INTERNET_NAME'
+ event_data = 'quad9.net'
+ event_module = 'example module'
+ source_event = evt
+
+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
result = module.handleEvent(evt)
self.assertIsNone(result)