Skip to content

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

New modules to use DNS reputation systems.

Steve Micallefcab1e04d0a99
diff --git a/modules/sfp_cinsscore.py b/modules/sfp_cinsscore.py
new file mode 100644
index 00000000..31550003
--- /dev/null
+++ b/modules/sfp_cinsscore.py
@@ -0,0 +1,268 @@
+# -*- coding: utf-8 -*-
+# -------------------------------------------------------------------------------
+# Name: sfp_cinsscore
+# Purpose: Checks if an IP is malicious according to the CINS Army List.
+#
+#
+# Created: 30/05/2018
+# Copyright: (c) Steve Micallef, 2018
+# Licence: GPL
+# -------------------------------------------------------------------------------
+
+from netaddr import IPAddress, IPNetwork
+import re
+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
+
+malchecks = {
+ 'cinsscore.com List': {
+ 'id': '_cinsscore',
+ 'type': 'list',
+ 'checks': ['ip'],
+ 'url': 'http://cinsscore.com/list/ci-badguys.txt'
+ }
+}
+
+
+class sfp_cinsscore(SpiderFootPlugin):
+ """CINS Army List:Investigate,Passive:Reputation Systems::Check if a netblock or IP is malicious according to cinsscore.com's Army List."""
+
+
+ # Default options
+ opts = {
+ '_cinsscore': True,
+ 'checkaffiliates': True,
+ 'cacheperiod': 18,
+ 'checknetblocks': True,
+ 'checksubnets': True
+ }
+
+ # Option descriptions
+ optdescs = {
+ 'checkaffiliates': "Apply checks to affiliates?",
+ 'cacheperiod': "Hours to cache list data before re-fetching.",
+ 'checknetblocks': "Report if any malicious IPs are found within owned netblocks?",
+ 'checksubnets': "Check if any malicious IPs are found within the same subnet of the target?"
+ }
+
+ # Be sure to completely clear any class variables in setup()
+ # or you run the risk of data persisting between scan runs.
+
+ results = list()
+
+ def setup(self, sfc, userOpts=dict()):
+ self.sf = sfc
+ self.results = list()
+
+ # Clear / reset any other class member variables here
+ # or you risk them persisting between threads.
+
+ for opt in userOpts.keys():
+ self.opts[opt] = userOpts[opt]
+
+ # What events is this module interested in for input
+ # * = be notified about all events.
+ def watchedEvents(self):
+ return ["IP_ADDRESS", "NETBLOCK_MEMBER", "AFFILIATE_IPADDR",
+ "NETBLOCK_OWNER"]
+
+ # What events this module produces
+ # This is to support the end user in selecting modules based on events
+ # produced.
+ def producedEvents(self):
+ return ["MALICIOUS_IPADDR", "MALICIOUS_AFFILIATE_IPADDR",
+ "MALICIOUS_SUBNET", "MALICIOUS_NETBLOCK"]
+
+ # Check the regexps to see whether the content indicates maliciousness
+ def contentMalicious(self, content, goodregex, badregex):
+ # First, check for the bad indicators
+ if len(badregex) > 0:
+ for rx in badregex:
+ if re.match(rx, content, re.IGNORECASE | re.DOTALL):
+ self.sf.debug("Found to be bad against bad regex: " + rx)
+ return True
+
+ # Finally, check for good indicators
+ if len(goodregex) > 0:
+ for rx in goodregex:
+ if re.match(rx, content, re.IGNORECASE | re.DOTALL):
+ self.sf.debug("Found to be good againt good regex: " + rx)
+ return False
+
+ # If nothing was matched, reply None
+ self.sf.debug("Neither good nor bad, unknown.")
+ return None
+
+ # Look up 'query' type sources
+ def resourceQuery(self, id, target, targetType):
+ self.sf.debug("Querying " + id + " for maliciousness of " + target)
+ for check in malchecks.keys():
+ cid = malchecks[check]['id']
+ if id == cid and malchecks[check]['type'] == "query":
+ url = unicode(malchecks[check]['url'])
+ res = self.sf.fetchUrl(url.format(target), timeout=self.opts['_fetchtimeout'], useragent=self.opts['_useragent'])
+ if res['content'] is None:
+ self.sf.error("Unable to fetch " + url.format(target), False)
+ return None
+ if self.contentMalicious(res['content'],
+ malchecks[check]['goodregex'],
+ malchecks[check]['badregex']):
+ return url.format(target)
+
+ return None
+
+ # Look up 'list' type resources
+ def resourceList(self, id, target, targetType):
+ targetDom = ''
+ # Get the base domain if we're supplied a domain
+ if targetType == "domain":
+ targetDom = self.sf.hostDomain(target, self.opts['_internettlds'])
+
+ for check in malchecks.keys():
+ cid = malchecks[check]['id']
+ if id == cid and malchecks[check]['type'] == "list":
+ data = dict()
+ url = malchecks[check]['url']
+ data['content'] = self.sf.cacheGet("sfmal_" + cid, self.opts.get('cacheperiod', 0))
+ if data['content'] is None:
+ data = self.sf.fetchUrl(url, timeout=self.opts['_fetchtimeout'], useragent=self.opts['_useragent'])
+ if data['content'] is None:
+ self.sf.error("Unable to fetch " + url, False)
+ return None
+ else:
+ self.sf.cachePut("sfmal_" + cid, data['content'])
+
+ # If we're looking at netblocks
+ if targetType == "netblock":
+ iplist = list()
+ # Get the regex, replace {0} with an IP address matcher to
+ # build a list of IP.
+ # Cycle through each IP and check if it's in the netblock.
+ if 'regex' in malchecks[check]:
+ rx = malchecks[check]['regex'].replace("{0}",
+ "(\d+\.\d+\.\d+\.\d+)")
+ pat = re.compile(rx, re.IGNORECASE)
+ self.sf.debug("New regex for " + check + ": " + rx)
+ for line in data['content'].split('\n'):
+ grp = re.findall(pat, line)
+ if len(grp) > 0:
+ #self.sf.debug("Adding " + grp[0] + " to list.")
+ iplist.append(grp[0])
+ else:
+ iplist = data['content'].split('\n')
+
+ for ip in iplist:
+ if len(ip) < 8 or ip.startswith("#"):
+ continue
+ ip = ip.strip()
+
+ try:
+ if IPAddress(ip) in IPNetwork(target):
+ self.sf.debug(ip + " found within netblock/subnet " +
+ target + " in " + check)
+ return url
+ except Exception as e:
+ self.sf.debug("Error encountered parsing: " + str(e))
+ continue
+
+ return None
+
+ # If we're looking at hostnames/domains/IPs
+ if 'regex' not in malchecks[check]:
+ for line in data['content'].split('\n'):
+ if line == target or (targetType == "domain" and line == targetDom):
+ self.sf.debug(target + "/" + targetDom + " found in " + check + " list.")
+ return url
+ else:
+ # Check for the domain and the hostname
+ rxDom = unicode(malchecks[check]['regex']).format(targetDom.decode('string_escape'))
+ rxTgt = unicode(malchecks[check]['regex']).format(target.decode('string_escape'))
+ for line in data['content'].split('\n'):
+ if (targetType == "domain" and re.match(rxDom, line, re.IGNORECASE)) or \
+ re.match(rxTgt, line, re.IGNORECASE):
+ self.sf.debug(target + "/" + targetDom + " found in " + check + " list.")
+ return url
+ return None
+
+ def lookupItem(self, resourceId, itemType, target):
+ for check in malchecks.keys():
+ cid = malchecks[check]['id']
+ if cid == resourceId and itemType in malchecks[check]['checks']:
+ self.sf.debug("Checking maliciousness of " + target + " (" +
+ itemType + ") with: " + cid)
+ if malchecks[check]['type'] == "query":
+ return self.resourceQuery(cid, target, itemType)
+ if malchecks[check]['type'] == "list":
+ return self.resourceList(cid, target, itemType)
+
+ return None
+
+ # Handle events sent to this module
+ def handleEvent(self, event):
+ eventName = event.eventType
+ srcModuleName = event.module
+ eventData = event.data
+
+ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
+
+ if eventData in self.results:
+ self.sf.debug("Skipping " + eventData + ", already checked.")
+ return None
+ else:
+ self.results.append(eventData)
+
+ if eventName == 'CO_HOSTED_SITE' and not self.opts.get('checkcohosts', False):
+ return None
+ if eventName == 'AFFILIATE_IPADDR' \
+ and not self.opts.get('checkaffiliates', False):
+ return None
+ if eventName == 'NETBLOCK_OWNER' and not self.opts.get('checknetblocks', False):
+ return None
+ if eventName == 'NETBLOCK_MEMBER' and not self.opts.get('checksubnets', False):
+ return None
+
+ for check in malchecks.keys():
+ cid = malchecks[check]['id']
+ # If the module is enabled..
+ if self.opts[cid]:
+ if eventName in ['IP_ADDRESS', 'AFFILIATE_IPADDR']:
+ typeId = 'ip'
+ if eventName == 'IP_ADDRESS':
+ evtType = 'MALICIOUS_IPADDR'
+ else:
+ evtType = 'MALICIOUS_AFFILIATE_IPADDR'
+
+ if eventName in ['BGP_AS_OWNER', 'BGP_AS_MEMBER']:
+ typeId = 'asn'
+ evtType = 'MALICIOUS_ASN'
+
+ if eventName in ['INTERNET_NAME', 'CO_HOSTED_SITE',
+ 'AFFILIATE_INTERNET_NAME', ]:
+ typeId = 'domain'
+ if eventName == "INTERNET_NAME":
+ evtType = "MALICIOUS_INTERNET_NAME"
+ if eventName == 'AFFILIATE_INTERNET_NAME':
+ evtType = 'MALICIOUS_AFFILIATE_INTERNET_NAME'
+ if eventName == 'CO_HOSTED_SITE':
+ evtType = 'MALICIOUS_COHOST'
+
+ if eventName == 'NETBLOCK_OWNER':
+ typeId = 'netblock'
+ evtType = 'MALICIOUS_NETBLOCK'
+ if eventName == 'NETBLOCK_MEMBER':
+ typeId = 'netblock'
+ evtType = 'MALICIOUS_SUBNET'
+
+ url = self.lookupItem(cid, typeId, eventData)
+ if self.checkForStop():
+ return None
+
+ # Notify other modules of what you've found
+ if url is not None:
+ text = check + " [" + eventData + "]\n" + "<SFURL>" + url + "</SFURL>"
+ evt = SpiderFootEvent(evtType, text, self.__name__, event)
+ self.notifyListeners(evt)
+
+ return None
+
+# End of sfp_cinsscore class
diff --git a/modules/sfp_cleanbrowsing.py b/modules/sfp_cleanbrowsing.py
new file mode 100644
index 00000000..0e7da6ca
--- /dev/null
+++ b/modules/sfp_cleanbrowsing.py
@@ -0,0 +1,98 @@
+# -*- coding: utf-8 -*-
+# -------------------------------------------------------------------------------
+# Name: sfp_cleanbrowsing
+# Purpose: SpiderFoot plug-in for looking up whether hosts are blocked by
+# Cleanbrowsing.org DNS (185.228.168.168 and 185.228.168.169)
+#
+# Author: Steve Micallef <[email protected]>
+#
+# Created: 30/05/2018
+# Copyright: (c) Steve Micallef 2018
+# Licence: GPL
+# -------------------------------------------------------------------------------
+
+import socket
+import dns.resolver
+from netaddr import IPNetwork
+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
+
+
+class sfp_cleanbrowsing(SpiderFootPlugin):
+ """Cleanbrowsing.org:Investigate,Passive:Reputation Systems::Check if a host would be blocked by Cleanbrowsing.org DNS"""
+
+ # Default options
+ opts = {
+ }
+
+ # Option descriptions
+ optdescs = {
+ }
+
+ results = dict()
+
+ def setup(self, sfc, userOpts=dict()):
+ self.sf = sfc
+ self.results = dict()
+
+ for opt in 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"]
+
+ # 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"]
+
+ def queryAddr(self, qaddr):
+ res = dns.resolver.Resolver()
+ res.nameservers = [ "185.228.168.168", "185.228.168.169" ]
+
+ try:
+ addrs = res.query(qaddr)
+ self.sf.debug("Addresses returned: " + str(addrs))
+ except BaseException as e:
+ self.sf.debug("Unable to resolve " + qaddr)
+ return False
+
+ if addrs:
+ return True
+ return False
+
+ # Handle events sent to this module
+ def handleEvent(self, event):
+ eventName = event.eventType
+ srcModuleName = event.module
+ eventData = event.data
+ parentEvent = event
+ resolved = False
+
+ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
+
+ if eventData in self.results:
+ return None
+ self.results[eventData] = True
+
+ # Check that it resolves first, as it becomes a valid
+ # malicious host only if NOT resolved by Cleanbrowsing.org.
+ try:
+ if self.sf.normalizeDNS(socket.gethostbyname_ex(eventData)):
+ resolved = True
+ except BaseException as e:
+ return None
+
+ if resolved:
+ found = self.queryAddr(eventData)
+ typ = "MALICIOUS_" + eventName
+ if eventName == "CO_HOSTED_SITE":
+ typ = "MALICIOUS_COHOST"
+ if not found:
+ evt = SpiderFootEvent(typ, "Blocked by Cleanbrowsing.org [" + eventData + "]",
+ self.__name__, parentEvent)
+ self.notifyListeners(evt)
+
+# End of sfp_cleanbrowsing class
diff --git a/modules/sfp_comodo.py b/modules/sfp_comodo.py
new file mode 100644
index 00000000..e2769ca8
--- /dev/null
+++ b/modules/sfp_comodo.py
@@ -0,0 +1,98 @@
+# -*- coding: utf-8 -*-
+# -------------------------------------------------------------------------------
+# Name: sfp_comodo
+# Purpose: SpiderFoot plug-in for looking up whether hosts are blocked by
+# Comodo DNS (8.26.56.26 and 8.20.247.20)
+#
+# Author: Steve Micallef <[email protected]>
+#
+# Created: 30/05/2018
+# Copyright: (c) Steve Micallef 2018
+# Licence: GPL
+# -------------------------------------------------------------------------------
+
+import socket
+import dns.resolver
+from netaddr import IPNetwork
+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
+
+
+class sfp_comodo(SpiderFootPlugin):
+ """Comodo:Investigate,Passive:Reputation Systems::Check if a host would be blocked by Comodo DNS"""
+
+ # Default options
+ opts = {
+ }
+
+ # Option descriptions
+ optdescs = {
+ }
+
+ results = dict()
+
+ def setup(self, sfc, userOpts=dict()):
+ self.sf = sfc
+ self.results = dict()
+
+ for opt in 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"]
+
+ # 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"]
+
+ def queryAddr(self, qaddr):
+ res = dns.resolver.Resolver()
+ res.nameservers = [ "8.26.56.26", "8.20.247.20" ]
+
+ try:
+ addrs = res.query(qaddr)
+ self.sf.debug("Addresses returned: " + str(addrs))
+ except BaseException as e:
+ self.sf.debug("Unable to resolve " + qaddr)
+ return False
+
+ if addrs:
+ return True
+ return False
+
+ # Handle events sent to this module
+ def handleEvent(self, event):
+ eventName = event.eventType
+ srcModuleName = event.module
+ eventData = event.data
+ parentEvent = event
+ resolved = False
+
+ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
+
+ if eventData in self.results:
+ return None
+ self.results[eventData] = True
+
+ # Check that it resolves first, as it becomes a valid
+ # malicious host only if NOT resolved by Comodo.
+ try:
+ if self.sf.normalizeDNS(socket.gethostbyname_ex(eventData)):
+ resolved = True
+ except BaseException as e:
+ return None
+
+ if resolved:
+ found = self.queryAddr(eventData)
+ typ = "MALICIOUS_" + eventName
+ if eventName == "CO_HOSTED_SITE":
+ typ = "MALICIOUS_COHOST"
+ if not found:
+ evt = SpiderFootEvent(typ, "Blocked by Comodo DNS [" + eventData + "]",
+ self.__name__, parentEvent)
+ self.notifyListeners(evt)
+
+# End of sfp_comodo class
diff --git a/modules/sfp_norton.py b/modules/sfp_norton.py
new file mode 100644
index 00000000..ef6f29b9
--- /dev/null
+++ b/modules/sfp_norton.py
@@ -0,0 +1,98 @@
+# -*- coding: utf-8 -*-
+# -------------------------------------------------------------------------------
+# Name: sfp_norton
+# Purpose: SpiderFoot plug-in for looking up whether hosts are blocked by
+# Norton DNS (199.85.126.20 and 199.85.127.20)
+#
+# Author: Steve Micallef <[email protected]>
+#
+# Created: 30/05/2018
+# Copyright: (c) Steve Micallef 2018
+# Licence: GPL
+# -------------------------------------------------------------------------------
+
+import socket
+import dns.resolver
+from netaddr import IPNetwork
+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
+
+
+class sfp_norton(SpiderFootPlugin):
+ """Norton ConnectSafe:Investigate,Passive:Reputation Systems::Check if a host would be blocked by Norton ConnectSafe DNS"""
+
+ # Default options
+ opts = {
+ }
+
+ # Option descriptions
+ optdescs = {
+ }
+
+ results = dict()
+
+ def setup(self, sfc, userOpts=dict()):
+ self.sf = sfc
+ self.results = dict()
+
+ for opt in 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"]
+
+ # 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"]
+
+ def queryAddr(self, qaddr):
+ res = dns.resolver.Resolver()
+ res.nameservers = [ "199.85.126.20", "199.85.127.20" ]
+
+ try:
+ addrs = res.query(qaddr)
+ self.sf.debug("Addresses returned: " + str(addrs))
+ except BaseException as e:
+ self.sf.debug("Unable to resolve " + qaddr)
+ return False
+
+ if addrs:
+ return True
+ return False
+
+ # Handle events sent to this module
+ def handleEvent(self, event):
+ eventName = event.eventType
+ srcModuleName = event.module
+ eventData = event.data
+ parentEvent = event
+ resolved = False
+
+ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
+
+ if eventData in self.results:
+ return None
+ self.results[eventData] = True
+
+ # Check that it resolves first, as it becomes a valid
+ # malicious host only if NOT resolved by Norton.
+ try:
+ if self.sf.normalizeDNS(socket.gethostbyname_ex(eventData)):
+ resolved = True
+ except BaseException as e:
+ return None
+
+ if resolved:
+ found = self.queryAddr(eventData)
+ typ = "MALICIOUS_" + eventName
+ if eventName == "CO_HOSTED_SITE":
+ typ = "MALICIOUS_COHOST"
+ if not found:
+ evt = SpiderFootEvent(typ, "Blocked by Norton ConnectSafe [" + eventData + "]",
+ self.__name__, parentEvent)
+ self.notifyListeners(evt)
+
+# End of sfp_norton class
diff --git a/modules/sfp_opendns.py b/modules/sfp_opendns.py
new file mode 100644
index 00000000..830b980e
--- /dev/null
+++ b/modules/sfp_opendns.py
@@ -0,0 +1,98 @@
+# -*- coding: utf-8 -*-
+# -------------------------------------------------------------------------------
+# Name: sfp_opendns
+# Purpose: SpiderFoot plug-in for looking up whether hosts are blocked by
+# OpenDNS DNS (208.67.222.222 and 208.67.220.220)
+#
+# Author: Steve Micallef <[email protected]>
+#
+# Created: 30/05/2018
+# Copyright: (c) Steve Micallef 2018
+# Licence: GPL
+# -------------------------------------------------------------------------------
+
+import socket
+import dns.resolver
+from netaddr import IPNetwork
+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
+
+
+class sfp_opendns(SpiderFootPlugin):
+ """OpenDNS:Investigate,Passive:Reputation Systems::Check if a host would be blocked by OpenDNS DNS"""
+
+ # Default options
+ opts = {
+ }
+
+ # Option descriptions
+ optdescs = {
+ }
+
+ results = dict()
+
+ def setup(self, sfc, userOpts=dict()):
+ self.sf = sfc
+ self.results = dict()
+
+ for opt in 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"]
+
+ # 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"]
+
+ def queryAddr(self, qaddr):
+ res = dns.resolver.Resolver()
+ res.nameservers = [ "208.67.222.222", "208.67.220.220" ]
+
+ try:
+ addrs = res.query(qaddr)
+ self.sf.debug("Addresses returned: " + str(addrs))
+ except BaseException as e:
+ self.sf.debug("Unable to resolve " + qaddr)
+ return False
+
+ if addrs:
+ return True
+ return False
+
+ # Handle events sent to this module
+ def handleEvent(self, event):
+ eventName = event.eventType
+ srcModuleName = event.module
+ eventData = event.data
+ parentEvent = event
+ resolved = False
+
+ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
+
+ if eventData in self.results:
+ return None
+ self.results[eventData] = True
+
+ # Check that it resolves first, as it becomes a valid
+ # malicious host only if NOT resolved by OpenDNS.
+ try:
+ if self.sf.normalizeDNS(socket.gethostbyname_ex(eventData)):
+ resolved = True
+ except BaseException as e:
+ return None
+
+ if resolved:
+ found = self.queryAddr(eventData)
+ typ = "MALICIOUS_" + eventName
+ if eventName == "CO_HOSTED_SITE":
+ typ = "MALICIOUS_COHOST"
+ if not found:
+ evt = SpiderFootEvent(typ, "Blocked by OpenDNS [" + eventData + "]",
+ self.__name__, parentEvent)
+ self.notifyListeners(evt)
+
+# End of sfp_opendns class
diff --git a/modules/sfp_yandex.py b/modules/sfp_yandex.py
new file mode 100644
index 00000000..4ea39025
--- /dev/null
+++ b/modules/sfp_yandex.py
@@ -0,0 +1,98 @@
+# -*- coding: utf-8 -*-
+# -------------------------------------------------------------------------------
+# Name: sfp_yandex
+# Purpose: SpiderFoot plug-in for looking up whether hosts are blocked by
+# Yandex DNS (77.88.8.88 and 77.88.8.2)
+#
+# Author: Steve Micallef <[email protected]>
+#
+# Created: 30/05/2018
+# Copyright: (c) Steve Micallef 2018
+# Licence: GPL
+# -------------------------------------------------------------------------------
+
+import socket
+import dns.resolver
+from netaddr import IPNetwork
+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
+
+
+class sfp_yandex(SpiderFootPlugin):
+ """Yandex:Investigate,Passive:Reputation Systems::Check if a host would be blocked by Yandex DNS"""
+
+ # Default options
+ opts = {
+ }
+
+ # Option descriptions
+ optdescs = {
+ }
+
+ results = dict()
+
+ def setup(self, sfc, userOpts=dict()):
+ self.sf = sfc
+ self.results = dict()
+
+ for opt in 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"]
+
+ # 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"]
+
+ def queryAddr(self, qaddr):
+ res = dns.resolver.Resolver()
+ res.nameservers = [ "77.88.8.88", "77.88.8.2" ]
+
+ try:
+ addrs = res.query(qaddr)
+ self.sf.debug("Addresses returned: " + str(addrs))
+ except BaseException as e:
+ self.sf.debug("Unable to resolve " + qaddr)
+ return False
+
+ if addrs:
+ return True
+ return False
+
+ # Handle events sent to this module
+ def handleEvent(self, event):
+ eventName = event.eventType
+ srcModuleName = event.module
+ eventData = event.data
+ parentEvent = event
+ resolved = False
+
+ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
+
+ if eventData in self.results:
+ return None
+ 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.normalizeDNS(socket.gethostbyname_ex(eventData)):
+ resolved = True
+ except BaseException as e:
+ return None
+
+ if resolved:
+ found = self.queryAddr(eventData)
+ typ = "MALICIOUS_" + eventName
+ if eventName == "CO_HOSTED_SITE":
+ typ = "MALICIOUS_COHOST"
+ if not found:
+ evt = SpiderFootEvent(typ, "Blocked by Yandex [" + eventData + "]",
+ self.__name__, parentEvent)
+ self.notifyListeners(evt)
+
+# End of sfp_yandex class