mirror of https://github.com/MISP/misp-modules
44 lines
1.2 KiB
Python
Executable File
44 lines
1.2 KiB
Python
Executable File
import json
|
|
import dns.resolver
|
|
|
|
misperrors = {'error' : 'Error'}
|
|
mispattributes = {'input': ['hostname', 'domain'], 'output': ['ip-src', 'ip-dst']}
|
|
moduleinfo = {'version': '0.1', 'author': 'Alexandre Dulaunoy', 'description': 'Simple DNS expansion service to resolve IP address from MISP attributes', 'module-type': ['expansion','hover']}
|
|
|
|
|
|
def handler(q=False):
|
|
if q is False:
|
|
return False
|
|
request = json.loads(q)
|
|
if request.get('hostname'):
|
|
toquery = request['hostname']
|
|
elif request.get('domain'):
|
|
toquery = request['domain']
|
|
else:
|
|
return False
|
|
r = dns.resolver.Resolver()
|
|
r.timeout = 2
|
|
r.lifetime = 2
|
|
r.nameservers = ['8.8.8.8']
|
|
try:
|
|
answer = r.query(toquery, 'A')
|
|
except dns.resolver.NXDOMAIN:
|
|
misperrors['error'] = "NXDOMAIN"
|
|
return misperrors
|
|
except dns.exception.Timeout:
|
|
misperrors['error'] = "Timeout"
|
|
return misperrors
|
|
except:
|
|
misperrors['error'] = "DNS resolving error"
|
|
return misperrors
|
|
r = {'results': [{'types': mispattributes['output'], 'values':[str(answer[0])]}]}
|
|
return r
|
|
|
|
|
|
def introspection():
|
|
return mispattributes
|
|
|
|
|
|
def version():
|
|
return moduleinfo
|