2016-03-25 11:02:32 +01:00
|
|
|
import json
|
|
|
|
import pypdns
|
|
|
|
|
2016-04-11 11:07:11 +02:00
|
|
|
misperrors = {'error': 'Error'}
|
|
|
|
mispattributes = {'input': ['hostname', 'domain', 'ip-src', 'ip-dst'], 'output': ['freetext']}
|
|
|
|
moduleinfo = {'version': '0.1', 'author': 'Alexandre Dulaunoy', 'description': 'Module to access CIRCL Passive DNS', 'module-type': ['expansion', 'hover']}
|
2016-03-25 11:02:32 +01:00
|
|
|
moduleconfig = ['username', 'password']
|
|
|
|
|
|
|
|
|
|
|
|
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('ip-src'):
|
|
|
|
toquery = request['ip-src']
|
|
|
|
elif request.get('ip-dst'):
|
|
|
|
toquery = request['ip-dst']
|
|
|
|
else:
|
|
|
|
misperrors['error'] = "Unsupported attributes type"
|
|
|
|
return misperrors
|
|
|
|
|
|
|
|
if (request.get('config')):
|
|
|
|
if (request['config'].get('username') is None) or (request['config'].get('password') is None):
|
|
|
|
misperrors['error'] = 'CIRCL Passive DNS authentication is missing'
|
|
|
|
return misperrors
|
|
|
|
|
|
|
|
x = pypdns.PyPDNS(basic_auth=(request['config']['username'], request['config']['password']))
|
|
|
|
res = x.query(toquery)
|
2016-03-25 13:52:10 +01:00
|
|
|
out = ''
|
2016-03-25 11:02:32 +01:00
|
|
|
for v in res:
|
2016-03-25 13:52:10 +01:00
|
|
|
out = out + "{} ".format(v['rdata'])
|
|
|
|
|
2016-04-11 11:07:11 +02:00
|
|
|
r = {'results': [{'types': mispattributes['output'], 'values': out}]}
|
2016-03-25 11:02:32 +01:00
|
|
|
return r
|
|
|
|
|
|
|
|
|
|
|
|
def introspection():
|
|
|
|
return mispattributes
|
|
|
|
|
|
|
|
|
|
|
|
def version():
|
|
|
|
moduleinfo['config'] = moduleconfig
|
|
|
|
return moduleinfo
|