Skip to content

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

sfp_dns_for_family: Add sfp_dns_for_family module (#1525)

bcoles228a57bc457b
diff --git a/modules/sfp_dns_for_family.py b/modules/sfp_dns_for_family.py
new file mode 100644
index 00000000..67f45e5b
--- /dev/null
+++ b/modules/sfp_dns_for_family.py
@@ -0,0 +1,117 @@
+# -*- coding: utf-8 -*-
+# -------------------------------------------------------------------------------
+# Name: sfp_dns_for_family
+# Purpose: Check if a host would be blocked by DNS for Family.
+#
+# Author: <[email protected]>
+#
+# Created: 2021-10-11
+# Copyright: (c) bcoles 2021
+# Licence: GPL
+# -------------------------------------------------------------------------------
+
+import dns.resolver
+
+from spiderfoot import SpiderFootEvent, SpiderFootPlugin
+
+
+class sfp_dns_for_family(SpiderFootPlugin):
+
+ meta = {
+ 'name': "DNS for Family",
+ 'summary': "Check if a host would be blocked by DNS for Family.",
+ 'flags': [],
+ 'useCases': ["Investigate", "Passive"],
+ 'categories': ["Reputation Systems"],
+ 'dataSource': {
+ 'website': "https://dnsforfamily.com/",
+ 'model': "FREE_NOAUTH_UNLIMITED",
+ 'references': [
+ "https://dnsforfamily.com/",
+ ],
+ 'favIcon': "https://dnsforfamily.com/Icons/favicon-32x32.png",
+ 'logo': "https://dnsforfamily.com/Templates/assets/images/logo.svg",
+ 'description': "DNS for Family aims to block websites which are considered as porn. "
+ "So that you and your children can safely surf internet to their heart's desire, "
+ "without worrying to be followed to harmful websites."
+ }
+ }
+
+ opts = {
+ }
+
+ optdescs = {
+ }
+
+ results = None
+
+ def setup(self, sfc, userOpts=dict()):
+ self.sf = sfc
+ self.results = self.tempStorage()
+
+ for opt in list(userOpts.keys()):
+ self.opts[opt] = userOpts[opt]
+
+ def watchedEvents(self):
+ return [
+ "INTERNET_NAME",
+ "AFFILIATE_INTERNET_NAME",
+ "CO_HOSTED_SITE"
+ ]
+
+ def producedEvents(self):
+ return [
+ "BLACKLISTED_INTERNET_NAME",
+ "BLACKLISTED_AFFILIATE_INTERNET_NAME",
+ "BLACKLISTED_COHOST",
+ ]
+
+ def queryAddr(self, qaddr):
+ if not qaddr:
+ return None
+
+ res = dns.resolver.Resolver()
+ res.nameservers = ["94.130.180.225", "78.47.64.161"]
+
+ try:
+ return res.resolve(qaddr)
+ except Exception:
+ self.debug(f"Unable to resolve {qaddr}")
+
+ return None
+
+ def handleEvent(self, event):
+ eventName = event.eventType
+ eventData = event.data
+
+ self.debug(f"Received event, {eventName}, from {event.module}")
+
+ if eventData in self.results:
+ return
+
+ self.results[eventData] = True
+
+ if eventName == "INTERNET_NAME":
+ blacklist_type = "BLACKLISTED_INTERNET_NAME"
+ elif eventName == "AFFILIATE_INTERNET_NAME":
+ blacklist_type = "BLACKLISTED_AFFILIATE_INTERNET_NAME"
+ elif eventName == "CO_HOSTED_SITE":
+ blacklist_type = "BLACKLISTED_COHOST"
+ else:
+ self.debug(f"Unexpected event type {eventName}, skipping")
+
+ res = self.queryAddr(eventData)
+
+ if not res:
+ return
+
+ for result in res:
+ k = str(result)
+ if k != '159.69.10.249':
+ continue
+
+ self.debug(f"{eventData} blocked by DNS for Family")
+ evt = SpiderFootEvent(blacklist_type, f"DNS for Family [{eventData}]", self.__name__, event)
+ self.notifyListeners(evt)
+
+# End of sfp_dns_for_family class
diff --git a/test/unit/modules/test_sfp_dns_for_family.py b/test/unit/modules/test_sfp_dns_for_family.py
new file mode 100644
index 00000000..b2d367f6
--- /dev/null
+++ b/test/unit/modules/test_sfp_dns_for_family.py
@@ -0,0 +1,109 @@
+# test_sfp_dns_for_family.py
+import pytest
+import unittest
+
+from modules.sfp_dns_for_family import sfp_dns_for_family
+from sflib import SpiderFoot
+from spiderfoot import SpiderFootEvent, SpiderFootTarget
+
+
+class TestModuleDnsForFamily(unittest.TestCase):
+ """
+ Test modules.sfp_dns_for_family
+ """
+
+ def test_opts(self):
+ module = sfp_dns_for_family()
+ self.assertEqual(len(module.opts), len(module.optdescs))
+
+ def test_setup(self):
+ """
+ Test setup(self, sfc, userOpts=dict())
+ """
+ sf = SpiderFoot(self.default_options)
+
+ module = sfp_dns_for_family()
+ module.setup(sf, dict())
+
+ def test_watchedEvents_should_return_list(self):
+ module = sfp_dns_for_family()
+ self.assertIsInstance(module.watchedEvents(), list)
+
+ def test_producedEvents_should_return_list(self):
+ module = sfp_dns_for_family()
+ self.assertIsInstance(module.producedEvents(), list)
+
+ def test_handleEvent_event_data_safe_internet_name_not_blocked_should_not_return_event(self):
+ sf = SpiderFoot(self.default_options)
+
+ module = sfp_dns_for_family()
+ module.setup(sf, dict())
+
+ 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_dns_for_family)
+
+ event_type = 'ROOT'
+ event_data = 'example data'
+ event_module = ''
+ source_event = ''
+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
+
+ event_type = 'INTERNET_NAME'
+ event_data = 'dns_for_family.com'
+ event_module = 'example module'
+ source_event = evt
+
+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
+ result = module.handleEvent(evt)
+
+ self.assertIsNone(result)
+
+ def test_handleEvent_event_data_adult_internet_name_blocked_should_return_event(self):
+ sf = SpiderFoot(self.default_options)
+
+ module = sfp_dns_for_family()
+ module.setup(sf, dict())
+
+ target_value = 'spiderfoot.net'
+ target_type = 'INTERNET_NAME'
+ target = SpiderFootTarget(target_value, target_type)
+ module.setTarget(target)
+
+ def new_notifyListeners(self, event):
+ expected = 'BLACKLISTED_INTERNET_NAME'
+ if str(event.eventType) != expected:
+ raise Exception(f"{event.eventType} != {expected}")
+
+ expected = 'DNS for Family [pornhub.com]'
+ if str(event.data) != expected:
+ raise Exception(f"{event.data} != {expected}")
+
+ raise Exception("OK")
+
+ module.notifyListeners = new_notifyListeners.__get__(module, sfp_dns_for_family)
+
+ event_type = 'ROOT'
+ event_data = 'example data'
+ event_module = ''
+ source_event = ''
+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
+
+ event_type = 'INTERNET_NAME'
+ event_data = 'pornhub.com'
+ event_module = 'example module'
+ source_event = evt
+
+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
+
+ with self.assertRaises(Exception) as cm:
+ module.handleEvent(evt)
+
+ self.assertEqual("OK", str(cm.exception))