Skip to content

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

Bug fixes, clean-up. Removed CryptoIOC module.

smicallefbac348d6e9ac
diff --git a/modules/sfp_cryptoioc.py b/modules/sfp_cryptoioc.py
deleted file mode 100644
index 022c0f56..00000000
--- a/modules/sfp_cryptoioc.py
+++ /dev/null
@@ -1,278 +0,0 @@
-# -*- coding: utf-8 -*-
-# -------------------------------------------------------------------------------
-# Name: sfp_cryptoioc
-# Purpose: Checks if an IP, hostname or domain is malicious.
-#
-#
-# Created: 07/09/2018
-# Copyright: (c) Steve Micallef, 2018
-# Licence: GPL
-# -------------------------------------------------------------------------------
-
-from netaddr import IPAddress, IPNetwork
-try:
- import re2 as re
-except ImportError as e:
- import re
-
-from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
-
-malchecks = {
- 'CryptoIOC': {
- 'id': 'cryptoioc',
- 'type': 'list',
- 'checks': ['ip', 'netblock'],
- 'url': 'https://cryptoioc.ch/downloads/csv',
- 'regex': '.*,\"{0}\",.*'
- }
-}
-
-class sfp_cryptoioc(SpiderFootPlugin):
- """CryptoIOC.ch:Investigate,Passive:Reputation Systems::Check if an IP is participating in malicious cryptocurrency mining."""
-
-
- # Default options
- opts = {
- 'cryptoioc': True,
- 'checkaffiliates': True,
- 'checkcohosts': True,
- 'cacheperiod': 18,
- 'checknetblocks': True,
- 'checksubnets': True
- }
-
- # Option descriptions
- optdescs = {
- 'cryptoioc': "Enable Bambenek IP check?",
- 'checkaffiliates': "Apply checks to affiliates?",
- 'checkcohosts': "Apply checks to sites found to be co-hosted on the target's IP?",
- '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 = None
-
- def setup(self, sfc, userOpts=dict()):
- self.sf = sfc
- self.results = self.tempStorage()
-
- # 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 ["INTERNET_NAME", "IP_ADDRESS",
- "NETBLOCK_MEMBER", "AFFILIATE_INTERNET_NAME", "AFFILIATE_IPADDR",
- "CO_HOSTED_SITE", "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_INTERNET_NAME",
- "MALICIOUS_AFFILIATE_IPADDR", "MALICIOUS_AFFILIATE_INTERNET_NAME",
- "MALICIOUS_SUBNET", "MALICIOUS_COHOST", "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
- try:
- rxDom = unicode(malchecks[check]['regex']).format(targetDom)
- rxTgt = unicode(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
-
- 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[eventData] = True
-
- 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 ['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_cryptoioc class
diff --git a/modules/sfp_digitaloceanspace.py b/modules/sfp_digitaloceanspace.py
index a2b60355..7c924718 100644
--- a/modules/sfp_digitaloceanspace.py
+++ b/modules/sfp_digitaloceanspace.py
@@ -164,8 +164,7 @@ class sfp_digitaloceanspace(SpiderFootPlugin):
evt = SpiderFootEvent("CLOUD_STORAGE_BUCKET", bucket[0] + ":" + bucket[1], self.__name__, event)
self.notifyListeners(evt)
if bucket[2] != "0":
- bucketname = bucket[1].replace("//", "")
- evt = SpiderFootEvent("CLOUD_STORAGE_BUCKET_OPEN", bucketname + ":" + bucket[1] + ": " + bucket[2] + " files found.",
+ evt = SpiderFootEvent("CLOUD_STORAGE_BUCKET_OPEN", bucket[0] + ":" + bucket[1] + ": " + bucket[2] + " files found.",
self.__name__, evt)
self.notifyListeners(evt)
diff --git a/modules/sfp_email.py b/modules/sfp_email.py
index 62aef254..b8d5a2e8 100644
--- a/modules/sfp_email.py
+++ b/modules/sfp_email.py
@@ -63,6 +63,7 @@ class sfp_email(SpiderFootPlugin):
myres = list()
for email in emails:
evttype = "EMAILADDR"
+ email = email.lower()
# Get the domain and strip potential ending .
mailDom = email.lower().split('@')[1].strip('.')
diff --git a/modules/sfp_emailformat.py b/modules/sfp_emailformat.py
index ff895d4b..c7dae576 100644
--- a/modules/sfp_emailformat.py
+++ b/modules/sfp_emailformat.py
@@ -79,6 +79,11 @@ class sfp_emailformat(SpiderFootPlugin):
self.sf.debug("Skipped address: " + email)
continue
+ # Skip masked emails
+ if re.match("^[0-9a-f]{8}\.[0-9]{7}@", email):
+ self.sf.debug("Skipped address: " + email)
+ continue
+
self.sf.info("Found e-mail address: " + email)
evt = SpiderFootEvent(evttype, email, self.__name__, event)
self.notifyListeners(evt)
diff --git a/modules/sfp_github.py b/modules/sfp_github.py
index 25397689..11088274 100644
--- a/modules/sfp_github.py
+++ b/modules/sfp_github.py
@@ -17,7 +17,6 @@ from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
class sfp_github(SpiderFootPlugin):
"""Github:Footprint,Passive:Social Media::Identify associated public code repositories on Github."""
-
# Default options
opts = {
'namesonly': True
@@ -65,7 +64,6 @@ class sfp_github(SpiderFootPlugin):
return repo_info
-
def handleEvent(self, event):
eventName = event.eventType
srcModuleName = event.module
@@ -170,7 +168,7 @@ class sfp_github(SpiderFootPlugin):
for item in ret['items']:
repo_info = self.buildRepoInfo(item)
if repo_info != None:
- if self.opts['namesonly'] and name not in item['name']:
+ if self.opts['namesonly'] and name != item['name']:
continue
evt = SpiderFootEvent("PUBLIC_CODE_REPO", repo_info,
@@ -237,7 +235,9 @@ class sfp_github(SpiderFootPlugin):
repo_info = self.buildRepoInfo(item)
if repo_info != None:
- if self.opts['namesonly'] and name not in item['name']:
+ if self.opts['namesonly'] and item['name'] != name:
+ continue
+ if eventName == "USERNAME" and "/" + name + "/" not in item.get('html_url', ''):
continue
evt = SpiderFootEvent("PUBLIC_CODE_REPO", repo_info,
diff --git a/modules/sfp_names.py b/modules/sfp_names.py
index d42f6ff8..f44d2344 100644
--- a/modules/sfp_names.py
+++ b/modules/sfp_names.py
@@ -17,7 +17,6 @@ except ImportError as e:
from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
-
class sfp_names(SpiderFootPlugin):
"""Name Extractor:Footprint,Passive:Real World:errorprone:Attempt to identify human names in fetched content."""
@@ -84,6 +83,11 @@ class sfp_names(SpiderFootPlugin):
else:
name = " ".join(map(str.capitalize, eventData.split("@")[0].split(".")))
name = unicode(name, 'utf-8', errors='replace')
+
+ # Names don't have numbers
+ if re.match("[0-9]", name):
+ return None
+
# Notify other modules of what you've found
evt = SpiderFootEvent("HUMAN_NAME", name, self.__name__, event)
if event.moduleDataSource:
diff --git a/modules/sfp_spider.py b/modules/sfp_spider.py
index aab9418b..fd2c0095 100644
--- a/modules/sfp_spider.py
+++ b/modules/sfp_spider.py
@@ -34,8 +34,7 @@ class sfp_spider(SpiderFootPlugin):
'filtermime': ['image/'],
'filterusers': True, # Don't follow /~user directories
'nosubs': False, # Should links to subdomains be ignored?
- 'reportduplicates': False,
- 'parsetext': True
+ 'reportduplicates': False
}
# Option descriptions
@@ -50,8 +49,7 @@ class sfp_spider(SpiderFootPlugin):
'filtermime': "MIME types to ignore.",
'filterusers': "Skip spidering of /~user directories?",
'nosubs': "Skip spidering of subdomains of the target?",
- 'reportduplicates': "Report links every time one is found, even if found before?",
- 'parsetext': "Parse content for possible hostnames/links, not just in valid HTML tags?"
+ 'reportduplicates': "Report links every time one is found, even if found before?"
}
# If using robots.txt, this will get populated with filter rules
@@ -120,8 +118,7 @@ class sfp_spider(SpiderFootPlugin):
# Extract links from the content
links = self.sf.parseLinks(url, fetched['content'],
- self.getTarget().getNames(),
- self.opts['parsetext'])
+ self.getTarget().getNames())
if links is None or len(links) == 0:
self.sf.info("No links found at " + url)
diff --git a/sflib.py b/sflib.py
index ad80c9ec..aae8fc5b 100644
--- a/sflib.py
+++ b/sflib.py
@@ -1174,7 +1174,7 @@ class SpiderFoot:
# The key will be the *absolute* URL of the link obtained, so for example if
# the link '/abc' was obtained from 'http://xyz.com', the key in the dict will
# be 'http://xyz.com/abc' with the 'original' attribute set to '/abc'
- def parseLinks(self, url, data, domains, parseText=True):
+ def parseLinks(self, url, data, domains):
returnLinks = dict()
urlsRel = []
@@ -1212,72 +1212,6 @@ class SpiderFoot:
self.error("Error parsing with BeautifulSoup: " + str(e), False)
return None
- # Find potential links that aren't links (text possibly in comments, etc.)
- parsedata = urllib2.unquote(data.lower())
-
- if parseText:
- # Find chunks of text encapsulating the data we care about
- offset = parsedata.find("http")
- regRelurl = re.compile('()(https?://.[a-zA-Z0-9\-\.\:\/_]+[^<\"\'])')
- while offset >= 0:
- offset = parsedata.find("http", offset)
- #print "found at offset: " + str(offset)
- if offset < 0:
- break
-
- # Get the trailing part for urls (some URLs are big..)
- chunkurl = parsedata[offset:(offset+2000)]
-
- try:
- m = regRelurl.findall(chunkurl)
- urlsRel.extend(regRelurl.findall(chunkurl))
- except Exception as e:
- self.error("Error applying regex3 to data (" + str(e) + ")", False)
- offset += len("http")
-
- # Internal links
- for domain in domains:
- if parseText:
- # Find chunks of text encapsulating the data we care about
- offset = parsedata.find(domain)
- if offset < 0:
- #print "skipping " + domain
- continue
-
- # If the text started with the domain, then start from after it
- if offset == 0:
- offset += len(domain)
-
- try:
- regRelhost = re.compile('(.)([a-z0-9\-\.]+\.' + domain + ')', re.IGNORECASE)
- regRelurl = re.compile('([>\"])([a-zA-Z0-9\-\.\:\/]+\.' + domain + '/.[^<\"]+)', re.IGNORECASE)
- except BaseException as e:
- self.error("Unable to form proper regexp trying to parse " + domain, False)
- continue
-
- while offset >= 0:
- offset = parsedata.find(domain, offset)
- #print "found at offset: " + str(offset)
- if offset < 0:
- break
-
- # Get 200 bytes before the domain to try and get hostnames
- chunkhost = parsedata[(offset-200):(offset+len(domain)+1)]
- # Get the trailing part for urls (some URLs are big..)
- chunkurl = parsedata[(offset-200):(offset+len(domain)+2000)]
-
- try:
- urlsRel.extend(regRelhost.findall(chunkhost))
- except Exception as e:
- self.error("Error applying regex2 to data (" + str(e) + ")", False)
-
- try:
- urlsRel.extend(regRelurl.findall(chunkurl))
- except Exception as e:
- self.error("Error applying regex3 to data (" + str(e) + ")", False)
-
- offset += len(domain)
-
# Loop through all the URLs/links found
for linkTuple in urlsRel:
# Remember the regex will return two vars (two groups captured)