From c45606562bc5d53438ce6672e173c4533f8f49ba Mon Sep 17 00:00:00 2001 From: downature Date: Thu, 26 Jan 2017 09:47:32 +0000 Subject: [PATCH 1/8] Update dns.py --- bin/dns.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/dns.py b/bin/dns.py index 03935ae..2eac9f3 100644 --- a/bin/dns.py +++ b/bin/dns.py @@ -4,6 +4,7 @@ import threading import json import base64 +import logging dict_data = {} dict_config = {} @@ -63,7 +64,7 @@ def SendDnsData(data,s,addr): try: rspdata = sock.recv(4096) except Exception as e: - print "sock.recv info:",e + logging.warn("sock.recv info:%s"%e) break s.sendto(rspdata ,addr) break @@ -74,7 +75,7 @@ def main(s): data, addr = s.recvfrom(2048) Tthreading(data,s,addr) except Exception as e: - print "Unknow error :\t",e + logging.warn("Unknow error:%s"%e) if __name__ == '__main__': @@ -92,6 +93,7 @@ def main(s): except Exception as e: print "\nBinding failed! Please run as administrator,\n\nAnd check the local IP address and port is correct?\n" print "==========Error message==========" - raise e + logging.critical(e) + sys.exit(-1) print "Bind successfully! Running ..." main(s) From f8ae1175e53334574219bb01e5661df6a2e28bf1 Mon Sep 17 00:00:00 2001 From: downature Date: Thu, 26 Jan 2017 09:48:37 +0000 Subject: [PATCH 2/8] 0.23 --- bin/dnslib/dnsfucation.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bin/dnslib/dnsfucation.py b/bin/dnslib/dnsfucation.py index 2cf4206..5621076 100644 --- a/bin/dnslib/dnsfucation.py +++ b/bin/dnslib/dnsfucation.py @@ -1,4 +1,5 @@ # -*- coding:utf-8 -*- +import logging def Search_key_ip(string,dict_data): string = string[:-1] @@ -19,13 +20,13 @@ def Hex2Ascii(string): Int = int(string,16) return chr(Int) except Exception as e: - print "Hex2Ascii info:\t",e + logging.warn("Hex2Ascii info:\t%s"%e) def Hex2Str_dec(string): try: return str(int(string,16)) except Exception as e: - print "Hex2Str_dec info:\t",e + logging.warn("Hex2Str_dec info:\t%s"%e) def HexIP2DecIP(string) : string = string.replace('\t','').replace('\n','').replace(' ','') @@ -36,7 +37,7 @@ def HexIP2DecIP(string) : else: return "?.?.?.?" except Exception as e: - print "HexIP2DecIP info:\t",e + logging("HexIP2DecIP info:\t%s"%e) def DnshextoDomain(string,start=24,end=26): '''原始数据:域名指针默认在24-26个字节位置, @@ -57,7 +58,7 @@ def DnshextoDomain(string,start=24,end=26): end +=2 return ''.join(Domain),end except Exception as e: - print "DnshextoDomain info:\t",e + logging.warn("DnshextoDomain info:\t%s"%e) def GetDnsDomainIP(data): '''提取域名和IP @@ -92,7 +93,7 @@ def GetDnsDomainIP(data): return iptext except Exception as e: - print "GetDnsDomainIP info:\t",e + logging("GetDnsDomainIP info:\t%s"%e) return [] def analysis(data,dict_data): @@ -119,7 +120,7 @@ def analysis2(data,dict_data): ip = None if len(domain) >0: - print "Query:\t",domain + logging("Query:\t%s"%domain) ip = Search_key_ip(domain,dict_data) if ip : if data[end+2:end+4] == '1c': @@ -130,7 +131,7 @@ def analysis2(data,dict_data): data = data[0:4] + '81800001000100000000'+data[24:end]+'00010001c00c000100010000003f0004' #十进制表示的IP变为十六进制表示的IP dnsip = '{:02X}{:02X}{:02X}{:02X}'.format(*map(int, ip.split('.'))).lower() - print "Revise:\t",domain + logging("Revise:\t%s"%domain) data = data + dnsip return 1,data.decode('hex') return 0,data.decode('hex') From e3cd7baba24f91be3562a57857917eb577f70aef Mon Sep 17 00:00:00 2001 From: downature Date: Thu, 26 Jan 2017 10:21:31 +0000 Subject: [PATCH 3/8] 0.23 --- bin/dns.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/dns.py b/bin/dns.py index 2eac9f3..4115a40 100644 --- a/bin/dns.py +++ b/bin/dns.py @@ -6,6 +6,7 @@ import base64 import logging +logging.basicConfig(level=logging.INFO) dict_data = {} dict_config = {} Remote_dns_server='114.114.114.114' @@ -64,7 +65,7 @@ def SendDnsData(data,s,addr): try: rspdata = sock.recv(4096) except Exception as e: - logging.warn("sock.recv info:%s"%e) + logging.warn("sock.recv info:\t%s"%e) break s.sendto(rspdata ,addr) break @@ -75,7 +76,7 @@ def main(s): data, addr = s.recvfrom(2048) Tthreading(data,s,addr) except Exception as e: - logging.warn("Unknow error:%s"%e) + logging.warn("Unknow error:\t%s"%e) if __name__ == '__main__': From 567777e824d25a1cf4177b48d22a0b682a8c8368 Mon Sep 17 00:00:00 2001 From: downature Date: Thu, 26 Jan 2017 11:14:38 +0000 Subject: [PATCH 4/8] 0.23 --- bin/dnslib/dnsfucation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/dnslib/dnsfucation.py b/bin/dnslib/dnsfucation.py index 5621076..53daf12 100644 --- a/bin/dnslib/dnsfucation.py +++ b/bin/dnslib/dnsfucation.py @@ -1,6 +1,6 @@ # -*- coding:utf-8 -*- import logging - +logging.basicConfig(level=logging.INFO) def Search_key_ip(string,dict_data): string = string[:-1] if string in dict_data.keys(): @@ -120,7 +120,7 @@ def analysis2(data,dict_data): ip = None if len(domain) >0: - logging("Query:\t%s"%domain) + logging.info("Query:\t%s"%domain) ip = Search_key_ip(domain,dict_data) if ip : if data[end+2:end+4] == '1c': @@ -131,7 +131,7 @@ def analysis2(data,dict_data): data = data[0:4] + '81800001000100000000'+data[24:end]+'00010001c00c000100010000003f0004' #十进制表示的IP变为十六进制表示的IP dnsip = '{:02X}{:02X}{:02X}{:02X}'.format(*map(int, ip.split('.'))).lower() - logging("Revise:\t%s"%domain) + logging.info("Revise:\t%s"%domain) data = data + dnsip return 1,data.decode('hex') return 0,data.decode('hex') From 811feb31c0e6e21f820f240c487a6fa25ee02652 Mon Sep 17 00:00:00 2001 From: downature Date: Thu, 26 Jan 2017 11:16:16 +0000 Subject: [PATCH 5/8] Update data.json --- conf/data.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conf/data.json b/conf/data.json index 56837fb..164ffd9 100644 --- a/conf/data.json +++ b/conf/data.json @@ -1,7 +1,8 @@ { "hosts":{ "racaljk":"https://coding.net/u/scaffrey/p/hosts/git/raw/master/hosts", - "yhosts":"https://raw.githubusercontent.com/vokins/yhosts/master/hosts" + "yhosts":"https://raw.githubusercontent.com/vokins/yhosts/master/hosts", + "adaway":"https://raw.githubusercontent.com/aoccin/adaway/master/hosts" }, "DNSMasq":"I'm too lazy, you know", "jsonb64":"https://raw.githubusercontent.com/dowsnature/dowsDNS/master/data/wrcd.base64" From 0f02cc2f1ae144c83b86769bfa1e01a834fd3b7e Mon Sep 17 00:00:00 2001 From: downature Date: Thu, 26 Jan 2017 11:17:12 +0000 Subject: [PATCH 6/8] 0.23.1 --- bin/dns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/dns.py b/bin/dns.py index 4115a40..8010c89 100644 --- a/bin/dns.py +++ b/bin/dns.py @@ -65,7 +65,7 @@ def SendDnsData(data,s,addr): try: rspdata = sock.recv(4096) except Exception as e: - logging.warn("sock.recv info:\t%s"%e) + logging.warn("Recv:\t%s"%e) break s.sendto(rspdata ,addr) break From cb2fbf3bf01d0c382d482caf83c5dbfbe11daee5 Mon Sep 17 00:00:00 2001 From: downature Date: Mon, 30 Jan 2017 06:02:52 +0000 Subject: [PATCH 7/8] 0.23.2 Fix zero length field name in format bug https://github.com/dowsnature/dowsDNS/issues/4 --- bin/dnslib/dnsfucation.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/dnslib/dnsfucation.py b/bin/dnslib/dnsfucation.py index 53daf12..3578b04 100644 --- a/bin/dnslib/dnsfucation.py +++ b/bin/dnslib/dnsfucation.py @@ -113,6 +113,13 @@ def analysis(data,dict_data): data = data.encode('hex').replace(iplist[i],dnsip).decode('hex') return data +def IP2HEX(ip): + zone = ip.split(".") + HEX = '' + for i in zone: + HEX += hex(int(i)).replace("0x",'') + return HEX + def analysis2(data,dict_data): '''构造DNS报文''' data = data.encode('hex') @@ -130,7 +137,8 @@ def analysis2(data,dict_data): data = data[0:4] + '81800001000100000000'+data[24:end]+'00010001c00c000100010000003f0004' #十进制表示的IP变为十六进制表示的IP - dnsip = '{:02X}{:02X}{:02X}{:02X}'.format(*map(int, ip.split('.'))).lower() + #dnsip = '{:02X}{:02X}{:02X}{:02X}'.format(*map(int, ip.split('.'))).lower() + dnsip = IP2HEX(ip) logging.info("Revise:\t%s"%domain) data = data + dnsip return 1,data.decode('hex') From 23bab5ab1f2cda30d9132bc7798f8f04b7e4fb6f Mon Sep 17 00:00:00 2001 From: downature Date: Mon, 30 Jan 2017 06:17:41 +0000 Subject: [PATCH 8/8] 0.23.3 --- bin/dnslib/dnsfucation.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/dnslib/dnsfucation.py b/bin/dnslib/dnsfucation.py index 3578b04..b3df0e2 100644 --- a/bin/dnslib/dnsfucation.py +++ b/bin/dnslib/dnsfucation.py @@ -117,7 +117,10 @@ def IP2HEX(ip): zone = ip.split(".") HEX = '' for i in zone: - HEX += hex(int(i)).replace("0x",'') + i = hex(int(i)).replace("0x",'') + if len(i) < 2: + i = '0' + i + HEX += i return HEX def analysis2(data,dict_data):