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

39 lines
1.1 KiB
Python
Raw Normal View History

2016-05-08 13:07:09 +02:00
# -*- coding: utf-8 -*-
import json
from datetime import date, timedelta
from pybgpranking import BGPRanking
2016-05-08 13:07:09 +02:00
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']}
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
bgpranking = BGPRanking()
values = bgpranking.query(toquery, date=(date.today() - timedelta(1)).isoformat())
2016-05-08 13:07:09 +02:00
if not values:
misperrors['error'] = 'Unable to find the ASN in BGP Ranking'
2016-05-08 13:07:09 +02:00
return misperrors
return {'results': [{'types': mispattributes['output'], 'values': values}]}
def introspection():
return mispattributes
def version():
return moduleinfo