misp-modules/misp_modules/modules/expansion/asn_history.py

49 lines
1.6 KiB
Python
Raw Normal View History

2016-05-08 13:07:09 +02:00
# -*- coding: utf-8 -*-
import json
from asnhistory import ASNHistory
misperrors = {'error': 'Error'}
2016-05-08 14:28:03 +02:00
mispattributes = {'input': ['AS'], 'output': ['freetext']}
2016-05-08 13:07:09 +02:00
moduleinfo = {'version': '0.1', 'author': 'Raphaël Vinot',
'description': 'Query an ASN Description history service (https://github.com/CIRCL/ASN-Description-History.git)',
'module-type': ['expansion', 'hover']}
moduleconfig = ['host', 'port', 'db']
def handler(q=False):
if q is False:
return False
request = json.loads(q)
2016-05-08 14:28:03 +02:00
if request.get('AS'):
toquery = request['AS']
2016-05-08 13:07:09 +02:00
else:
misperrors['error'] = "Unsupported attributes type"
return misperrors
2018-12-11 15:29:09 +01:00
if not request.get('config') and not (request['config'].get('host')
and request['config'].get('port')
and request['config'].get('db')):
2016-05-08 13:07:09 +02:00
misperrors['error'] = 'ASN description history configuration is missing'
return misperrors
asnhistory = ASNHistory(host=request['config'].get('host'),
port=request['config'].get('port'), db=request['config'].get('db'))
values = ['{} {}'.format(date.isoformat(), description) for date, description in asnhistory.get_all_descriptions(toquery)]
if not values:
misperrors['error'] = 'Unable to find descriptions for this ASN'
return misperrors
return {'results': [{'types': mispattributes['output'], 'values': values}]}
def introspection():
return mispattributes
def version():
moduleinfo['config'] = moduleconfig
return moduleinfo