Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and make it compatible with python3.6 #8

Merged
merged 1 commit into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Py-DNS-over-HTTPS-Proxy
Provides a simple Python based proxy for running DNS over HTTPS to Google's DNS over HTTPS service.

Recently I wrote a blog post which probably gives you just enough information to get this up and running on a Mac / Linux box... https://robertputt.co.uk/securing-dns-traffic-with-dns-over-https.html, please note this script only seems to play nice with Python2.7 not Python 3.x
Recently I wrote a blog post which probably gives you just enough information to get this up and running on a Mac / Linux box... https://robertputt.co.uk/securing-dns-traffic-with-dns-over-https.html, This script plays nice with both Python2.7 and Python 3.x

Configuration can be easily done with virtualenv:

```
virtualenv dns_proxy
cd dns_proxy/
source bin/activate
pip install dnslib requests
pip install configparser dnslib requests
git clone https://github.com/robputt796/Py-DNS-over-HTTPS-Proxy.git
cat Py-DNS-over-HTTPS-Proxy/https_dns_proxy/config.ini
python Py-DNS-over-HTTPS-Proxy/https_dns_proxy/__init__.py &
Expand Down
16 changes: 8 additions & 8 deletions https_dns_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import base64
import os
import datetime
import ConfigParser
from configparser import ConfigParser
import sys
from dnslib.server import DNSServer
from dnslib.server import BaseResolver
Expand All @@ -14,10 +14,10 @@
from dnslib import QTYPE

# read from config.ini
myconfig = ConfigParser.ConfigParser()
myconfig = ConfigParser()
config_name = 'config.ini'
config_path = os.path.join(sys.path[0], config_name)
myconfig.readfp(open(config_path))
myconfig.read_file(open(config_path))

if len(sys.argv) == 2:
ENVIRONMENT=str(sys.argv[1])
Expand Down Expand Up @@ -58,16 +58,16 @@ def new_HTTPAdapter_build_response(self, request, resp):
class HTTPSResolver(BaseResolver):

def resolve(self, request, handler):
hostname = '.'.join(request.q.qname.label)
hostname = str(request.q.qname)
ltype = request.q.qtype
headers = {"Host": "dns.google.com"}

try:
if CACHE[hostname]['dt'] > datetime.datetime.now() - datetime.timedelta(minutes=30):
print "Cache Hit: %s" % hostname
print("Cache Hit: %s" % hostname)
answer = CACHE[hostname][ltype]
else:
print "Cache Expired: %s" % hostname
print("Cache Expired: %s" % hostname)
del CACHE[hostname]
raise Exception("Cache Expired")
except:
Expand All @@ -78,7 +78,7 @@ def resolve(self, request, handler):
verify=False)

if PINNED_CERT != lookup_resp.peercert:
print lookup_resp.peercert
print(lookup_resp.peercert)
if EXIT_ON_MITM:
print ("ERROR: REMOTE SSL CERT DID NOT MATCH EXPECTED (PINNED) "
"SSL CERT, EXITING IN CASE OF MAN IN THE MIDDLE ATTACK")
Expand All @@ -91,7 +91,7 @@ def resolve(self, request, handler):

if lookup_resp.status_code == 200:
try:
print "Cache Miss: %s" % hostname
print("Cache Miss: %s" % hostname)
answer = json.loads(lookup_resp.text)['Answer']
CACHE[hostname] = {ltype: answer, "dt": datetime.datetime.now()}
except:
Expand Down