|
| 1 | +## DNS-over-TLS proxy |
| 2 | + |
| 3 | +This is very simple and mimimilistic, DNS proxy service capable of running in multi-thread mode, handling multilpe connections in parallel and build using python. |
| 4 | + |
| 5 | +This is packaged with Docker and Dcoker-compose. Docker Compose can help deploy this in docker stack infrastructure or kubernetes. |
| 6 | +The module Execution starts from `DNSoverTLS.__main__:start()` method. |
| 7 | + |
| 8 | + |
| 9 | +```bash |
| 10 | ++--------------+ U/T +----------------------+ TCP +-----------------------------+ |
| 11 | +| + --------> + + --------> + | |
| 12 | +| DNS Req | | DNS Proxy | | Cloudflare - TLS - DNS | |
| 13 | +| + <-------- + + <-------- + | |
| 14 | ++--------------+ U/T +----------------------+ TCP +-----------------------------+ |
| 15 | + 8053(UDP) - 8853(TCP) |
| 16 | + |
| 17 | +``` |
| 18 | + |
| 19 | +### How to run: |
| 20 | + |
| 21 | +#### Single service |
| 22 | +```bash |
| 23 | +# Build Docker |
| 24 | +docker build -t dns . |
| 25 | + |
| 26 | +# Run the docker Image |
| 27 | +docker run -d -p 8053:8053/udp -p8853:8853 -t dns |
| 28 | + |
| 29 | +# Test the proxy |
| 30 | +# Handle TCP connections |
| 31 | +dig @127.0.0.1 -p8853 rsehgal.in +tcp |
| 32 | + |
| 33 | +# Handle UDP connections. |
| 34 | +dig @127.0.0.1 -p8053 rsehgal.in |
| 35 | + |
| 36 | +; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> @127.0.0.1 -p9090 rsehgal.in |
| 37 | +; (1 server found) |
| 38 | +;; global options: +cmd |
| 39 | +;; Got answer: |
| 40 | +;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32042 |
| 41 | +;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1 |
| 42 | +
|
| 43 | +;; OPT PSEUDOSECTION: |
| 44 | +; EDNS: version: 0, flags:; udp: 1232 |
| 45 | +; PAD: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 (".........................................................................................................................................................................................................................................................................................................................................................................................................") |
| 46 | +;; QUESTION SECTION: |
| 47 | +;rsehgal.in. IN A |
| 48 | +
|
| 49 | +;; ANSWER SECTION: |
| 50 | +rsehgal.in. 20 IN A 206.189.89.118 |
| 51 | +rsehgal.in. 20 IN A 157.230.35.153 |
| 52 | +
|
| 53 | +;; Query time: 589 msec |
| 54 | +;; SERVER: 127.0.0.1#9090(127.0.0.1) |
| 55 | +;; WHEN: Sat Sep 12 08:40:31 UTC 2020 |
| 56 | +;; MSG SIZE rcvd: 468 |
| 57 | +``` |
| 58 | +
|
| 59 | +#### Build and Deploy in cluster |
| 60 | +```bash |
| 61 | +# Build docker compose |
| 62 | +docker-compose build . |
| 63 | +
|
| 64 | +# Run compose in docker-swarm mode |
| 65 | +# Create master node |
| 66 | +docker swarm init |
| 67 | +
|
| 68 | +# Join the Swarm, create multinode cluster |
| 69 | +docker swarm join --token <SWARMTOKEN> |
| 70 | +
|
| 71 | +# Deploy proxy in swarn |
| 72 | +docker stack deploy --compose-file docker-compose.yml dns-proxy |
| 73 | +
|
| 74 | +# Handle TCP connections |
| 75 | +dig @127.0.0.1 -p8853 rsehgal.in +tcp |
| 76 | +
|
| 77 | +# Handle UDP connections. |
| 78 | +dig @127.0.0.1 -p8053 rsehgal.in |
| 79 | +
|
| 80 | +; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> @127.0.0.1 -p9090 rsehgal.in |
| 81 | +; (1 server found) |
| 82 | +;; global options: +cmd |
| 83 | +;; Got answer: |
| 84 | +;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29786 |
| 85 | +;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1 |
| 86 | +
|
| 87 | +;; OPT PSEUDOSECTION: |
| 88 | +; EDNS: version: 0, flags:; udp: 1232 |
| 89 | +; PAD: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 (".........................................................................................................................................................................................................................................................................................................................................................................................................") |
| 90 | +;; QUESTION SECTION: |
| 91 | +;rsehgal.in. IN A |
| 92 | +
|
| 93 | +;; ANSWER SECTION: |
| 94 | +rsehgal.in. 20 IN A 157.230.35.153 |
| 95 | +rsehgal.in. 20 IN A 157.230.37.202 |
| 96 | +
|
| 97 | +;; Query time: 522 msec |
| 98 | +;; SERVER: 127.0.0.1#9090(127.0.0.1) |
| 99 | +;; WHEN: Sat Sep 12 08:51:22 UTC 2020 |
| 100 | +;; MSG SIZE rcvd: 468 |
| 101 | +``` |
| 102 | +
|
| 103 | +### Proxy features |
| 104 | +1. Supports TCP and UDP connections with Proxy. |
| 105 | +1. Ready to use logging module. |
| 106 | +2. Threaded server. |
| 107 | +3. Packaged as docker. |
| 108 | +4. Packaged as docker-compose. |
| 109 | + 1. Ready to deploy in docker-swarm cluster, multinode deployment. |
| 110 | +5. No third party library used. |
| 111 | +6. No dependencies. |
| 112 | +7. Currently connects with Cloudflare only, but can me modified to work with any DNS-TLS providers. |
| 113 | +7. Server certificate verification using SSL. |
| 114 | +
|
| 115 | +
|
| 116 | +### Security consideration |
| 117 | +1. Imagine this proxy being deployed in an infrastructure. What would be the security concerns you would raise? |
| 118 | + - The infrastructure deployment in current case is packaged with docker-swarn. The default docker-swarm deployment takes care of securing node to node communication. For load balancing, request routing etc. |
| 119 | + - Loggin module is plugged in, which can help do detailed loggin with help of python's loggin module. This loggin result can be even sent to SIEM solutions like Splunk. This module is not coded yet, but the way the plugin has been written, this feature can be easily extended. |
| 120 | + - Server certificate verification using CA certificates in OS. |
| 121 | +
|
| 122 | +2. How would you integrate that solution in a distributed, microservices-oriented and containerized architecture? |
| 123 | + - For such solutions, I prefer, docker-swarm, since the application is already packaged as container, deployment is swarm through docker-compose file make it really easy, secure and monitoring. |
| 124 | + - Microservices connecting to swarm/ |
| 125 | +
|
| 126 | +3. What other improvements do you think would be interesting to add to the project? |
| 127 | + - Logging to SIEM. |
| 128 | + - Handle Zone transfer request. |
| 129 | + - There is lot of biolerplate code, that can be removed. Hope fully in next REL ;) |
| 130 | + - Scaleable multiprocessing instead of multithreaded, as python suffers from world famous [GIL](https://en.wikipedia.org/wiki/Global_interpreter_lock) issue. |
0 commit comments