2022-04-11 15:25:57 +00:00
|
|
|
version = "0.2"
|
2021-07-15 15:49:52 +00:00
|
|
|
from nserver import NameServer, Response, A, NS, TXT
|
|
|
|
import redis
|
|
|
|
import json
|
|
|
|
import re
|
|
|
|
|
|
|
|
rdb = redis.Redis(host='127.0.0.1', port='6666', decode_responses=True)
|
|
|
|
|
|
|
|
|
|
|
|
ns = NameServer("dns.hashlookup.circl.lu")
|
|
|
|
|
|
|
|
@ns.rule("info.dns.hashlookup.circl.lu", ["TXT"])
|
|
|
|
def say_info(query):
|
|
|
|
#if query.name.endswith(".com.au"):
|
|
|
|
# return TXT(query.name, "G'day mate")
|
|
|
|
info = {}
|
2022-04-11 15:25:57 +00:00
|
|
|
lookup = rdb.info()
|
2021-07-15 15:49:52 +00:00
|
|
|
info['nsrl-version'] = rdb.get('nsrl-version')
|
2022-04-11 15:25:57 +00:00
|
|
|
info['stat:hashlookup_total_keys'] = lookup['estimate_keys[default]']
|
2021-07-15 15:49:52 +00:00
|
|
|
info['hashlookup-version'] = version
|
|
|
|
return TXT(query.name, json.dumps(info))
|
|
|
|
|
|
|
|
@ns.rule("**", ["TXT"])
|
|
|
|
def wildcard_hashlookup(query):
|
|
|
|
hashq = query.name.split('.', 1)
|
|
|
|
print(hashq[0])
|
|
|
|
if re.findall(r"^[a-fA-F\d]{32}$", hashq[0]):
|
|
|
|
print("MD5")
|
|
|
|
sha1 = rdb.get("l:{}".format(hashq[0].upper()))
|
|
|
|
elif re.findall(r"^[a-fA-F\d]{40}$", hashq[0]):
|
|
|
|
print("SHA-1")
|
|
|
|
sha1 = hashq[0].upper()
|
|
|
|
else:
|
|
|
|
return Response()
|
|
|
|
if sha1 is None:
|
|
|
|
return Response()
|
|
|
|
if not rdb.exists("h:{}".format(sha1.upper())):
|
|
|
|
return Response()
|
2021-09-24 06:16:08 +00:00
|
|
|
h = {}
|
|
|
|
h['SHA-1'] = rdb.hget("h:{}".format(sha1), 'SHA-1')
|
|
|
|
h['MD5'] = rdb.hget("h:{}".format(sha1), 'MD5')
|
|
|
|
h['FileName'] = rdb.hget("h:{}".format(sha1), 'FileName')
|
|
|
|
print(h)
|
2021-07-15 15:49:52 +00:00
|
|
|
#if "OpSystemCode" in h:
|
|
|
|
# if rdb.exists("h-OpSystemCode:{}".format(h['OpSystemCode'])):
|
|
|
|
# h['OpSystemCode'] = rdb.hgetall("h-OpSystemCode:{}".format(h['OpSystemCode']))
|
|
|
|
#if "ProductCode" in h:
|
|
|
|
# if rdb.exists("h-ProductCode:{}".format(h['ProductCode'])):
|
|
|
|
# h['ProductCode'] = rdb.hgetall("h-ProductCode:{}".format(h['ProductCode']))
|
|
|
|
|
|
|
|
return TXT(query.name, json.dumps(h))
|
|
|
|
|
2022-04-11 15:25:57 +00:00
|
|
|
#@ns.rule("**", ["ANY"])
|
|
|
|
#def do_nothing(query):
|
|
|
|
# print(query)
|
|
|
|
# return TXT(query.name, "")
|
|
|
|
|
2021-07-15 15:49:52 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
ns.settings.SERVER_PORT = 53 # It's over 9000!
|
|
|
|
ns.settings.SERVER_ADDRESS = "185.194.93.133"
|
|
|
|
ns.run()
|