Example #1
0
 def checkQuery(self, query_data):
     m = None
     domain = bytetodomain(query_data[12:-4])
     for p in self.patterns:
         m = p.match(domain)
         if m:
             break
     if not m:
         return None
     print "white list match:", domain, self
     return self.query(query_data)
Example #2
0
 def query(self, query_data):
     domain = bytetodomain(query_data[12:-4])
     qtype = struct.unpack('!h', query_data[-4:-2])[0]
     id = struct.unpack('!h', query_data[0:2])[0]
     #print "id", id
     #msg = [line for line in str(m.from_wire(query_data)).split('\n') if line.find("id", 0, -1) < 0]
     msg = query_data[4:]
     responce = self._query(tuple(msg),
                            query_data=query_data) # query_data must be written as a named argument, because of lru_cache()
     if responce:
         return responce[0:2] + query_data[0:2] + responce[4:]
     else:
         return responce
Example #3
0
 def query(self, query_data):
     domain = bytetodomain(query_data[12:-4])
     qtype = struct.unpack('!h', query_data[-4:-2])[0]
     id = struct.unpack('!h', query_data[0:2])[0]
     #print "id", id
     #msg = [line for line in str(m.from_wire(query_data)).split('\n') if line.find("id", 0, -1) < 0]
     msg = query_data[4:]
     responce = self._query(
         tuple(msg), query_data=query_data
     )  # query_data must be written as a named argument, because of lru_cache()
     if responce:
         return responce[0:2] + query_data[0:2] + responce[4:]
     else:
         return responce
Example #4
0
 def transfer(self, query_data, addr, server):
     if not query_data: return
     domain = bytetodomain(query_data[12:-4])
     qtype = struct.unpack('!h', query_data[-4:-2])[0]
     #print 'domain:%s, qtype:%x, thread:%d' % (domain, qtype, threading.activeCount())
     sys.stdout.flush()
     response = None
     for i in range(9):
         response = self.servers.query(query_data)
         if response:
             # udp dns packet no length
             server.sendto(response[2:], addr)
             break
     if response is None:
         print "[ERROR] Tried 9 times and failed to resolve %s" % domain
     return