SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
New module to identify hosting providers.
Steve Micallefee949b678eca
diff --git a/modules/sfp_hosting.py b/modules/sfp_hosting.pynew file mode 100644index 00000000..a429a547--- /dev/null+++ b/modules/sfp_hosting.py@@ -0,0 +1,91 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_hosting+# Purpose: SpiderFoot plug-in for looking up whether IPs/Netblocks/Domains+# appear in an IP categorization table of hosting providers.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 16/08/2015+# Copyright: (c) Steve Micallef 2015+# Licence: GPL+# -------------------------------------------------------------------------------++import socket+from netaddr import IPAddress, IPNetwork+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent+++class sfp_hosting(SpiderFootPlugin):+ """Hosting Providers: Find out if any IP addresses identified fall within known 3rd party hosting ranges, e.g. Amazon, Azure, etc."""++ # Default options+ opts = {+ }++ # Option descriptions+ optdescs = {+ }++ # Target+ 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 ['IP_ADDRESS']++ # What events this module produces+ # This is to support the end user in selecting modules based on events+ # produced.+ def producedEvents(self):+ return ["PROVIDER_HOSTING"]++ def queryAddr(self, qaddr):+ data = dict()+ url = "https://raw.githubusercontent.com/client9/ipcat/master/datacenters.csv"++ data['content'] = self.sf.cacheGet("sfipcat", 48)+ if data['content'] is None:+ data['content'] = self.sf.fetchUrl(url, useragent=self.opts['_useragent'])+ if data['content'] is None:+ self.sf.error("Unable to fetch " + url, False)+ return None+ else:+ self.sf.cachePut("sfipcat", data['content'])++ for line in data['content'].split('\n'):+ if "," not in line:+ continue+ [start,end,title,url] = line.split(",")++ if IPAddress(qaddr) > IPAddress(start) and IPAddress(qaddr) < IPAddress(end):+ return [title, url]++ return False++ # 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+ self.results[eventData] = True++ ret = self.queryAddr(eventData)+ if ret != False:+ evt = SpiderFootEvent("PROVIDER_HOSTING", ret[0] + ": " + ret[1],+ self.__name__, event)+ self.notifyListeners(evt)++# End of sfp_hosting classdiff --git a/sfdb.py b/sfdb.pyindex d746c87f..e4595ed6 100644--- a/sfdb.py+++ b/sfdb.py@@ -143,6 +143,7 @@ class SpiderFootDb:"INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('PROVIDER_DNS', 'Name Server (DNS ''NS'' Records)', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('PROVIDER_JAVASCRIPT', 'Externally Hosted Javascript', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('PROVIDER_MAIL', 'Email Gateway (DNS ''MX'' Records)', 0, 'ENTITY')",+ "INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('PROVIDER_HOSTING', 'Hosting Provider', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('PUBLIC_CODE_REPO', 'Public Code Repository', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('RAW_RIR_DATA', 'Raw Data from RIRs', 1, 'DATA')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('RAW_DNS_RECORDS', 'Raw DNS Records', 1, 'DATA')",