Browse Source

Merge branch 'geoip_country'

pull/81/head
Andreas Muehlemann 5 years ago
parent
commit
bb62394c1e
  1. 1
      REQUIREMENTS
  2. 2
      misp_modules/modules/expansion/__init__.py
  3. 2
      misp_modules/modules/expansion/geoip_country.cfg
  4. 58
      misp_modules/modules/expansion/geoip_country.py

1
REQUIREMENTS

@ -18,3 +18,4 @@ pillow
pytesseract
SPARQLWrapper
domaintools_api
pygeoip

2
misp_modules/modules/expansion/__init__.py

@ -2,4 +2,4 @@ from . import _vmray
__all__ = ['vmray_submit', 'asn_history', 'circl_passivedns', 'circl_passivessl',
'countrycode', 'cve', 'dns', 'domaintools', 'eupi', 'ipasn', 'passivetotal', 'sourcecache',
'virustotal', 'whois', 'shodan', 'reversedns', 'wiki']
'virustotal', 'whois', 'shodan', 'reversedns', 'geoip_country', 'wiki']

2
misp_modules/modules/expansion/geoip_country.cfg

@ -0,0 +1,2 @@
[defaults]
database=/opt/misp-modules/var/GeoIP.dat

58
misp_modules/modules/expansion/geoip_country.py

@ -0,0 +1,58 @@
import json, pygeoip
import sys, logging
import ConfigParser
log = logging.getLogger('geoip_country')
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
log.addHandler(ch)
misperrors = {'error': 'Error'}
mispattributes = {'input': ['ip-src', 'ip-dst', 'domain|ip'], 'output': ['freetext']}
# possible module-types: 'expansion', 'hover' or both
moduleinfo = {'version': '0.1', 'author': 'Andreas Muehlemann',
'description': 'Query a local copy of Maxminds Geolite database',
'module-type': ['expansion', 'hover']}
# get current db from http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
config = ConfigParser.ConfigParser()
config.read('./geoip_contry.cfg')
gi = pygeoip.GeoIP(config.get('defaults', 'database')
def handler(q=False):
if q is False:
return False
request = json.loads(q)
if request.get('ip-dst'):
toquery = request['ip-dst']
elif request.get('ip-src'):
toquery = request['ip-src']
elif request.get('domain|ip'):
toquery = request['domain|ip'].split('|')[1]
else:
return false
log.debug(toquery)
try:
answer = gi.country_code_by_addr(toquery)
except:
misperrors['error'] = "GeoIP resolving error"
return misperrors
r = {'results': [{'types': mispattributes['output'],
'values': [str(answer)]}]}
return r
def introspection():
return mispattributes
def version():
moduleinfo['config'] = moduleconfig
return moduleinfo
Loading…
Cancel
Save