Skip to content

Commit

Permalink
Merge pull request #8 from nimatrueway/master
Browse files Browse the repository at this point in the history
Update and make it compatible with python3.6
  • Loading branch information
robputt authored Jan 30, 2018
2 parents b574310 + b2821c5 commit 58cd2d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
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

0 comments on commit 58cd2d2

Please sign in to comment.