SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
GeoIP Lookup module
smicallef1cf79322634f
diff --git a/evtypes.sql b/evtypes.sqlindex 0c1f9035..d2f1c143 100644--- a/evtypes.sql+++ b/evtypes.sql@@ -3,6 +3,7 @@--INSERT INTO tbl_event_types (event, event_descr) VALUES ('AFFILIATE', 'Affiliate');INSERT INTO tbl_event_types (event, event_descr) VALUES ('EMAILADDR', 'Email Address');+INSERT INTO tbl_event_types (event, event_descr) VALUES ('GEOINFO', 'Physical Location')INSERT INTO tbl_event_types (event, event_descr) VALUES ('IP_ADDRESS', 'IP Address');INSERT INTO tbl_event_types (event, event_descr) VALUES ('SUBDOMAIN', 'Sub-domain');INSERT INTO tbl_event_types (event, event_descr) VALUES ('SIMILARDOMAIN', 'Similar Domain');diff --git a/modules/sfp_geoip.py b/modules/sfp_geoip.pynew file mode 100644index 00000000..715651ee--- /dev/null+++ b/modules/sfp_geoip.py@@ -0,0 +1,81 @@+#-------------------------------------------------------------------------------+# Name: sfp_geoip+# Purpose: SpiderFoot plug-in to identify the Geo-location of IP addresses+# identified by other modules.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 18/02/2013+# Copyright: (c) Steve Micallef 2013+# Licence: GPL+#-------------------------------------------------------------------------------++import sys+import re+import json+import socket+from sflib import SpiderFoot, SpiderFootPlugin++# SpiderFoot standard lib (must be initialized in setup)+sf = None++class sfp_geoip(SpiderFootPlugin):+ """Identifies the physical location of IP addresses identified."""++ # Default options+ opts = {+ # These must always be set+ '__debug': True,+ '__debugfilter': ''+ }++ # URL this instance is working on+ seedUrl = None+ baseDomain = None # calculated from the URL in setup+ results = dict()++ def setup(self, url, userOpts=dict()):+ global sf+ self.seedUrl = url+ self.results = dict()++ for opt in userOpts.keys():+ self.opts[opt] = userOpts[opt]++ # For error reporting, debug, etc.+ sf = SpiderFoot(self.opts)++ # Extract the 'meaningful' part of the FQDN from the URL+ self.baseDomain = sf.urlBaseDom(self.seedUrl)+ sf.debug('Base Domain: ' + self.baseDomain)++ # What events is this module interested in for input+ def watchedEvents(self):+ return ['IP_ADDRESS']++ # Handle events sent to this module+ def handleEvent(self, srcModuleName, eventName, eventSource, eventData):+ 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("http://api.hostip.info/get_json.php?ip=" + eventData)+ if res['content'] == None:+ sf.debug("No GeoIP info found for " + eventData)+ hostip = json.loads(res['content'])+ countrycity = hostip['country_name'] + " (" + hostip['city'] + ")"++ self.notifyListeners("GEOINFO", eventData, countrycity)++ return None++# End of sfp_geoip class++if __name__ == '__main__':+ print "This module cannot be run stand-alone."+ exit(-1)diff --git a/sfdbsetup.py b/sfdbsetup.pyindex 4d195471..8a7f086e 100644--- a/sfdbsetup.py+++ b/sfdbsetup.py@@ -69,6 +69,7 @@ class SpiderFootDbInit:"CREATE INDEX idx_scan_results_event ON tbl_scan_results (scan_instance_id, event)","INSERT INTO tbl_event_types (event, event_descr) VALUES ('AFFILIATE', 'Affiliate')","INSERT INTO tbl_event_types (event, event_descr) VALUES ('EMAILADDR', 'Email Address')",+ "INSERT INTO tbl_event_types (event, event_descr) VALUES ('GEOINFO', 'Physical Location')","INSERT INTO tbl_event_types (event, event_descr) VALUES ('IP_ADDRESS', 'IP Address')","INSERT INTO tbl_event_types (event, event_descr) VALUES ('SUBDOMAIN', 'Sub-domain')","INSERT INTO tbl_event_types (event, event_descr) VALUES ('SIMILARDOMAIN', 'Similar Domain')",diff --git a/sflib.py b/sflib.pyindex 17b32422..088a1b13 100644--- a/sflib.py+++ b/sflib.py@@ -436,12 +436,13 @@ class SpiderFoot:if fatal:self.fatal('URL could not be fetched (' + h.code + ')')except urllib2.URLError as e:- self.debug("Error fetching " + url)+ self.debug("Error fetching " + url + "(" + str(e) + ")")result['status'] = str(e)if fatal:self.fatal('URL could not be fetched (' + str(e) + ')')except Exception as x:- self.error("Unexpected exception occurred fetching: " + url + "(" + str(x) + ")")+ self.debug("Unexpected exception occurred fetching: " + url + "(" + str(x) + ")")+ result['content'] = Noneresult['status'] = str(x)if fatal:self.fatal('URL could not be fetched (' + str(x) + ')')