SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Azure blob finder module.
smicallef4c45efe0f1e8
diff --git a/modules/sfp_azureblobstorage.py b/modules/sfp_azureblobstorage.pynew file mode 100644index 00000000..c7913985--- /dev/null+++ b/modules/sfp_azureblobstorage.py@@ -0,0 +1,154 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_azureblobstorage+# Purpose: SpiderFoot plug-in for identifying potential Azure blobs related+# to the target.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 14/07/2019+# Copyright: (c) Steve Micallef 2019+# Licence: GPL+# -------------------------------------------------------------------------------++import threading+import time+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent++class sfp_azureblobstorage(SpiderFootPlugin):+ """Azure Blob Finder:Footprint,Passive:Crawling and Scanning::Search for potential Azure blobs associated with the target and attempt to list their contents."""+++ # Default options+ opts = {+ "suffixes": "test,dev,web,beta,bucket,space,files,content,data,prod,staging,production,stage,app,media,development,-test,-dev,-web,-beta,-bucket,-space,-files,-content,-data,-prod,-staging,-production,-stage,-app,-media,-development",+ "_maxthreads": 20+ }++ # Option descriptions+ optdescs = {+ "suffixes": "List of suffixes to append to domains tried as blob storage names"+ }++ results = None+ s3results = None++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc+ self.s3results = dict()+ self.results = dict()+ self.lock = threading.Lock()++ for opt in userOpts.keys():+ self.opts[opt] = userOpts[opt]++ # What events is this module interested in for input+ def watchedEvents(self):+ return ["DOMAIN_NAME", "LINKED_URL_EXTERNAL"]++ # What events this module produces+ # This is to support the end user in selecting modules based on events+ # produced.+ def producedEvents(self):+ return ["CLOUD_STORAGE_BUCKET"]++ def checkSite(self, url):+ res = self.sf.fetchUrl(url, timeout=10, useragent="SpiderFoot", noLog=True)++ if res['code']:+ with self.lock:+ self.s3results[url] = True++ def threadSites(self, siteList):+ ret = list()+ self.s3results = dict()+ running = True+ i = 0+ t = []++ for site in siteList:+ if self.checkForStop():+ return None++ self.sf.info("Spawning thread to check bucket: " + site)+ t.append(threading.Thread(name='sfp_azureblobstorages_' + site,+ target=self.checkSite, args=(site,)))+ t[i].start()+ i += 1++ # Block until all threads are finished+ while running:+ found = False+ for rt in threading.enumerate():+ if rt.name.startswith("sfp_azureblobstorages_"):+ found = True++ if not found:+ running = False++ time.sleep(0.25)++ # Return once the scanning has completed+ return self.s3results++ def batchSites(self, sites):+ i = 0+ res = list()+ siteList = list()++ for site in sites:+ if i >= self.opts['_maxthreads']:+ data = self.threadSites(siteList)+ if data == None:+ return res++ for ret in data.keys():+ if data[ret]:+ res.append(ret)+ i = 0+ siteList = list()++ siteList.append(site)+ i += 1++ return res++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data++ if eventData in self.results:+ return None+ else:+ self.results[eventData] = True++ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)++ if eventName == "LINKED_URL_EXTERNAL":+ if ".blob.core.windows.net" in eventData:+ b = self.sf.urlFQDN(eventData)+ evt = SpiderFootEvent("CLOUD_STORAGE_BUCKET", b, self.__name__, event)+ self.notifyListeners(evt)+ return None++ targets = [ eventData.replace('.', ''), self.sf.domainKeyword(eventData, self.opts['_internettlds']) ]+ urls = list()+ for t in targets:+ suffixes = [''] + self.opts['suffixes'].split(',')+ for s in suffixes:+ if self.checkForStop():+ return None++ b = t + s + ".blob.core.windows.net"+ url = "https://" + b+ urls.append(url)++ # Batch the scans+ ret = self.batchSites(urls)+ for b in ret:+ evt = SpiderFootEvent("CLOUD_STORAGE_BUCKET", b, self.__name__, event)+ self.notifyListeners(evt)++# End of sfp_azureblobstorage class