Skip to content

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

sfp_opendns: Use OpenDNS FamilyShield DNS servers (#1499)

bcolesf9d45efad154
diff --git a/modules/sfp_opendns.py b/modules/sfp_opendns.py
index c8710f58..e5a28a12 100644
--- a/modules/sfp_opendns.py
+++ b/modules/sfp_opendns.py
@@ -28,6 +28,7 @@ class sfp_opendns(SpiderFootPlugin):
'website': "https://www.opendns.com/",
'model': "FREE_NOAUTH_UNLIMITED",
'references': [
+ "https://www.opendns.com/setupguide/?url=familyshield",
"https://support.opendns.com/hc/en-us/categories/204012807-OpenDNS-Knowledge-Base",
"https://support.opendns.com/hc/en-us/categories/204012907-OpenDNS-Device-Configuration"
],
@@ -35,8 +36,9 @@ class sfp_opendns(SpiderFootPlugin):
'logo': "https://d15ni2z53ptwz9.cloudfront.net/opendns-www/img/logo-opendns.png",
'description': "Cisco Umbrella provides protection against threats on the internet such as "
"malware, phishing, and ransomware.\n"
- "OpenDNS is a suite of consumer products aimed at "
- "making your internet faster, safer, and more reliable.",
+ "OpenDNS is a suite of consumer products aimed at making your internet faster, safer, and more reliable. "
+ "FamilyShield is the single easiest way to protect your kids online, block adult websites, "
+ "and protect your family from phishing and malware.",
}
}
@@ -48,6 +50,15 @@ class sfp_opendns(SpiderFootPlugin):
results = None
+ checks = {
+ "146.112.61.105": "OpenDNS - Botnet",
+ "146.112.61.106": "OpenDNS - Adult",
+ "146.112.61.107": "OpenDNS - Malware",
+ "146.112.61.108": "OpenDNS - Phishing",
+ "146.112.61.109": "OpenDNS - Blocked",
+ "146.112.61.110": "OpenDNS - Malware",
+ }
+
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
self.results = self.tempStorage()
@@ -66,24 +77,22 @@ class sfp_opendns(SpiderFootPlugin):
return [
"MALICIOUS_INTERNET_NAME",
"MALICIOUS_AFFILIATE_INTERNET_NAME",
- "MALICIOUS_COHOST"]
+ "MALICIOUS_COHOST"
+ ]
def queryAddr(self, qaddr):
+ if not qaddr:
+ return None
+
res = dns.resolver.Resolver()
- res.nameservers = ["208.67.222.222", "208.67.220.220"]
- # FamilyShield
- # res.nameservers = ["208.67.222.123", "208.67.220.123"]
+ res.nameservers = ["208.67.222.123", "208.67.220.123"]
try:
- addrs = res.resolve(qaddr)
- self.debug(f"Addresses returned: {addrs}")
+ return res.resolve(qaddr)
except Exception:
self.debug(f"Unable to resolve {qaddr}")
- return False
- if addrs:
- return True
- return False
+ return None
def handleEvent(self, event):
eventName = event.eventType
@@ -96,30 +105,26 @@ class sfp_opendns(SpiderFootPlugin):
self.results[eventData] = True
- # Check that it resolves first, as it becomes a valid
- # malicious host only if NOT resolved by OpenDNS.
- if not self.sf.resolveHost(eventData) and not self.sf.resolveHost6(eventData):
- return
+ if eventName == "INTERNET_NAME":
+ e = "MALICIOUS_INTERNET_NAME"
+ elif eventName == "AFFILIATE_INTERNET_NAME":
+ e = "MALICIOUS_AFFILIATE_INTERNET_NAME"
+ elif eventName == "CO_HOSTED_SITE":
+ e = "MALICIOUS_COHOST"
+ else:
+ self.debug(f"Unexpected event type {eventName}, skipping")
- found = self.queryAddr(eventData)
+ res = self.queryAddr(eventData)
- # Host was found, not blocked
- if found:
+ if not res:
return
- self.debug(f"{eventData} was blocked by OpenDNS")
-
- typ = "MALICIOUS_" + eventName
-
- if eventName == "CO_HOSTED_SITE":
- typ = "MALICIOUS_COHOST"
+ self.debug(f"{eventData} found in OpenDNS Blocklist: {res}")
- evt = SpiderFootEvent(
- typ,
- f"Blocked by OpenDNS [{eventData}]",
- self.__name__,
- event
- )
- self.notifyListeners(evt)
+ for result in res:
+ k = str(result)
+ if k in self.checks:
+ evt = SpiderFootEvent(e, f"{self.checks[k]} [{eventData}]", self.__name__, event)
+ self.notifyListeners(evt)
# End of sfp_opendns class
diff --git a/test/unit/modules/test_sfp_opendns.py b/test/unit/modules/test_sfp_opendns.py
index fdabde72..9c8974aa 100644
--- a/test/unit/modules/test_sfp_opendns.py
+++ b/test/unit/modules/test_sfp_opendns.py
@@ -34,10 +34,7 @@ class TestModuleopendns(unittest.TestCase):
module = sfp_opendns()
self.assertIsInstance(module.producedEvents(), list)
- def test_queryAddr_should_resolve_unblocked_host(self):
- """
- Test queryAddr(self, qaddr)
- """
+ def test_handleEvent_event_data_safe_internet_name_not_blocked_should_not_return_event(self):
sf = SpiderFoot(self.default_options)
module = sfp_opendns()
@@ -48,29 +45,65 @@ class TestModuleopendns(unittest.TestCase):
target = SpiderFootTarget(target_value, target_type)
module.setTarget(target)
- resolved = module.queryAddr('opendns.com')
- 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)
- """
+ module.notifyListeners = new_notifyListeners.__get__(module, sfp_opendns)
+
+ 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 = 'opendns.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_opendns()
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)
+ def new_notifyListeners(self, event):
+ expected = 'MALICIOUS_INTERNET_NAME'
+ if str(event.eventType) != expected:
+ raise Exception(f"{event.eventType} != {expected}")
+
+ expected = 'OpenDNS - Adult [pornhub.com]'
+ if str(event.data) != expected:
+ raise Exception(f"{event.data} != {expected}")
+
+ raise Exception("OK")
+
+ module.notifyListeners = new_notifyListeners.__get__(module, sfp_opendns)
+
event_type = 'ROOT'
event_data = 'example data'
event_module = ''
source_event = ''
evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
- result = module.handleEvent(evt)
+ event_type = 'INTERNET_NAME'
+ event_data = 'pornhub.com'
+ event_module = 'example module'
+ source_event = evt
- self.assertIsNone(result)
+ 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))