Skip to content

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

Replaced usage of search engines with common crawl.

Steve Micalleff39758145c89
diff --git a/modules/sfp_commoncrawl.py b/modules/sfp_commoncrawl.py
new file mode 100644
index 00000000..9c6e9428
--- /dev/null
+++ b/modules/sfp_commoncrawl.py
@@ -0,0 +1,149 @@
+# -*- coding: utf-8 -*-
+# -------------------------------------------------------------------------------
+# Name: sfp_commoncrawl
+# Purpose: Searches the commoncrawl.org project's indexes for URLs related
+# to the target.
+#
+# Author: Steve Micallef <[email protected]>
+#
+# Created: 05/09/2018
+# Copyright: (c) Steve Micallef 2018
+# Licence: GPL
+# -------------------------------------------------------------------------------
+
+import re
+import json
+import urllib
+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
+
+
+class sfp_commoncrawl(SpiderFootPlugin):
+ """CommonCrawl:Footprint:Crawling and Scanning::Searches for URLs found through CommonCrawl.org."""
+
+
+ # Default options
+ opts = {
+ "indexes": 3
+ }
+
+ # Option descriptions
+ optdescs = {
+ "indexes": "Number of most recent indexes to attempt, because results tend to be occasionally patchy."
+ }
+
+ results = dict()
+ indexBase = list()
+ errorState = False
+
+ def setup(self, sfc, userOpts=dict()):
+ self.sf = sfc
+ self.results = dict()
+ self.indexBase = list()
+ self.errorState = False
+
+ for opt in userOpts.keys():
+ self.opts[opt] = userOpts[opt]
+
+ def search(self, target):
+ ret = list()
+ for index in self.indexBase:
+ url = "https://index.commoncrawl.org/" + index + \
+ "-index?url=" + target + "/*&output=json"
+ res = self.sf.fetchUrl(url , timeout=self.opts['_fetchtimeout'],
+ useragent="SpiderFoot")
+
+ if res['code'] in [ "400", "401", "402", "403", "404" ]:
+ self.sf.error("CommonCrawl search doesn't seem to be available.", False)
+ self.errorState = True
+ return None
+
+ ret.append(res['content'])
+
+ return ret
+
+ def getLatestIndexes(self):
+ url = "https://commoncrawl.s3.amazonaws.com/cc-index/collections/index.html"
+ res = self.sf.fetchUrl(url , timeout=self.opts['_fetchtimeout'],
+ useragent="SpiderFoot")
+
+ if res['code'] in [ "400", "401", "402", "403", "404" ]:
+ self.sf.error("CommonCrawl index collection doesn't seem to be available.", False)
+ self.errorState = True
+ return None
+
+ indexes = re.findall(".*(CC-MAIN-\d+-\d+).*", res['content'])
+ highest = 0
+ indexlist = dict()
+ for m in indexes:
+ ms = m.replace("CC-MAIN-", "").replace("-", "")
+ indexlist[ms] = True
+
+ topindexes = sorted(indexlist.keys(), reverse=True)[0:self.opts['indexes']]
+
+ if len(topindexes) < self.opts['indexes']:
+ self.sf.error("Not able to find latest CommonCrawl indexes.", False)
+ self.errorState = True
+ return None
+
+ retindex = list()
+ for i in topindexes:
+ retindex.append("CC-MAIN-" + str(i)[0:4] + "-" + str(i)[4:6])
+ self.sf.debug("CommonCrawl indexes: " + str(retindex))
+ return retindex
+
+ # What events is this module interested in for input
+ def watchedEvents(self):
+ return ["INTERNET_NAME"]
+
+ # What events this module produces
+ # This is to support the end user in selecting modules based on events
+ # produced.
+ def producedEvents(self):
+ return ["LINKED_URL_INTERNAL", "SEARCH_ENGINE_WEB_CONTENT"]
+
+ # 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:
+ return None
+ else:
+ self.results[eventData] = True
+
+ if len(self.indexBase) == 0:
+ self.indexBase = self.getLatestIndexes()
+
+ if len(self.indexBase) == 0:
+ self.sf.error("Unable to fetch CommonCrawl index.", False)
+ return None
+
+ data = self.search(eventData)
+ if not data:
+ self.sf.error("Unable to obtain content from CommonCrawl.", False)
+ return None
+
+ for content in data:
+ # Submit the gresults for analysis
+ sevt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", content,
+ self.__name__, event)
+ self.notifyListeners(sevt)
+
+ try:
+ for line in content.split("\n"):
+ if len(line) < 2:
+ continue
+ link = json.loads(line)
+ if 'url' not in link:
+ continue
+ evt = SpiderFootEvent("LINKED_URL_INTERNAL", link['url'],
+ self.__name__, sevt)
+ self.notifyListeners(evt)
+ except BaseException as e:
+ self.sf.error("Malformed JSON from CommonCrawl.org: " + str(e), False)
+ return None
+
+# End of sfp_commoncrawl class
diff --git a/modules/sfp_intfiles.py b/modules/sfp_intfiles.py
index dd5f23c9..b7186d16 100644
--- a/modules/sfp_intfiles.py
+++ b/modules/sfp_intfiles.py
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# -------------------------------------------------------------------------------
# Name: sfp_intfiles
-# Purpose: From Spidering and from searching search engines, identifies
-# files of potential interest.
+# Purpose: From Spidered pages found, identifies files of potential interest.
#
# Author: Steve Micallef <[email protected]>
#
@@ -23,37 +22,32 @@ class sfp_intfiles(SpiderFootPlugin):
# Default options
opts = {
'pages': 20, # Number of search results pages to iterate
- 'fileexts': ["doc", "docx", "ppt", "pptx", "pdf", 'xls', 'xlsx', 'zip'],
- 'usesearch': True,
- 'searchengine': "yahoo"
+ 'fileexts': ["doc", "docx", "ppt", "pptx", "pdf", 'xls', 'xlsx', 'zip']
}
# Option descriptions
optdescs = {
- 'pages': "Number of search engine results pages to iterate through if using one.",
- 'fileexts': "File extensions of files you consider interesting.",
- 'usesearch': "Use search engines to quickly find files. If false, only spidering will be used.",
- 'searchengine': "If using a search engine, which one? google, yahoo or bing."
+ 'fileexts': "File extensions of files you consider interesting."
}
- results = list()
+ results = dict()
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
- self.results = list()
+ 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", "LINKED_URL_INTERNAL"]
+ return ["LINKED_URL_INTERNAL"]
# What events this module produces
# This is to support the end user in selecting modules based on events
# produced.
def producedEvents(self):
- return ["SEARCH_ENGINE_WEB_CONTENT", "INTERESTING_FILE"]
+ return ["INTERESTING_FILE"]
# Handle events sent to this module
def handleEvent(self, event):
@@ -63,93 +57,15 @@ class sfp_intfiles(SpiderFootPlugin):
self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
- if eventName == "INTERNET_NAME" and not self.opts['usesearch']:
- self.sf.debug("Not using a search engine to find interesting files.")
- return None
-
if eventData in self.results:
return None
+ else:
+ self.results[eventData] = True
- if eventName == "LINKED_URL_INTERNAL":
- for fileExt in self.opts['fileexts']:
- if "." + fileExt.lower() in eventData.lower():
- if eventData in self.results:
- continue
- else:
- self.results.append(eventData)
-
- evt = SpiderFootEvent("INTERESTING_FILE", eventData,
- self.__name__, event)
- self.notifyListeners(evt)
- return None
-
- if eventData not in self.results:
- self.results.append(eventData)
-
- # Handling INTERNET_NAME event..
for fileExt in self.opts['fileexts']:
- # Sites hosted on the domain
- if self.opts['searchengine'].lower() == "google":
- pages = self.sf.googleIterate("site:" + eventData + "+" +
- "%2Bext:" + fileExt, dict(limit=self.opts['pages'],
- useragent=self.opts['_useragent'],
- timeout=self.opts['_fetchtimeout']))
- self.__dataSource__ = "Google"
-
- if self.opts['searchengine'].lower() == "bing":
- pages = self.sf.bingIterate("site:" + eventData + "+" +
- "%2Bfiletype:" + fileExt, dict(limit=self.opts['pages'],
- useragent=self.opts['_useragent'],
- timeout=self.opts['_fetchtimeout']))
- self.__dataSource__ = "Bing"
-
- if self.opts['searchengine'].lower() == "yahoo":
- pages = self.sf.yahooIterate("site:" + eventData + "+" +
- "%2Bfiletype:" + fileExt, dict(limit=self.opts['pages'],
- useragent=self.opts['_useragent'],
- timeout=self.opts['_fetchtimeout']))
- self.__dataSource__ = "Yahoo"
-
- if pages is None:
- self.sf.info("No results returned from " + self.opts['searchengine'] +
- " for " + fileExt + " files.")
- continue
-
- for page in pages.keys():
- if page in self.results:
- continue
- else:
- self.results.append(page)
-
- # Check if we've been asked to stop
- if self.checkForStop():
- return None
-
- # Submit the gresults for analysis
- evt = SpiderFootEvent("SEARCH_ENGINE_WEB_CONTENT", pages[page],
+ if "." + fileExt.lower() in eventData.lower():
+ evt = SpiderFootEvent("INTERESTING_FILE", eventData,
self.__name__, event)
self.notifyListeners(evt)
- links = self.sf.parseLinks(page, pages[page], eventData)
- if len(links) == 0:
- continue
-
- for link in links.keys():
- if link in self.results:
- continue
-
- if self.opts['searchengine'] == "yahoo":
- link = re.sub(r'.*RU=(.*?)/RK=.*', r'\1', link)
-
- if self.sf.urlFQDN(link).endswith(eventData):
- # This for loop might seem redundant but sometimes search engines return results
- # for other file extensions.
- for fe in self.opts['fileexts']:
- if "." + fe.lower() in link.lower():
- self.sf.info("Found an interesting file: " + link)
- evt = SpiderFootEvent("INTERESTING_FILE", link,
- self.__name__, event)
- self.notifyListeners(evt)
- self.results.append(link)
-
# End of sfp_intfiles class