Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
misp-modules/misp_modules/modules/expansion/dns.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
61 lines (50 sloc)
1.73 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import dns.resolver | |
misperrors = {'error': 'Error'} | |
mispattributes = {'input': ['hostname', 'domain', 'domain|ip'], 'output': ['ip-src', | |
'ip-dst']} | |
moduleinfo = {'version': '0.2', 'author': 'Alexandre Dulaunoy', | |
'description': 'Simple DNS expansion service to resolve IP address from MISP attributes', | |
'module-type': ['expansion', 'hover']} | |
moduleconfig = ['nameserver'] | |
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'] | |
elif request.get('domain|ip'): | |
toquery = request['domain|ip'].split('|')[0] | |
else: | |
return False | |
r = dns.resolver.Resolver() | |
r.timeout = 2 | |
r.lifetime = 2 | |
if request.get('config'): | |
if request['config'].get('nameserver'): | |
nameservers = [] | |
nameservers.append(request['config'].get('nameserver')) | |
r.nameservers = nameservers | |
else: | |
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 Exception: | |
misperrors['error'] = "DNS resolving error" | |
return misperrors | |
r = {'results': [{'types': mispattributes['output'], | |
'values':[str(answer[0])]}]} | |
return r | |
def introspection(): | |
return mispattributes | |
def version(): | |
moduleinfo['config'] = moduleconfig | |
return moduleinfo |