From f8b542b13989b8a4fe9df35b9d61f654c573afd3 Mon Sep 17 00:00:00 2001 From: Miguel Cuartin Date: Tue, 16 Feb 2021 10:34:42 -0500 Subject: [PATCH] Initial Commit --- .gitignore | 1 + dnproxy.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ dnproxy.yml | 0 requirements.txt | 11 +++++++++++ 4 files changed, 59 insertions(+) create mode 100644 .gitignore create mode 100644 dnproxy.py create mode 100644 dnproxy.yml create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f5e96db --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv \ No newline at end of file diff --git a/dnproxy.py b/dnproxy.py new file mode 100644 index 0000000..2316413 --- /dev/null +++ b/dnproxy.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +import logging as l +import socket + +from pyfiglet import Figlet + +import dns.flags +import dns.message +import dns.rdataclass +import dns.rdatatype +import dns.name +import dns.query + +from typing import cast + +# General config +l.basicConfig(level=l.INFO) +f = Figlet(font='slant') + +l.info(f.renderText('dnproxy')) + +# General Parameters +HOST = '127.0.0.1' +PORT = 53 +UPSTREAM_IP = '1.1.1.1' +TLS_HOSTNAME = 'cloudflare-dns.com' + + +with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + s.bind((HOST, PORT)) + l.info(f"Listening on {HOST}:{PORT}") + + while True: + (wire, host) = s.recvfrom(1024) + q = dns.message.from_wire(wire) + l.info(f'Question {q.id}:{q.question}') + + try: + r = dns.query.tls(q, UPSTREAM_IP, server_hostname=TLS_HOSTNAME) + l.info(f'Response {r.id}:{r.answer}') + + except KeyError: + l.error("error") + + wire = r.to_wire() + s.sendto(wire, host) \ No newline at end of file diff --git a/dnproxy.yml b/dnproxy.yml new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..76e8b1c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,11 @@ +certifi==2020.12.5 +cffi==1.14.5 +chardet==4.0.0 +cryptography==3.4.5 +dnspython==2.1.0 +idna==2.10 +pycparser==2.20 +pyfiglet==0.8.post1 +requests==2.25.1 +requests-toolbelt==0.9.1 +urllib3==1.26.3