Skip to content

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

sfp_yandexdns: Use family filter DNS servers (#1501)

bcoles156b1f2783bd
diff --git a/modules/sfp_yandexdns.py b/modules/sfp_yandexdns.py
index fbcf9c4f..750ca399 100644
--- a/modules/sfp_yandexdns.py
+++ b/modules/sfp_yandexdns.py
@@ -2,7 +2,7 @@
# -------------------------------------------------------------------------------
# Name: sfp_yandexdns
# Purpose: SpiderFoot plug-in for looking up whether hosts are blocked by
-# Yandex DNS (77.88.8.88 and 77.88.8.2)
+# Yandex DNS.
#
# Author: Steve Micallef <[email protected]>
#
@@ -20,7 +20,7 @@ class sfp_yandexdns(SpiderFootPlugin):
meta = {
'name': "Yandex DNS",
- 'summary': "Check if a host would be blocked by Yandex DNS",
+ 'summary': "Check if a host would be blocked by Yandex DNS.",
'flags': [],
'useCases': ["Investigate", "Passive"],
'categories': ["Reputation Systems"],
@@ -28,13 +28,16 @@ class sfp_yandexdns(SpiderFootPlugin):
'website': "https://yandex.com/",
'model': "FREE_NOAUTH_UNLIMITED",
'references': [
- "https://tech.yandex.com/"
+ "https://tech.yandex.com/",
+ "https://dns.yandex.com/advanced/",
],
'favIcon': "https://yastatic.net/iconostasis/_/tToKamh-mh5XlViKpgiJRQgjz1Q.png",
'logo': "https://yastatic.net/iconostasis/_/tToKamh-mh5XlViKpgiJRQgjz1Q.png",
- 'description': "Yandex is a technology company that builds intelligent products and services powered by machine learning. "
- "Our goal is to help consumers and businesses better navigate the online and offline world. "
- "Since 1997, we have delivered world-class, locally relevant search and information services.",
+ 'description': "Yandex.DNS is a free, recursive DNS service. "
+ "Yandex.DNS' servers are located in Russia, CIS countries, and Western Europe."
+ 'In "Basic" mode, there is no traffic filtering. '
+ 'In "Safe" mode, protection from infected and fraudulent sites is provided. '
+ '"Family" mode enables protection from dangerous sites and blocks sites with adult content.'
}
}
@@ -48,6 +51,11 @@ class sfp_yandexdns(SpiderFootPlugin):
results = None
+ checks = {
+ "213.180.193.250": "Yandex - Infected",
+ "93.158.134.250": "Yandex - Adult",
+ }
+
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
self.results = self.tempStorage()
@@ -55,73 +63,67 @@ class sfp_yandexdns(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 ["INTERNET_NAME", "AFFILIATE_INTERNET_NAME", "CO_HOSTED_SITE"]
+ return [
+ "INTERNET_NAME",
+ "AFFILIATE_INTERNET_NAME",
+ "CO_HOSTED_SITE"
+ ]
- # What events this module produces
- # This is to support the end user in selecting modules based on events
- # produced.
def producedEvents(self):
- return ["MALICIOUS_INTERNET_NAME", "MALICIOUS_AFFILIATE_INTERNET_NAME",
- "MALICIOUS_COHOST"]
+ return [
+ "MALICIOUS_INTERNET_NAME",
+ "MALICIOUS_AFFILIATE_INTERNET_NAME",
+ "MALICIOUS_COHOST"
+ ]
- # Query Yandex DNS "safe" servers
- # https://dns.yandex.com/advanced/
+ # Query Yandex DNS "family" servers
def queryAddr(self, qaddr):
+ if not qaddr:
+ return None
+
res = dns.resolver.Resolver()
- res.nameservers = ["77.88.8.88", "77.88.8.2"]
+ res.nameservers = ["77.88.8.7", "77.88.8.3"]
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
# Handle events sent to this module
def handleEvent(self, event):
eventName = event.eventType
- srcModuleName = event.module
eventData = event.data
- parentEvent = event
- resolved = False
- 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
- # Check that it resolves first, as it becomes a valid
- # malicious host only if NOT resolved by Yandex.
- try:
- if self.sf.resolveHost(eventData) or self.sf.resolveHost6(eventData):
- resolved = True
- except Exception:
- self.debug(f"Unable to resolve {eventData}")
- return
-
- if not resolved:
- 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)
- if found:
+ if not res:
return
- if eventName == "CO_HOSTED_SITE":
- typ = "MALICIOUS_COHOST"
- else:
- typ = "MALICIOUS_" + eventName
+ self.debug(f"{eventData} found in Yandex Blocklist: {res}")
- evt = SpiderFootEvent(typ, "Blocked by Yandex [" + eventData + "]",
- self.__name__, parentEvent)
- 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_yandexdns class
diff --git a/test/unit/modules/test_sfp_yandexdns.py b/test/unit/modules/test_sfp_yandexdns.py
index ffaa2341..7ce8377f 100644
--- a/test/unit/modules/test_sfp_yandexdns.py
+++ b/test/unit/modules/test_sfp_yandexdns.py
@@ -34,10 +34,7 @@ class TestModuleyandexdns(unittest.TestCase):
module = sfp_yandexdns()
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_yandexdns()
@@ -48,29 +45,65 @@ class TestModuleyandexdns(unittest.TestCase):
target = SpiderFootTarget(target_value, target_type)
module.setTarget(target)
- resolved = module.queryAddr('yandex.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_yandexdns)
+
+ 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 = 'yandex.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_yandexdns()
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 = 'Yandex - Adult [pornhub.com]'
+ if str(event.data) != expected:
+ raise Exception(f"{event.data} != {expected}")
+
+ raise Exception("OK")
+
+ module.notifyListeners = new_notifyListeners.__get__(module, sfp_yandexdns)
+
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))