From e8181ab8211758a1384c8f017ecb3c2fd3eb1a97 Mon Sep 17 00:00:00 2001 From: RyanC Date: Thu, 11 Dec 2014 16:22:49 -0800 Subject: [PATCH 01/12] remove commit 428f2e25 --- plugin/pluginDns.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/plugin/pluginDns.py b/plugin/pluginDns.py index 814a5cf..6b74a9a 100644 --- a/plugin/pluginDns.py +++ b/plugin/pluginDns.py @@ -144,7 +144,7 @@ def getIp6(self, domain): result = self._getRecordForRPC(domain, 'getIp6') # if we got an NS record because there is no IP we need to ask the NS server for the IP if self.conf['disable_ns_lookups'] != '1': - if "ns" in result: + if result == '["ns"]': if(domain.endswith('_ip6.bit')): domain = domain[:-8] + 'bit' @@ -256,18 +256,6 @@ def _getIPv4FromNS(self,domain): def _getIPv6FromNS(self,domain): #28 is the AAAA record server = self._getNSServer(domain) - - translate = self.getTranslate(domain) - - if translate != '[]': - try: - translate = json.loads(translate) - except: - if app['debug']: traceback.print_exc() - return - - domain = translate[0].rstrip('.') - return app['services']['dns']._lookup(domain, 28 , server)[0]['data'] def _getSubDomainTlsFingerprint(self,domain,protocol,port): From b6fb7949d024b9109bd26c52c629fe9847133228 Mon Sep 17 00:00:00 2001 From: RyanC Date: Thu, 11 Dec 2014 16:29:05 -0800 Subject: [PATCH 02/12] remove commit 92529dee --- plugin/pluginDns.py | 17 +---------------- plugin/pluginNamespaceDomain.py | 6 ------ 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/plugin/pluginDns.py b/plugin/pluginDns.py index 6b74a9a..14cc783 100644 --- a/plugin/pluginDns.py +++ b/plugin/pluginDns.py @@ -129,7 +129,7 @@ def getIp4(self, domain): result = self._getRecordForRPC(domain, 'getIp4') # if we got an NS record because there is no IP we need to ask the NS server for the IP if self.conf['disable_ns_lookups'] != '1': - if "ns" in result: + if result == '["ns"]': if(domain.endswith('_ip4.bit')): domain = domain[:-8] + 'bit' @@ -218,9 +218,6 @@ def getTlsFingerprint(self, domain, protocol, port): def getNS(self, domain): return self._getRecordForRPC(domain, 'getNS') - def getTranslate(self, domain): - return self._getRecordForRPC(domain, 'getTranslate') - def _getTls(self, domain): return self._getRecordForRPC(domain, 'getTls') @@ -239,18 +236,6 @@ def _getNSServer(self,domain): def _getIPv4FromNS(self,domain): #1 is the A record server = self._getNSServer(domain) - - translate = self.getTranslate(domain) - - if translate != '[]': - try: - translate = json.loads(translate) - except: - if app['debug']: traceback.print_exc() - return - - domain = translate[0].rstrip('.') - return app['services']['dns']._lookup(domain, 1 , server)[0]['data'] def _getIPv6FromNS(self,domain): diff --git a/plugin/pluginNamespaceDomain.py b/plugin/pluginNamespaceDomain.py index f3a0010..992fd51 100644 --- a/plugin/pluginNamespaceDomain.py +++ b/plugin/pluginNamespaceDomain.py @@ -24,7 +24,6 @@ class pluginNamespaceDomain(plugin.PluginThread): 'getFingerprint': 'fingerprint', 'getTls': 'tls', 'getNS' : 'ns', - 'getTranslate' : 'translate', } def pLoadconfig(self): @@ -127,11 +126,6 @@ def _fetchNamecoinData(self, domain, recType, subdoms, data, result): result.add(domain, recType, data) return True - # ns record in a dictionary, potentially with the translate option - if recType == 'ip' and 'ns' in data: - result.add(domain, recType, data) - return True - # legacy compatibility with "" in map instead of root if recType == 'ip' and 'map' in data and '' in data['map']: result.add(domain, recType, data['map']['']) From 998122a15db41864287488a0885d554e043f41a3 Mon Sep 17 00:00:00 2001 From: RyanC Date: Thu, 11 Dec 2014 16:30:31 -0800 Subject: [PATCH 03/12] remove commit 5952b64d --- lib/dnsServer/namecoindns.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/dnsServer/namecoindns.py b/lib/dnsServer/namecoindns.py index f702938..228714a 100644 --- a/lib/dnsServer/namecoindns.py +++ b/lib/dnsServer/namecoindns.py @@ -93,8 +93,6 @@ def get_response(self, query, domain, qtype, qclass, src_addr): elif qtype == 28: #answer = struct.pack("!I", ipstr2int(value)) reqtype = "AAAA" - elif qtype == 52: - reqtype = "TLSA" else : reqtype = None answers = app['services']['dns'].lookup({"query":query, "domain":domain, "qtype":qtype, "qclass":qclass, "src_addr":src_addr}) #print 'domain:', domain @@ -120,11 +118,6 @@ def get_response(self, query, domain, qtype, qclass, src_addr): tempresults["rdata"] = tempresult elif response["type"] == 28 : tempresults["rdata"] = response["data"] - elif response["type"] == 52 : - tempresult = '\x03\x00' - tempresult += chr(int(response["data"][0][0])) - tempresult += bytearray.fromhex(response["data"][0][1]) - tempresults["rdata"] = tempresult #else : return 3, [] results.append(tempresults) return 0, results @@ -164,8 +157,6 @@ def get_response(self, query, domain, qtype, qclass, src_addr): return self.get_response(query, domain, 5, qclass, src_addr) #tempresults["rdata"] = struct.pack("!I", ipstr2int(response["data"])) tempresults["rdata"] = response["data"] - elif response["type"] == 52 : - tempresults["rdata"] = response["data"] #else : return 3, [] results.append(tempresults) return 0, results From 53bcc40aa00a8b92bda0d375a2bcfb08695d0af2 Mon Sep 17 00:00:00 2001 From: RyanC Date: Thu, 11 Dec 2014 16:33:17 -0800 Subject: [PATCH 04/12] remove commit a3028e15 --- plugin/pluginDns.py | 27 ++++++++++++--------------- service/serviceDNS.py | 3 --- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/plugin/pluginDns.py b/plugin/pluginDns.py index 14cc783..215864c 100644 --- a/plugin/pluginDns.py +++ b/plugin/pluginDns.py @@ -45,7 +45,6 @@ class pluginDns(plugin.PluginThread): name = 'dns' options = { 'start': ['Launch at startup', 1], - 'disable_ns_lookups': ['Disable remote lookups for NS records','0'], #'host': ['Listen on ip', '127.0.0.1'], #'port': ['Listen on port', 53], #'resolver': ['Forward standard requests to', '8.8.8.8,8.8.4.4'], @@ -128,30 +127,28 @@ def _getRecordForRPC(self, domain, recType): def getIp4(self, domain): result = self._getRecordForRPC(domain, 'getIp4') # if we got an NS record because there is no IP we need to ask the NS server for the IP - if self.conf['disable_ns_lookups'] != '1': - if result == '["ns"]': + if result == '["ns"]': - if(domain.endswith('_ip4.bit')): - domain = domain[:-8] + 'bit' - if(domain.endswith('_ip.bit')): - domain = domain[:-7] + 'bit' + if(domain.endswith('_ip4.bit')): + domain = domain[:-8] + 'bit' + if(domain.endswith('_ip.bit')): + domain = domain[:-7] + 'bit' - result = '["'+self._getIPv4FromNS(domain)+'"]' + result = '["'+self._getIPv4FromNS(domain)+'"]' return result def getIp6(self, domain): result = self._getRecordForRPC(domain, 'getIp6') # if we got an NS record because there is no IP we need to ask the NS server for the IP - if self.conf['disable_ns_lookups'] != '1': - if result == '["ns"]': + if result == '["ns"]': - if(domain.endswith('_ip6.bit')): - domain = domain[:-8] + 'bit' - if(domain.endswith('_ip.bit')): - domain = domain[:-7] + 'bit' + if(domain.endswith('_ip6.bit')): + domain = domain[:-8] + 'bit' + if(domain.endswith('_ip.bit')): + domain = domain[:-7] + 'bit' - result = '["'+self._getIPv6FromNS(domain)+'"]' + result = '["'+self._getIPv6FromNS(domain)+'"]' return result diff --git a/service/serviceDNS.py b/service/serviceDNS.py index c96bbe4..2d3e178 100644 --- a/service/serviceDNS.py +++ b/service/serviceDNS.py @@ -11,7 +11,6 @@ class serviceDNS(plugin.PluginThread): 'host': ['Listen on ip', '127.0.0.1'], 'port': ['Listen on port', 53], 'resolver': ['Forward standard requests to', '8.8.8.8,8.8.4.4'], - 'disable_standard_lookups': ['Disable lookups for standard domains','0'] } srv = None @@ -37,8 +36,6 @@ def lookup(self, qdict) : # return app['plugins'][service].lookup(qdict) if qdict["domain"].endswith(".bit") or qdict["domain"].endswith(".tor"): return app['plugins']['domain'].lookup(qdict) - if self.conf['disable_standard_lookups'] == '1': - return [] return self._lookup(qdict["domain"],qdict["qtype"]) def _lookup(self, domain, qtype=1, server = ''): From f5211bdff355378e997e4c751cad6dd172abf19e Mon Sep 17 00:00:00 2001 From: RyanC Date: Thu, 11 Dec 2014 16:37:56 -0800 Subject: [PATCH 05/12] remove commit 48024e68 --- lib/dnsServer/namecoindns.py | 4 ++-- plugin/pluginNamespaceDomain.py | 1 + service/serviceDNS.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/dnsServer/namecoindns.py b/lib/dnsServer/namecoindns.py index 228714a..ba6f507 100644 --- a/lib/dnsServer/namecoindns.py +++ b/lib/dnsServer/namecoindns.py @@ -111,7 +111,7 @@ def get_response(self, query, domain, qtype, qclass, src_addr): elif response["type"] == 2 or response["type"] == 5: tempresults["rdata"] = labels2str(response["data"].split(".")) elif response["type"] == 16 : - tempresults["rdata"] = labels2str(response["data"]) + tempresults["rdata"] = label2str(response["data"]) elif response["type"] == 15 : tempresult = struct.pack("!H", response["data"][0]) tempresult += labels2str(response["data"][1].split(".")) @@ -147,7 +147,7 @@ def get_response(self, query, domain, qtype, qclass, src_addr): elif response["type"] == 2 or response["type"] == 5: tempresults["rdata"] = labels2str(response["data"].split(".")) elif response["type"] == 16 : - tempresults["rdata"] = labels2str(response["data"]) + tempresults["rdata"] = label2str(response["data"]) elif response["type"] == 15 : tempresult = struct.pack("!H", response["data"][0]) tempresult += labels2str(response["data"][1].split(".")) diff --git a/plugin/pluginNamespaceDomain.py b/plugin/pluginNamespaceDomain.py index 992fd51..ec369a4 100644 --- a/plugin/pluginNamespaceDomain.py +++ b/plugin/pluginNamespaceDomain.py @@ -185,6 +185,7 @@ def _expandSelectedRecord(self, nameData, subDoms, limit = maxNestedCalls): return nameData def lookup(self, qdict) : + if qdict["domain"].endswith(".bit"): return self._bitLookup(qdict) diff --git a/service/serviceDNS.py b/service/serviceDNS.py index 2d3e178..4a2f85c 100644 --- a/service/serviceDNS.py +++ b/service/serviceDNS.py @@ -36,9 +36,9 @@ def lookup(self, qdict) : # return app['plugins'][service].lookup(qdict) if qdict["domain"].endswith(".bit") or qdict["domain"].endswith(".tor"): return app['plugins']['domain'].lookup(qdict) - return self._lookup(qdict["domain"],qdict["qtype"]) + return self._lookup(qdict) - def _lookup(self, domain, qtype=1, server = ''): + def _lookup(self, domain, qtype='1', server = ''): #make sure the server string is a string and not unicode, otherwise the DNS library fails to resolve it server = str(server) From ea75427e00c1379ac49319d35966b607ed1989bf Mon Sep 17 00:00:00 2001 From: RyanC Date: Thu, 11 Dec 2014 16:39:24 -0800 Subject: [PATCH 06/12] remove commit 75be6c82 --- lib/dnsServer/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/dnsServer/__init__.py b/lib/dnsServer/__init__.py index 35077bc..c842dca 100644 --- a/lib/dnsServer/__init__.py +++ b/lib/dnsServer/__init__.py @@ -189,7 +189,8 @@ def format_question(question, qtype, qclass): def format_resource(resource, question): r = '' r += labels2str(question) - r += struct.pack("!HHIH", resource['qtype'], resource['qclass'], resource['ttl'], len(resource['rdata'])) + r += struct.pack("!HHI", resource['qtype'], resource['qclass'], resource['ttl']) + r += struct.pack("!H", len(resource['rdata'] )) r += resource['rdata'] return r From 648dc0ab025d28866938dd9700026fd9dbc79391 Mon Sep 17 00:00:00 2001 From: RyanC Date: Thu, 11 Dec 2014 16:45:45 -0800 Subject: [PATCH 07/12] remove commit 59633337 --- lib/dnsServer/__init__.py | 6 +++++- lib/dnsServer/namecoindns.py | 4 +++- plugin/pluginNamespaceDomain.py | 38 +++++++++++++++------------------ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/dnsServer/__init__.py b/lib/dnsServer/__init__.py index c842dca..4ae1114 100644 --- a/lib/dnsServer/__init__.py +++ b/lib/dnsServer/__init__.py @@ -190,7 +190,11 @@ def format_resource(resource, question): r = '' r += labels2str(question) r += struct.pack("!HHI", resource['qtype'], resource['qclass'], resource['ttl']) - r += struct.pack("!H", len(resource['rdata'] )) + # change the format of the response if its a TXT response, otherwise assume it is an A record + if resource['qtype'] == 16: + r += struct.pack("!HB", len(resource['rdata']) + 1 , len(resource['rdata'] )) + else: + r += struct.pack("!H", len(resource['rdata'] )) r += resource['rdata'] return r diff --git a/lib/dnsServer/namecoindns.py b/lib/dnsServer/namecoindns.py index ba6f507..5e2dd68 100644 --- a/lib/dnsServer/namecoindns.py +++ b/lib/dnsServer/namecoindns.py @@ -1,4 +1,4 @@ -#name_scan "d/yourdomain" 1 +#namponse_scan "d/yourdomain" 1 import sys, os #sys.path.append('/home/khal/sources/nmcontrol/lib/') import DNS @@ -124,6 +124,8 @@ def get_response(self, query, domain, qtype, qclass, src_addr): if type(response) == types.StringType : if self.isIP(response) : return 0, [{"qtype":1, "qclass":qclass, "ttl":300, "rdata":struct.pack("!I", ipstr2int(response))}] + if response.endswith(".onion"): + return 0, [{"qtype":16, "qclass":qclass, "ttl":300, "rdata":response}] return 3, [] #if query not in self._answers: #return 3, [] diff --git a/plugin/pluginNamespaceDomain.py b/plugin/pluginNamespaceDomain.py index ec369a4..709321a 100644 --- a/plugin/pluginNamespaceDomain.py +++ b/plugin/pluginNamespaceDomain.py @@ -218,20 +218,20 @@ def _bitLookup(self,qdict): if answers != '[]': nameData = json.loads(answers) answers = str(nameData[0]) - #did we get an IP address or nothing? - if answers: - return answers - return + #did we get an IP address or nothing? + if answers: + return answers + return '[]' elif reqtype == "AAAA": #new style AAAA request answers = app['plugins']['dns'].getIp6(qdict["domain"]) if answers != '[]': nameData = json.loads(answers) answers = str(nameData[0]) - #did we get an IP address or nothing? - if answers: - return answers - return + #did we get an IP address or nothing? + if answers: + return answers + return '[]' elif reqtype == "TLSA": port = qdict["domain"].split(".")[0][1:] protocol = qdict["domain"].split(".")[1][1:] @@ -241,19 +241,15 @@ def _bitLookup(self,qdict): return def _torLookup(self,qdict): - - answers = app['plugins']['dns'].getOnion(qdict["domain"]) - if answers != '[]': - nameData = json.loads(answers) - answers = str(nameData[0]) + #if TXT record + if qdict['qtype'] == 16: + answers = app['plugins']['dns'].getOnion(qdict["domain"]) + if answers != '[]': + nameData = json.loads(answers) + answers = str(nameData[0]) #did we get an IP address or nothing? if answers: - #if TXT record - if qdict['qtype'] == 16: - return {"type":16, "class":1, "ttl":300, "data":answers} - #if A record return a CNAME - elif qdict['qtype'] == 1: - return {"type":5, "class":1, "ttl":300, "data":answers} - - return + return answers + return '[]' + return '[]' From 22862bc2963689fdbddc35428aafae00f5d9e0d3 Mon Sep 17 00:00:00 2001 From: RyanC Date: Thu, 11 Dec 2014 16:50:45 -0800 Subject: [PATCH 08/12] remove commit 851a1b32 --- lib/dnsServer/__init__.py | 7 +---- lib/dnsServer/namecoindns.py | 4 +-- plugin/pluginNamespaceDomain.py | 50 ++++++++++++++++----------------- service/serviceDNS.py | 2 +- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/lib/dnsServer/__init__.py b/lib/dnsServer/__init__.py index 4ae1114..35077bc 100644 --- a/lib/dnsServer/__init__.py +++ b/lib/dnsServer/__init__.py @@ -189,12 +189,7 @@ def format_question(question, qtype, qclass): def format_resource(resource, question): r = '' r += labels2str(question) - r += struct.pack("!HHI", resource['qtype'], resource['qclass'], resource['ttl']) - # change the format of the response if its a TXT response, otherwise assume it is an A record - if resource['qtype'] == 16: - r += struct.pack("!HB", len(resource['rdata']) + 1 , len(resource['rdata'] )) - else: - r += struct.pack("!H", len(resource['rdata'] )) + r += struct.pack("!HHIH", resource['qtype'], resource['qclass'], resource['ttl'], len(resource['rdata'])) r += resource['rdata'] return r diff --git a/lib/dnsServer/namecoindns.py b/lib/dnsServer/namecoindns.py index 5e2dd68..09c9482 100644 --- a/lib/dnsServer/namecoindns.py +++ b/lib/dnsServer/namecoindns.py @@ -121,11 +121,9 @@ def get_response(self, query, domain, qtype, qclass, src_addr): #else : return 3, [] results.append(tempresults) return 0, results - if type(response) == types.StringType : + if type(response) == types.StringType : if self.isIP(response) : return 0, [{"qtype":1, "qclass":qclass, "ttl":300, "rdata":struct.pack("!I", ipstr2int(response))}] - if response.endswith(".onion"): - return 0, [{"qtype":16, "qclass":qclass, "ttl":300, "rdata":response}] return 3, [] #if query not in self._answers: #return 3, [] diff --git a/plugin/pluginNamespaceDomain.py b/plugin/pluginNamespaceDomain.py index 709321a..1c97620 100644 --- a/plugin/pluginNamespaceDomain.py +++ b/plugin/pluginNamespaceDomain.py @@ -10,7 +10,7 @@ class pluginNamespaceDomain(plugin.PluginThread): #'resolver': ['Forward standard requests to', '8.8.8.8,8.8.4.4'], } depends = {'plugins': ['data', 'dns'],'services': ['dns']} - filters = {'dns': '.bit$|.tor$'} + filters = {'dns': '.bit$'} handle = ['dns'] maxNestedCalls = 10 @@ -183,17 +183,31 @@ def _expandSelectedRecord(self, nameData, subDoms, limit = maxNestedCalls): #print "* nameData:", nameData return nameData - + + def domainToNamespace(self, domain): + if domain.count(".") >= 2 : + host = ".".join(domain.split(".")[-2:-1]) + subdomain = ".".join(domain.split(".")[:-2]) + else : + host = domain.split(".")[0] + subdomain = "" + return 'd/'+host, host, subdomain + + def namespaceToDomain(self, name): + pass + def lookup(self, qdict) : - - if qdict["domain"].endswith(".bit"): - return self._bitLookup(qdict) - - if qdict["domain"].endswith(".tor"): - return self._torLookup(qdict) - - - def _bitLookup(self,qdict): + #dns = app['services']['dns'].lookup() + # + name, host, subdomain = self.domainToNamespace(qdict["domain"]) + item = app['plugins']['data'].getData(name) + #rawlist = json.dumps(rawjson) + try: + item = json.loads(item) + except: + if app['debug']: traceback.print_exc() + return + qtype = qdict['qtype'] if qtype == 1: reqtype = "A" @@ -239,17 +253,3 @@ def _bitLookup(self,qdict): answers = json.loads(answers) return {"type":52, "class":1, "ttl":300, "data":answers} return - - def _torLookup(self,qdict): - #if TXT record - if qdict['qtype'] == 16: - answers = app['plugins']['dns'].getOnion(qdict["domain"]) - if answers != '[]': - nameData = json.loads(answers) - answers = str(nameData[0]) - #did we get an IP address or nothing? - if answers: - return answers - return '[]' - return '[]' - diff --git a/service/serviceDNS.py b/service/serviceDNS.py index 4a2f85c..f27e443 100644 --- a/service/serviceDNS.py +++ b/service/serviceDNS.py @@ -34,7 +34,7 @@ def lookup(self, qdict) : #for service, value in self.services.iteritems(): # if re.search(value['filter'], qdict["domain"]): # return app['plugins'][service].lookup(qdict) - if qdict["domain"].endswith(".bit") or qdict["domain"].endswith(".tor"): + if qdict["domain"].endswith(".bit"): return app['plugins']['domain'].lookup(qdict) return self._lookup(qdict) From cc612375aac39ab6135c9c8404b25109ef957e1e Mon Sep 17 00:00:00 2001 From: RyanC Date: Thu, 11 Dec 2014 16:52:02 -0800 Subject: [PATCH 09/12] remove commit 27981ed3 --- plugin/pluginNamespaceDomain.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/plugin/pluginNamespaceDomain.py b/plugin/pluginNamespaceDomain.py index 1c97620..021b541 100644 --- a/plugin/pluginNamespaceDomain.py +++ b/plugin/pluginNamespaceDomain.py @@ -229,23 +229,23 @@ def lookup(self, qdict) : if reqtype == "A": #new style A request answers = app['plugins']['dns'].getIp4(qdict["domain"]) - if answers != '[]': - nameData = json.loads(answers) - answers = str(nameData[0]) - #did we get an IP address or nothing? - if answers: - return answers - return '[]' + if answers != '[]': + nameData = json.loads(answers) + answers = str(nameData[0]) + #did we get an IP address or nothing? + if answers: + return answers + return '[]' elif reqtype == "AAAA": #new style AAAA request answers = app['plugins']['dns'].getIp6(qdict["domain"]) - if answers != '[]': - nameData = json.loads(answers) - answers = str(nameData[0]) - #did we get an IP address or nothing? - if answers: - return answers - return '[]' + if answers != '[]': + nameData = json.loads(answers) + answers = str(nameData[0]) + #did we get an IP address or nothing? + if answers: + return answers + return '[]' elif reqtype == "TLSA": port = qdict["domain"].split(".")[0][1:] protocol = qdict["domain"].split(".")[1][1:] From 918378b0bfb59a2c1dc764388d8197247b80098d Mon Sep 17 00:00:00 2001 From: RyanC Date: Thu, 11 Dec 2014 16:59:27 -0800 Subject: [PATCH 10/12] remove commit 2748d5aa --- plugin/pluginDns.py | 54 +-------------- plugin/pluginNamespaceDomain.py | 114 +++++++++++++++++++++++++++----- service/serviceDNS.py | 12 +--- 3 files changed, 102 insertions(+), 78 deletions(-) diff --git a/plugin/pluginDns.py b/plugin/pluginDns.py index 215864c..41b29cd 100644 --- a/plugin/pluginDns.py +++ b/plugin/pluginDns.py @@ -3,7 +3,7 @@ #import DNS #import json, base64, types, random, traceback import re, json -import random + class dnsResult(dict): @@ -58,7 +58,6 @@ class pluginDns(plugin.PluginThread): 'getFreenet': [1, 1, '', 'Get the freenet config for the domain'], 'getFingerprint': [1, 1, '', 'Get the sha1 of the certificate for the domain (deprecated)'], 'getTlsFingerprint': [1, 3, ' ', 'Get the TLS information for the domain'], - 'getNS': [1, 1, '', 'Get a list of NS for the domain'], 'verifyFingerprint': [1, 2, ' ', 'Verify if the fingerprint is' ' acceptable for the domain'], @@ -125,32 +124,10 @@ def _getRecordForRPC(self, domain, recType): return result.toJsonForRPC() def getIp4(self, domain): - result = self._getRecordForRPC(domain, 'getIp4') - # if we got an NS record because there is no IP we need to ask the NS server for the IP - if result == '["ns"]': - - if(domain.endswith('_ip4.bit')): - domain = domain[:-8] + 'bit' - if(domain.endswith('_ip.bit')): - domain = domain[:-7] + 'bit' - - result = '["'+self._getIPv4FromNS(domain)+'"]' - - return result + return self._getRecordForRPC(domain, 'getIp4') def getIp6(self, domain): - result = self._getRecordForRPC(domain, 'getIp6') - # if we got an NS record because there is no IP we need to ask the NS server for the IP - if result == '["ns"]': - - if(domain.endswith('_ip6.bit')): - domain = domain[:-8] + 'bit' - if(domain.endswith('_ip.bit')): - domain = domain[:-7] + 'bit' - - result = '["'+self._getIPv6FromNS(domain)+'"]' - - return result + return self._getRecordForRPC(domain, 'getIp6') def getOnion(self, domain): return self._getRecordForRPC(domain, 'getOnion') @@ -212,34 +189,9 @@ def getTlsFingerprint(self, domain, protocol, port): result.add(domain, 'getTlsFingerprint' , answer) return result.toJsonForRPC() - def getNS(self, domain): - return self._getRecordForRPC(domain, 'getNS') - def _getTls(self, domain): return self._getRecordForRPC(domain, 'getTls') - def _getNSServer(self,domain): - item = self.getNS(domain) - - try: - servers = json.loads(item) - except: - if app['debug']: traceback.print_exc() - return - - server = servers[random.randrange(0, len(servers))] - return server - - def _getIPv4FromNS(self,domain): - #1 is the A record - server = self._getNSServer(domain) - return app['services']['dns']._lookup(domain, 1 , server)[0]['data'] - - def _getIPv6FromNS(self,domain): - #28 is the AAAA record - server = self._getNSServer(domain) - return app['services']['dns']._lookup(domain, 28 , server)[0]['data'] - def _getSubDomainTlsFingerprint(self,domain,protocol,port): #Get the first subdomain tls fingerprint that has the includeSubdomain flag turned on for i in xrange(0,domain.count('.')): diff --git a/plugin/pluginNamespaceDomain.py b/plugin/pluginNamespaceDomain.py index 021b541..0ae7ea2 100644 --- a/plugin/pluginNamespaceDomain.py +++ b/plugin/pluginNamespaceDomain.py @@ -20,10 +20,9 @@ class pluginNamespaceDomain(plugin.PluginThread): 'getOnion' : 'tor', 'getI2p' : 'i2p', 'getI2p_b32' : 'i2p_b32', - 'getFreenet' : 'freenet', + 'getFreenet': 'freenet', 'getFingerprint': 'fingerprint', 'getTls': 'tls', - 'getNS' : 'ns', } def pLoadconfig(self): @@ -122,19 +121,11 @@ def _fetchNamecoinData(self, domain, recType, subdoms, data, result): result.add(domain, recType, data) return True - if recType == 'ns' and ( type(data) == str or type(data) is unicode ): - result.add(domain, recType, data) - return True - # legacy compatibility with "" in map instead of root if recType == 'ip' and 'map' in data and '' in data['map']: result.add(domain, recType, data['map']['']) return True - if recType == 'ns' and 'map' in data and '' in data['map']: - result.add(domain, recType, data['map']['']['ns']) - return True - return False # remove incompatible records (ns with ip, etc) @@ -142,6 +133,7 @@ def _fetchNamecoinData(self, domain, recType, subdoms, data, result): # pass def _fetchSubTree(self, subData, subKeys): + for sub in subKeys: if sub == '' and len(sub) == 0: return subData @@ -229,23 +221,28 @@ def lookup(self, qdict) : if reqtype == "A": #new style A request answers = app['plugins']['dns'].getIp4(qdict["domain"]) - if answers != '[]': - nameData = json.loads(answers) - answers = str(nameData[0]) + if answers != '[]': + nameData = json.loads(answers) + answers = str(nameData[0]) #did we get an IP address or nothing? + if answers.lower() == 'ns': + server = self._getNSServer(qdict["domain"]) + answers = self._getIPFromNS(qdict,server) if answers: return answers - return '[]' elif reqtype == "AAAA": #new style AAAA request answers = app['plugins']['dns'].getIp6(qdict["domain"]) - if answers != '[]': - nameData = json.loads(answers) - answers = str(nameData[0]) + if answers != '[]': + nameData = json.loads(answers) + answers = str(nameData[0]) + #this probably doesnt work for ipv6... + if answers.lower() == 'ns': + server = self._getNSServer(qdict["domain"]) + answers = self._getIPFromNS(qdict,server) #did we get an IP address or nothing? if answers: return answers - return '[]' elif reqtype == "TLSA": port = qdict["domain"].split(".")[0][1:] protocol = qdict["domain"].split(".")[1][1:] @@ -253,3 +250,84 @@ def lookup(self, qdict) : answers = json.loads(answers) return {"type":52, "class":1, "ttl":300, "data":answers} return + + print item + + #Try old style map resolution and recursive lookup when using a NS record + if str(item[u"name"]) == "d/" + host : + try : + + try: + value = json.loads(item[u"value"]) + except: + if app['debug']: print "Value Result Is Not Valid JSON" + return + + #old style resolution + if value.has_key(u"map") : + if type(value[u"map"]) is types.DictType : + hasdefault = False + for key in value[u"map"].keys()[:] : + if key == u"" : + hasdefault = True + if str(key) == subdomain : + if type(value[u"map"][key]) == types.DictType : + #return dnslookup(value, key, qdict) + if value[u"map"][key].has_key(u"ns") : + server = value[u"map"][key][u"ns"][random.randrange(0, len(value[u"map"][key][u"ns"])-1)] + #return app['services']['dns']._lookup(qdict, server) + return app['services']['dns']._lookup(qdict, server)[0]['data'] + #return [{"qtype":1, "qclass":qclass, "ttl":300, "rdata":struct.pack("!I", ipstr2int(response))}] + #return [{'name': 'ssl.bit', 'data': '178.32.31.42', 'typename': 'A', 'classstr': 'IN', 'ttl': 86400, 'type': 1, 'class': 1, 'rdlength': 4}] + return str(value[u"map"][u""]) + #else : + #if type(value[u"map"][key]) == types.DictType : + #return dnslookup(domain, qt) + #return 1, str(value[u"map"][key]) + if hasdefault : + if type(value[u"map"][u""]) == types.DictType : + return self.dnslookup(value, u"", qdict) + return str(value[u"map"][u""]) + + except : + if app['debug']: traceback.print_exc() + return + + #app['services']['dns'].lookup() + + def _getNSServer(self,domain): + name, host, subdomain = self.domainToNamespace(domain) + item = app['plugins']['data'].getData(name) + + try: + item = json.loads(item) + except: + if app['debug']: traceback.print_exc() + return + + try: + value = json.loads(item[u"value"]) + except: + if app['debug']: print "Value Result Is Not Valid JSON" + return + + server = value[u"ns"][random.randrange(0, len(value[u"ns"]))] + return server + + def _getIPFromNS(self,qdict,server): + return app['services']['dns']._lookup(qdict, server)[0]['data'] + + def dnslookup(self, value, key, qdict) : + print 'dnslookup:', value, key, qdict + if value[u"map"][key].has_key(u"ns") : + server = self.servers[random.randrange(0, len(self.servers)-1)] + self.reqobj = DNS.Request(server=server) + + x = DnsClient.Request(server="8.8.8.8") + if type(value[u"map"][key][u"ns"]) == types.UnicodeType : + y = x.req(str(value[u"map"][key][u"ns"])).answers[0]["data"] + else : + y = x.req(str(value[u"map"][key][u"ns"][0])).answers[0]["data"] + ns = DNS.Request(server=y) + return ns.req(name=qdict["domain"], qtype=qdict["qtype"]).answers[0] + diff --git a/service/serviceDNS.py b/service/serviceDNS.py index f27e443..14007ee 100644 --- a/service/serviceDNS.py +++ b/service/serviceDNS.py @@ -38,19 +38,13 @@ def lookup(self, qdict) : return app['plugins']['domain'].lookup(qdict) return self._lookup(qdict) - def _lookup(self, domain, qtype='1', server = ''): + def _lookup(self, qdict, server = ''): #make sure the server string is a string and not unicode, otherwise the DNS library fails to resolve it server = str(server) - + if server == '': server = self.servers[random.randrange(0, len(self.servers)-1)] - if app['debug']: print "Fetching IP Address for: ", domain, "with NS Server:", server - x = DNS.Request(server=server) - result = x.req(name=domain, qtype=qtype).answers - - if app['debug']: print "* result: ", result - - return result + return x.req(name=qdict["domain"], qtype=qdict["qtype"]).answers From 54f02d6b7d24129d9d713285b68e77f663c92650 Mon Sep 17 00:00:00 2001 From: RyanC Date: Thu, 11 Dec 2014 17:00:47 -0800 Subject: [PATCH 11/12] remove commit 1850d4a1 --- plugin/pluginNamespaceDomain.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/pluginNamespaceDomain.py b/plugin/pluginNamespaceDomain.py index 0ae7ea2..2153409 100644 --- a/plugin/pluginNamespaceDomain.py +++ b/plugin/pluginNamespaceDomain.py @@ -191,6 +191,8 @@ def namespaceToDomain(self, name): def lookup(self, qdict) : #dns = app['services']['dns'].lookup() # + print 'inside lookup' + print qdict name, host, subdomain = self.domainToNamespace(qdict["domain"]) item = app['plugins']['data'].getData(name) #rawlist = json.dumps(rawjson) @@ -236,10 +238,8 @@ def lookup(self, qdict) : if answers != '[]': nameData = json.loads(answers) answers = str(nameData[0]) - #this probably doesnt work for ipv6... if answers.lower() == 'ns': - server = self._getNSServer(qdict["domain"]) - answers = self._getIPFromNS(qdict,server) + print 'zomg its an NS' #did we get an IP address or nothing? if answers: return answers From 2fbf28a215dbaab9af95c2be62fa67dd9d787b9b Mon Sep 17 00:00:00 2001 From: RyanC Date: Thu, 11 Dec 2014 17:13:53 -0800 Subject: [PATCH 12/12] remove commit 93e31425 --- plugin/pluginNamespaceDomain.py | 88 ++------------------------------- service/serviceDNS.py | 11 ++--- 2 files changed, 6 insertions(+), 93 deletions(-) diff --git a/plugin/pluginNamespaceDomain.py b/plugin/pluginNamespaceDomain.py index 2153409..d55fc84 100644 --- a/plugin/pluginNamespaceDomain.py +++ b/plugin/pluginNamespaceDomain.py @@ -9,7 +9,7 @@ class pluginNamespaceDomain(plugin.PluginThread): 'start': ['Launch at startup', 1], #'resolver': ['Forward standard requests to', '8.8.8.8,8.8.4.4'], } - depends = {'plugins': ['data', 'dns'],'services': ['dns']} + depends = {'plugins': ['data', 'dns']} filters = {'dns': '.bit$'} handle = ['dns'] @@ -194,7 +194,7 @@ def lookup(self, qdict) : print 'inside lookup' print qdict name, host, subdomain = self.domainToNamespace(qdict["domain"]) - item = app['plugins']['data'].getData(name) + item = app['plugins']['data'].getData(['data', ['getData', name]]) #rawlist = json.dumps(rawjson) try: item = json.loads(item) @@ -202,68 +202,9 @@ def lookup(self, qdict) : if app['debug']: traceback.print_exc() return - qtype = qdict['qtype'] - if qtype == 1: - reqtype = "A" - if qtype == 2: - reqtype = "NS" - elif qtype == 5: - reqtype = "CNAME" - elif qtype == 16: - reqtype = "TXT" - elif qtype == 15: - reqtype = "MX" - elif qtype == 28: - reqtype = "AAAA" - elif qtype == 52: - reqtype = "TLSA" - - - #try the new API first, then fall back to map if it fails - if reqtype == "A": - #new style A request - answers = app['plugins']['dns'].getIp4(qdict["domain"]) - if answers != '[]': - nameData = json.loads(answers) - answers = str(nameData[0]) - #did we get an IP address or nothing? - if answers.lower() == 'ns': - server = self._getNSServer(qdict["domain"]) - answers = self._getIPFromNS(qdict,server) - if answers: - return answers - elif reqtype == "AAAA": - #new style AAAA request - answers = app['plugins']['dns'].getIp6(qdict["domain"]) - if answers != '[]': - nameData = json.loads(answers) - answers = str(nameData[0]) - if answers.lower() == 'ns': - print 'zomg its an NS' - #did we get an IP address or nothing? - if answers: - return answers - elif reqtype == "TLSA": - port = qdict["domain"].split(".")[0][1:] - protocol = qdict["domain"].split(".")[1][1:] - answers = app['plugins']['dns'].getTlsFingerprint(qdict["domain"], protocol, port) - answers = json.loads(answers) - return {"type":52, "class":1, "ttl":300, "data":answers} - return - - print item - - #Try old style map resolution and recursive lookup when using a NS record if str(item[u"name"]) == "d/" + host : try : - - try: - value = json.loads(item[u"value"]) - except: - if app['debug']: print "Value Result Is Not Valid JSON" - return - - #old style resolution + value = json.loads(item[u"value"]) if value.has_key(u"map") : if type(value[u"map"]) is types.DictType : hasdefault = False @@ -288,35 +229,12 @@ def lookup(self, qdict) : if type(value[u"map"][u""]) == types.DictType : return self.dnslookup(value, u"", qdict) return str(value[u"map"][u""]) - except : if app['debug']: traceback.print_exc() return #app['services']['dns'].lookup() - def _getNSServer(self,domain): - name, host, subdomain = self.domainToNamespace(domain) - item = app['plugins']['data'].getData(name) - - try: - item = json.loads(item) - except: - if app['debug']: traceback.print_exc() - return - - try: - value = json.loads(item[u"value"]) - except: - if app['debug']: print "Value Result Is Not Valid JSON" - return - - server = value[u"ns"][random.randrange(0, len(value[u"ns"]))] - return server - - def _getIPFromNS(self,qdict,server): - return app['services']['dns']._lookup(qdict, server)[0]['data'] - def dnslookup(self, value, key, qdict) : print 'dnslookup:', value, key, qdict if value[u"map"][key].has_key(u"ns") : diff --git a/service/serviceDNS.py b/service/serviceDNS.py index 14007ee..f3b3b66 100644 --- a/service/serviceDNS.py +++ b/service/serviceDNS.py @@ -31,17 +31,12 @@ def pStop(self): def lookup(self, qdict) : if app['debug']: print 'Lookup:', qdict - #for service, value in self.services.iteritems(): - # if re.search(value['filter'], qdict["domain"]): - # return app['plugins'][service].lookup(qdict) - if qdict["domain"].endswith(".bit"): - return app['plugins']['domain'].lookup(qdict) + for service, value in self.services.iteritems(): + if re.search(value['filter'], qdict["domain"]): + return app['plugins'][service].lookup(qdict) return self._lookup(qdict) def _lookup(self, qdict, server = ''): - #make sure the server string is a string and not unicode, otherwise the DNS library fails to resolve it - server = str(server) - if server == '': server = self.servers[random.randrange(0, len(self.servers)-1)]