SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
SHODAN support via REST API.
smicallef463ae429d6f8
diff --git a/LICENSE.tp b/LICENSE.tpindex f2940243..cabd16ae 100644--- a/LICENSE.tp+++ b/LICENSE.tp@@ -1,3 +1,71 @@+License for the Python SHODAN library:+======================================+Copyright (c) 2014 John Matherly <[email protected]>++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++Except as contained in this notice, the name(s) of the above+copyright holders shall not be used in advertising or otherwise+to promote the sale, use or other dealings in this Software+without prior written authorization.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.++License for simplejson by Bob Ippolito:+========================================+Copyright (c) 2006 Bob Ippolito++Permission is hereby granted, free of charge, to any person obtaining a copy of+this software and associated documentation files (the "Software"), to deal in+the Software without restriction, including without limitation the rights to+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies+of the Software, and to permit persons to whom the Software is furnished to do+so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.++License for requests by Kenneth Reitz:+=======================================+Copyright 2014 Kenneth Reitz++ Licensed under the Apache License, Version 2.0 (the "License");+ you may not use this file except in compliance with the License.+ You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing, software+ distributed under the License is distributed on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ See the License for the specific language governing permissions and+ limitations under the License.+License for SocksiPy by Dan Haim:==================================Copyright 2006 Dan-Haim. All rights reserved.diff --git a/evtypes.sql b/evtypes.sqlindex 7dc71154..6c21162e 100644--- a/evtypes.sql+++ b/evtypes.sql@@ -15,6 +15,7 @@ INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_IPAINSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_AFFILIATE', 'Defaced Affiliate', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_COHOST', 'Defaced Co-Hosted Site', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_AFFILIATE_IPADDR', 'Defaced Affiliate IP Address', 0);+INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEVICE_TYPE', 'Device Type', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('GEOINFO', 'Physical Location', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('HTTP_CODE', 'HTTP Status Code', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('INITIAL_TARGET', 'User-Supplied Target', 0);@@ -31,6 +32,7 @@ INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('MALICIOUS_AINSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('MALICIOUS_NETBLOCK', 'Malicious IP on Owned Netblock', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('MALICIOUS_SUBNET', 'Malicious IP on Same Subnet', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('NETBLOCK', 'Netblock Ownership', 0);+INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('OPERATING_SYSTEM', 'Operating System', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('PROVIDER_DNS', 'Name Server (DNS ''NS'' Records)', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('PROVIDER_INTERNET', 'Internet Service Provider', 0);INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('PROVIDER_JAVASCRIPT', 'Externally Hosted Javascript', 0);diff --git a/modules/sfp_shodan.py b/modules/sfp_shodan.pynew file mode 100644index 00000000..5d6f82cd--- /dev/null+++ b/modules/sfp_shodan.py@@ -0,0 +1,120 @@+#-------------------------------------------------------------------------------+# Name: sfp_shodan+# Purpose: Query SHODAN for identified IP addresses.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 19/03/2014+# Copyright: (c) Steve Micallef+# Licence: GPL+#-------------------------------------------------------------------------------++import sys+import json+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent++# SpiderFoot standard lib (must be initialized in setup)+sf = None++class sfp_shodan(SpiderFootPlugin):+ """SHODAN:Obtain information from SHODAN about identified IP addresses."""++ # Default options+ opts = {+ "apikey": ""+ }++ # Option descriptions+ optdescs = {+ "apikey": "Your SHODAN API Key."+ }++ # Be sure to completely clear any class variables in setup()+ # or you run the risk of data persisting between scan runs.++ # Target+ baseDomain = None # calculated from the URL in setup+ results = dict()++ def setup(self, sfc, target, userOpts=dict()):+ global sf++ sf = sfc+ self.baseDomain = target+ self.results = dict()++ # 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+ def watchedEvents(self):+ return ["IP_ADDRESS"]++ # What events this module produces+ def producedEvents(self):+ return ["OPERATING_SYSTEM", "DEVICE_TYPE",+ "TCP_PORT_OPEN", "TCP_PORT_OPEN_BANNER"]++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data++ sf.debug("Received event, " + eventName + ", from " + srcModuleName)++ # Don't look up stuff twice+ if self.results.has_key(eventData):+ sf.debug("Skipping " + eventData + " as already mapped.")+ return None+ else:+ self.results[eventData] = True++ res = sf.fetchUrl("https://api.shodan.io/shodan/host/" + eventData + \+ "?key=" + self.opts['apikey'],+ timeout=self.opts['_fetchtimeout'], useragent=self.opts['_useragent'])+ if res['content'] == None:+ sf.info("No SHODAN info found for " + eventData)+ return None++ try:+ info = json.loads(res['content'])+ except Exception as e:+ sf.error("Error processing JSON response from SHODAN.", False)+ return None++ os = info.get('os')+ devtype = info.get('devicetype')++ if os != None:+ # Notify other modules of what you've found+ evt = SpiderFootEvent("OPERATING_SYSTEM", os, self.__name__, event)+ self.notifyListeners(evt)++ if devtype != None:+ # Notify other modules of what you've found+ evt = SpiderFootEvent("DEVICE_TYPE", devtype, self.__name__, event)+ self.notifyListeners(evt)+++ sf.info("Found SHODAN data for " + eventData)+ for rec in info['data']:+ port = str(rec.get('port'))+ banner = rec.get('banner')++ if port != None:+ # Notify other modules of what you've found+ evt = SpiderFootEvent("TCP_PORT_OPEN", port, self.__name__, event)+ self.notifyListeners(evt)++ if banner != None:+ # Notify other modules of what you've found+ evt = SpiderFootEvent("TCP_PORT_OPEN_BANNER", banner, self.__name__, event)+ self.notifyListeners(evt)++ return None++# End of sfp_shodan classdiff --git a/sfdb.py b/sfdb.pyindex 1f42fd96..a1f2770e 100644--- a/sfdb.py+++ b/sfdb.py@@ -87,6 +87,7 @@ class SpiderFootDb:"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_AFFILIATE', 'Defaced Affiliate', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_AFFILIATE_IPADDR', 'Defaced Affiliate IP Address', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEFACED_COHOST', 'Defaced Co-Hosted Site', 0)",+ "INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('DEVICE_TYPE', 'Device Type', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('EMAILADDR', 'Email Address', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('GEOINFO', 'Physical Location', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('HTTP_CODE', 'HTTP Status Code', 0)",@@ -104,6 +105,7 @@ class SpiderFootDb:"INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('MALICIOUS_SUBNET', 'Malicious IP on Same Subnet', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('LINKED_URL_INTERNAL', 'Linked URL - Internal', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('LINKED_URL_EXTERNAL', 'Linked URL - External', 0)",+ "INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('OPERATING_SYSTEM', 'Operating System', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('PROVIDER_DNS', 'Name Server (DNS ''NS'' Records)', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('PROVIDER_INTERNET', 'Internet Service Provider', 0)","INSERT INTO tbl_event_types (event, event_descr, event_raw) VALUES ('PROVIDER_MAIL', 'Email Gateway (DNS ''MX'' Records)', 0)",