Added IPv6 support, Added support for multiple response queries
This commit is contained in:
parent
f79cc000f7
commit
74edb49492
43
main.py
43
main.py
@ -15,14 +15,33 @@ class bcolors:
|
|||||||
# REGEX Magic, how does it work
|
# REGEX Magic, how does it work
|
||||||
IPV4SEG = r'(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])'
|
IPV4SEG = r'(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])'
|
||||||
IPV4ADDR = r'(?:(?:' + IPV4SEG + r'\.){3,3}' + IPV4SEG + r')'
|
IPV4ADDR = r'(?:(?:' + IPV4SEG + r'\.){3,3}' + IPV4SEG + r')'
|
||||||
|
IPV6SEG = r'(?:(?:[0-9a-fA-F]){1,4})'
|
||||||
|
IPV6GROUPS = (
|
||||||
|
r'(?:' + IPV6SEG + r':){7,7}' + IPV6SEG, # 1:2:3:4:5:6:7:8
|
||||||
|
r'(?:' + IPV6SEG + r':){1,7}:', # 1:: 1:2:3:4:5:6:7::
|
||||||
|
r'(?:' + IPV6SEG + r':){1,6}:' + IPV6SEG, # 1::8 1:2:3:4:5:6::8 1:2:3:4:5:6::8
|
||||||
|
r'(?:' + IPV6SEG + r':){1,5}(?::' + IPV6SEG + r'){1,2}', # 1::7:8 1:2:3:4:5::7:8 1:2:3:4:5::8
|
||||||
|
r'(?:' + IPV6SEG + r':){1,4}(?::' + IPV6SEG + r'){1,3}', # 1::6:7:8 1:2:3:4::6:7:8 1:2:3:4::8
|
||||||
|
r'(?:' + IPV6SEG + r':){1,3}(?::' + IPV6SEG + r'){1,4}', # 1::5:6:7:8 1:2:3::5:6:7:8 1:2:3::8
|
||||||
|
r'(?:' + IPV6SEG + r':){1,2}(?::' + IPV6SEG + r'){1,5}', # 1::4:5:6:7:8 1:2::4:5:6:7:8 1:2::8
|
||||||
|
IPV6SEG + r':(?:(?::' + IPV6SEG + r'){1,6})', # 1::3:4:5:6:7:8 1::3:4:5:6:7:8 1::8
|
||||||
|
r':(?:(?::' + IPV6SEG + r'){1,7}|:)', # ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::
|
||||||
|
r'fe80:(?::' + IPV6SEG + r'){0,4}%[0-9a-zA-Z]{1,}', # fe80::7:8%eth0 fe80::7:8%1 (link-local IPv6 addresses with zone index)
|
||||||
|
r'::(?:ffff(?::0{1,4}){0,1}:){0,1}[^\s:]' + IPV4ADDR, # ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255 (IPv4-mapped IPv6 addresses and IPv4-translated addresses)
|
||||||
|
r'(?:' + IPV6SEG + r':){1,4}:[^\s:]' + IPV4ADDR, # 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 (IPv4-Embedded IPv6 Address)
|
||||||
|
)
|
||||||
|
IPV6ADDR = '|'.join(['(?:{})'.format(g) for g in IPV6GROUPS[::-1]]) # Reverse rows for greedy match
|
||||||
|
regex4 = re.compile(IPV4ADDR)
|
||||||
|
regex6 = re.compile(IPV6ADDR)
|
||||||
class DoTProxy:
|
class DoTProxy:
|
||||||
def resolve(self,request,handler):
|
def resolve(self,request,handler):
|
||||||
reply = request.reply()
|
reply = request.reply()
|
||||||
print(bcolors.WARNING, request.q.qname, str(QTYPE[request.q.qtype]), bcolors.RESET)
|
print(bcolors.WARNING, request.q.qname, str(QTYPE[request.q.qtype]), bcolors.RESET)
|
||||||
IP = DoTquery(str(request.q.qname), QTYPE[request.q.qtype])
|
IP = DoTquery(str(request.q.qname), QTYPE[request.q.qtype])
|
||||||
query_response = str(request.q.qname)+" "+str(ttl)+" "+str(QTYPE[request.q.qtype])+" "+IP
|
for i in range(len(IP)):
|
||||||
print(str(query_response))
|
query_response = str(request.q.qname)+" "+str(ttl)+" "+str(QTYPE[request.q.qtype])+" "+IP[i]
|
||||||
reply.add_answer(*RR.fromZone(query_response))
|
print(str(query_response))
|
||||||
|
reply.add_answer(*RR.fromZone(query_response))
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
#Setup DNS server, this will listen for incoming DNS packets
|
#Setup DNS server, this will listen for incoming DNS packets
|
||||||
@ -33,22 +52,22 @@ server = server.DNSServer(resolver,port=53,address="0.0.0.0",logger=logger, tcp=
|
|||||||
# Query upstream DoH server
|
# Query upstream DoH server
|
||||||
def DoTquery(domain, query_type):
|
def DoTquery(domain, query_type):
|
||||||
#response = pythonDoh.client.query(str(domain), type=str(query_type), server="calebfontenot.com", verbose=True, fallback=False)
|
#response = pythonDoh.client.query(str(domain), type=str(query_type), server="calebfontenot.com", verbose=True, fallback=False)
|
||||||
if str(domain) == "conntest.nintendowifi.net.":
|
if "nintendowifi.net." in str(domain):
|
||||||
print("bruh moment")
|
print(bcolors.FAIL+"Intercepted query!"+bcolors.RESET)
|
||||||
return "172.104.88.237"
|
return ["172.104.88.237"]
|
||||||
else:
|
else:
|
||||||
q = dns.message.make_query(str(domain), str(query_type))
|
q = dns.message.make_query(str(domain), str(query_type))
|
||||||
response = dns.query.tls(q, "74.80.18.217", server_hostname="calebfontenot.com", port=853)
|
response = dns.query.tls(q, "74.80.18.217", server_hostname="calebfontenot.com", port=853)
|
||||||
print(response)
|
print(response)
|
||||||
# There's probably a better way of doing this, but I can't figure it out...
|
# There's probably a better way of doing this, but I can't figure it out...
|
||||||
if str(query_type) == "A":
|
if str(query_type) == "A":
|
||||||
regex = re.compile(IPV4ADDR)
|
IP = regex4.findall(str(response.answer))
|
||||||
IP = regex.findall(str(response.answer))
|
|
||||||
print(bcolors.OK+"IP is", str(IP[0])+bcolors.RESET)
|
print(bcolors.OK+"IP is", str(IP[0])+bcolors.RESET)
|
||||||
elif str(query_type) == "AAAA":
|
elif str(query_type) == "AAAA":
|
||||||
print("Not implemented yet!")
|
IP = regex6.findall(str(response.answer))
|
||||||
|
#print("Not implemented yet!")
|
||||||
else:
|
else:
|
||||||
return("Queries beyond A or AAAA are not implemented")
|
print(bcolors.FAIL+"Queries beyond A or AAAA are not implemented"+bcolors.RESET)
|
||||||
return IP[0]
|
return IP
|
||||||
#server.start_thread()
|
#server.start_thread()
|
||||||
server.start()
|
server.start()
|
Loading…
Reference in New Issue
Block a user