From: root Date: Mon, 25 Dec 2017 21:45:31 +0000 (+0000) Subject: Add fake dns server X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;ds=inline;p=software%2Fwtfismyip.git Add fake dns server --- diff --git a/fakedns.service b/fakedns.service new file mode 100644 index 0000000..ab9aa6b --- /dev/null +++ b/fakedns.service @@ -0,0 +1,10 @@ +[Unit] +Description=Fake DNS Server + +[Service] +ExecStart=/usr/bin/python3 ./nameserver.py +NonBlocking=true +WorkingDirectory=/srv/www/wtfismyip.dn/ + +[Install] +WantedBy=multi-user.target diff --git a/nameserver.py b/nameserver.py new file mode 100755 index 0000000..e5a0ba1 --- /dev/null +++ b/nameserver.py @@ -0,0 +1,51 @@ +#!/usr/bin/python3 + +import asyncio +import hashlib +import os.path + +import dns.message + +import sqlite3 +con = sqlite3.connect("tokens.sqlite") + +with con: + con.execute("CREATE TABLE IF NOT EXISTS token (token CHAR[32], ip VARCHAR[40])") + + +class DnsServerProtocol: + def connection_made(self, transport): + self.transport = transport + + def datagram_received(self, data, addr): + # with open(os.path.join('packets', hashlib.sha224(data).hexdigest()), 'wb') as fd: + # fd.write(data) + message = dns.message.from_wire(data) + for question in message.question: + qname = str(question).split('.')[0] + + with con: + con.execute("INSERT INTO token (token, ip) VALUES (?, ?)", (qname, addr[0])) + + + response = dns.message.make_response(message) + self.transport.sendto(response.to_wire(), addr) + +loop = asyncio.get_event_loop() +print("Starting UDP server") +# One protocol instance will be created to serve all client requests +listen = loop.create_datagram_endpoint( + DnsServerProtocol, local_addr=('fda3:c723:abcd:efe1:5054:ff:fec8:148e', 53)) +transport, protocol = loop.run_until_complete(listen) +listen = loop.create_datagram_endpoint( + DnsServerProtocol, local_addr=('10.100.96.17', 53)) +transport, protocol = loop.run_until_complete(listen) + + +try: + loop.run_forever() +except KeyboardInterrupt: + pass + +transport.close() +loop.close() diff --git a/wtfismyip.dn.zone b/wtfismyip.dn.zone new file mode 100644 index 0000000..2ce6147 --- /dev/null +++ b/wtfismyip.dn.zone @@ -0,0 +1,9 @@ +@ IN A 10.100.96.17 + AAAA fda3:c723:abcd:efe1:5054:ff:fec8:148e + +www IN CNAME wtfismyip.dn. +v4 IN A 10.100.96.17 +v6 IN AAAA fda3:c723:abcd:efe1:5054:ff:fec8:148e + +ns4 IN NS v4 +ns6 IN NS v6