forked from MISP/misp-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
whois.py
executable file
·52 lines (38 loc) · 1.46 KB
/
whois.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
import json
try:
from uwhois import Uwhois
except ImportError:
print("uwhois module not installed.")
misperrors = {'error': 'Error'}
mispattributes = {'input': ['domain', 'ip-src', 'ip-dst'], 'output': ['freetext']}
moduleinfo = {'version': '0.1', 'author': 'Raphaël Vinot',
'description': 'Query a local instance of uwhois (https://github.com/rafiot/uwhoisd)',
'module-type': ['expansion']}
moduleconfig = ['server', 'port']
def handler(q=False):
if q is False:
return False
request = json.loads(q)
if request.get('domain'):
toquery = request['domain']
elif request.get('ip-src'):
toquery = request['ip-src']
elif request.get('ip-dst'):
toquery = request['ip-dst']
else:
misperrors['error'] = "Unsupported attributes type"
return misperrors
if not request.get('config') and not (request['config'].get('apikey') and request['config'].et('url')):
misperrors['error'] = 'EUPI authentication is missing'
return misperrors
uwhois = Uwhois(request['config']['server'], int(request['config']['port']))
if 'event_id' in request:
return handle_expansion(uwhois, toquery)
def handle_expansion(w, domain):
return {'results': [{'types': mispattributes['output'], 'values': w.query(domain)}]}
def introspection():
return mispattributes
def version():
moduleinfo['config'] = moduleconfig
return moduleinfo