Skip to content

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

modules: remove unused malchecks code

Brendan Coles4710f0119f85
diff --git a/modules/sfp_fortinet.py b/modules/sfp_fortinet.py
index a7de6263..dc708f2e 100644
--- a/modules/sfp_fortinet.py
+++ b/modules/sfp_fortinet.py
@@ -10,7 +10,6 @@
# Licence: GPL
# -------------------------------------------------------------------------------
-from netaddr import IPAddress, IPNetwork
import re
from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
@@ -18,7 +17,6 @@ from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
malchecks = {
'Fortiguard Threat Lookup': {
'id': '_fortiguard',
- 'type': 'query',
'checks': [ 'ip' ],
'url': 'https://fortiguard.com/search?q={0}&engine=8',
'badregex': ['.*Your signature is blacklisted.*'],
@@ -113,99 +111,20 @@ class sfp_fortinet(SpiderFootPlugin):
# Look up 'query' type sources
def resourceQuery(self, id, target, targetType):
- self.sf.debug("Querying " + id + " for maliciousness of " + target)
+ self.sf.debug(f"Querying {id} for maliciousness of {target}")
+
for check in list(malchecks.keys()):
cid = malchecks[check]['id']
- if id == cid and malchecks[check]['type'] == "query":
+ if id == cid:
url = str(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'])
- if not targetDom:
- return None
- for check in list(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
- try:
- rxDom = str(malchecks[check]['regex']).format(targetDom)
- rxTgt = str(malchecks[check]['regex']).format(target)
- 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
- except BaseException as e:
- self.sf.debug("Error encountered parsing 2: " + str(e))
- continue
+ if self.contentMalicious(res['content'], malchecks[check]['goodregex'], malchecks[check]['badregex']):
+ return url.format(target)
return None
@@ -213,12 +132,8 @@ class sfp_fortinet(SpiderFootPlugin):
for check in list(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)
+ self.sf.debug(f"Checking maliciousness of {target} ({itemType}) with: {cid}")
+ return self.resourceQuery(cid, target, itemType)
return None
@@ -233,8 +148,8 @@ class sfp_fortinet(SpiderFootPlugin):
if eventData in self.results:
self.sf.debug("Skipping " + eventData + ", already checked.")
return None
- else:
- self.results[eventData] = True
+
+ self.results[eventData] = True
if eventName == 'CO_HOSTED_SITE' and not self.opts.get('checkcohosts', False):
return None
diff --git a/modules/sfp_isc.py b/modules/sfp_isc.py
index dbfd315f..630ec999 100644
--- a/modules/sfp_isc.py
+++ b/modules/sfp_isc.py
@@ -10,7 +10,6 @@
# Licence: GPL
# -------------------------------------------------------------------------------
-from netaddr import IPAddress, IPNetwork
import re
from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
@@ -18,7 +17,6 @@ from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
malchecks = {
'Internet Storm Center': {
'id': '_isc',
- 'type': 'query',
'checks': ['ip'],
'url': 'https://isc.sans.edu/api/ip/{0}',
'badregex': ['.*<attacks>\d+</attacks>.*'],
@@ -119,99 +117,20 @@ class sfp_isc(SpiderFootPlugin):
# Look up 'query' type sources
def resourceQuery(self, id, target, targetType):
- self.sf.debug("Querying " + id + " for maliciousness of " + target)
+ self.sf.debug(f"Querying {id} for maliciousness of {target}")
+
for check in list(malchecks.keys()):
cid = malchecks[check]['id']
- if id == cid and malchecks[check]['type'] == "query":
+ if id == cid:
url = str(malchecks[check]['url'])
res = self.sf.fetchUrl(url.format(target), timeout=30, 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'])
- if not targetDom:
- return None
- for check in list(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=30, 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
- try:
- rxDom = str(malchecks[check]['regex']).format(targetDom)
- rxTgt = str(malchecks[check]['regex']).format(target)
- 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
- except BaseException as e:
- self.sf.debug("Error encountered parsing 2: " + str(e))
- continue
+ if self.contentMalicious(res['content'], malchecks[check]['goodregex'], malchecks[check]['badregex']):
+ return url.format(target)
return None
@@ -219,12 +138,8 @@ class sfp_isc(SpiderFootPlugin):
for check in list(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)
+ self.sf.debug(f"Checking maliciousness of {target} ({itemType}) with: {cid}")
+ return self.resourceQuery(cid, target, itemType)
return None
@@ -239,8 +154,8 @@ class sfp_isc(SpiderFootPlugin):
if eventData in self.results:
self.sf.debug("Skipping " + eventData + ", already checked.")
return None
- else:
- self.results[eventData] = True
+
+ self.results[eventData] = True
if eventName == 'CO_HOSTED_SITE' and not self.opts.get('checkcohosts', False):
return None
diff --git a/modules/sfp_totalhash.py b/modules/sfp_totalhash.py
index a0ae3e6b..5ac368ab 100644
--- a/modules/sfp_totalhash.py
+++ b/modules/sfp_totalhash.py
@@ -10,7 +10,6 @@
# Licence: GPL
# -------------------------------------------------------------------------------
-from netaddr import IPAddress, IPNetwork
import re
from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
@@ -18,7 +17,6 @@ from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
malchecks = {
'TotalHash.com Database': {
'id': '_totalhash',
- 'type': 'query',
'checks': ['ip', 'domain'],
'url': 'https://totalhash.cymru.com/search/?dnsrr:*{0}%20or%20ip:{0}',
'badregex': ['.*<a href=\"/analysis.*'],
@@ -116,99 +114,20 @@ class sfp_totalhash(SpiderFootPlugin):
# Look up 'query' type sources
def resourceQuery(self, id, target, targetType):
- self.sf.debug("Querying " + id + " for maliciousness of " + target)
+ self.sf.debug(f"Querying {id} for maliciousness of {target}")
+
for check in list(malchecks.keys()):
cid = malchecks[check]['id']
- if id == cid and malchecks[check]['type'] == "query":
+ if id == cid:
url = str(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'])
- if not targetDom:
- return None
- for check in list(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
- try:
- rxDom = str(malchecks[check]['regex']).format(targetDom)
- rxTgt = str(malchecks[check]['regex']).format(target)
- 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
- except BaseException as e:
- self.sf.debug("Error encountered parsing 2: " + str(e))
- continue
+ if self.contentMalicious(res['content'], malchecks[check]['goodregex'], malchecks[check]['badregex']):
+ return url.format(target)
return None
@@ -216,12 +135,8 @@ class sfp_totalhash(SpiderFootPlugin):
for check in list(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)
+ self.sf.debug(f"Checking maliciousness of {target} ({itemType}) with: {cid}")
+ return self.resourceQuery(cid, target, itemType)
return None
@@ -236,8 +151,8 @@ class sfp_totalhash(SpiderFootPlugin):
if eventData in self.results:
self.sf.debug("Skipping " + eventData + ", already checked.")
return None
- else:
- self.results[eventData] = True
+
+ self.results[eventData] = True
if eventName == 'CO_HOSTED_SITE' and not self.opts.get('checkcohosts', False):
return None
diff --git a/modules/sfp_watchguard.py b/modules/sfp_watchguard.py
index a2682837..5a6d59f9 100644
--- a/modules/sfp_watchguard.py
+++ b/modules/sfp_watchguard.py
@@ -11,14 +11,12 @@
# -------------------------------------------------------------------------------
import re
-from netaddr import IPAddress, IPNetwork
from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
malchecks = {
'Watchguard Reputation Authority Lookup': {
'id': '_watchguard',
- 'type': 'query',
'checks': [ 'ip' ],
'url': 'http://reputationauthority.org/lookup?ip={0}',
'badregex': ['.*>[6-9][0-9]/100 </td>.*', '.*>100/100 </td>.*'],
@@ -108,99 +106,20 @@ class sfp_watchguard(SpiderFootPlugin):
# Look up 'query' type sources
def resourceQuery(self, id, target, targetType):
- self.sf.debug("Querying " + id + " for maliciousness of " + target)
+ self.sf.debug(f"Querying {id} for maliciousness of {target}")
+
for check in list(malchecks.keys()):
cid = malchecks[check]['id']
- if id == cid and malchecks[check]['type'] == "query":
+ if id == cid:
url = str(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'])
- if not targetDom:
- return None
- for check in list(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
- try:
- rxDom = str(malchecks[check]['regex']).format(targetDom)
- rxTgt = str(malchecks[check]['regex']).format(target)
- 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
- except BaseException as e:
- self.sf.debug("Error encountered parsing 2: " + str(e))
- continue
+ if self.contentMalicious(res['content'], malchecks[check]['goodregex'], malchecks[check]['badregex']):
+ return url.format(target)
return None
@@ -208,12 +127,8 @@ class sfp_watchguard(SpiderFootPlugin):
for check in list(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)
+ self.sf.debug(f"Checking maliciousness of {target} ({itemType}) with: {cid}")
+ return self.resourceQuery(cid, target, itemType)
return None
@@ -228,8 +143,8 @@ class sfp_watchguard(SpiderFootPlugin):
if eventData in self.results:
self.sf.debug("Skipping " + eventData + ", already checked.")
return None
- else:
- self.results[eventData] = True
+
+ self.results[eventData] = True
if eventName == 'CO_HOSTED_SITE' and not self.opts.get('checkcohosts', False):
return None