Skip to content

Commit

Permalink
bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
henices committed Jul 18, 2014
1 parent 83b3213 commit 29b148c
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions tcpdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,33 @@ def private_dns_response(data):
print 'domain:%s, qtype:%x' % (q_domain, qtype)
sys.stdout.flush()

if qtype != 0x0001:
return None

if Questions != '\x00\x01' or AnswerRRs != '\x00\x00' or \
AuthorityRRs != '\x00\x00' or AdditionalRRs != '\x00\x00':
return None

items = cfg['private_host'].items()

for domain, ip in items:
if fnmatch(q_domain, domain):
ret = TID
ret += '\x81\x80'
ret += '\x00\x01'
ret += '\x00\x01'
ret += '\x00\x00'
ret += '\x00\x00'
ret += data[12:]
ret += '\xc0\x0c'
ret += '\x00\x01'
ret += '\x00\x01'
ret += '\x00\x00\xff\xff'
ret += '\x00\x04'
ret += socket.inet_aton(ip)

return ret
try:
if qtype != 0x0001:
return

if Questions != '\x00\x01' or AnswerRRs != '\x00\x00' or \
AuthorityRRs != '\x00\x00' or AdditionalRRs != '\x00\x00':
return

items = cfg['private_host'].items()

for domain, ip in items:
if fnmatch(q_domain, domain):
ret = TID
ret += '\x81\x80'
ret += '\x00\x01'
ret += '\x00\x01'
ret += '\x00\x00'
ret += '\x00\x00'
ret += data[12:]
ret += '\xc0\x0c'
ret += '\x00\x01'
ret += '\x00\x01'
ret += '\x00\x00\xff\xff'
ret += '\x00\x04'
ret += socket.inet_aton(ip)
finally:
return (q_domain, ret)


def check_dns_packet(data):
Expand Down Expand Up @@ -199,7 +200,7 @@ def transfer(querydata, addr, server):
t_id = querydata[:2]
key = querydata[2:].encode('hex')

response = private_dns_response(querydata)
q_domain, response = private_dns_response(querydata)
if response:
server.sendto(response, addr)
return
Expand Down Expand Up @@ -232,7 +233,7 @@ def transfer(querydata, addr, server):
break

if response is None:
print "[ERROR] Tried many times and failed to resolve %s" % domain
print "[ERROR] Tried many times and failed to resolve %s" % q_domain


class ThreadedUDPServer(SocketServer.ThreadingMixIn, SocketServer.UDPServer):
Expand Down

0 comments on commit 29b148c

Please sign in to comment.