forked from MISP/misp-modules
-
Notifications
You must be signed in to change notification settings - Fork 3
/
hashdd.py
executable file
·41 lines (33 loc) · 1.25 KB
/
hashdd.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
import json
import requests
misperrors = {'error': 'Error'}
mispattributes = {'input': ['md5'], 'output': ['text']}
moduleinfo = {'version': '0.2', 'author': 'Alexandre Dulaunoy', 'description': 'An expansion module to check hashes against hashdd.com including NSLR dataset.', 'module-type': ['hover']}
moduleconfig = []
hashddapi_url = 'https://api.hashdd.com/v1/knownlevel/nsrl/'
def handler(q=False):
if q is False:
return False
v = None
request = json.loads(q)
for input_type in mispattributes['input']:
if request.get(input_type):
v = request[input_type].upper()
break
if v is None:
misperrors['error'] = 'Hash value is missing.'
return misperrors
r = requests.get(hashddapi_url + v)
if r.status_code == 200:
state = json.loads(r.text)
summary = state['knownlevel'] if state and state['result'] == "SUCCESS" else state['message']
else:
misperrors['error'] = '{} API not accessible'.format(hashddapi_url)
return misperrors['error']
r = {'results': [{'types': mispattributes['output'], 'values': summary}]}
return r
def introspection():
return mispattributes
def version():
moduleinfo['config'] = moduleconfig
return moduleinfo