def decode_name(self, last=-1):
     """
         Orig docstring: Decode label at current offset in buffer (following pointers
         to cached elements where necessary)
         This method has overwritten because of Kitty. Sometimes it produces fuzzed data
         with iso-8859-1 encodings that the original DNS lib can not handle because that type
         of DNS domain label not exists in real world scenario but here it is.
     """
     label = []
     done = False
     while not done:
         (length,) = self.unpack("!B")
         if get_bits(length, 6, 2) == 3:
             # Pointer
             self.offset -= 1
             pointer = get_bits(self.unpack("!H")[0], 0, 14)
             save = self.offset
             if last == save:
                 raise BufferError(
                     f"Recursive pointer in DNSLabel [offset={self.offset:d},pointer={pointer:d},"
                     f"length={len(self.data):d}]")
             if pointer < self.offset:
                 self.offset = pointer
             else:
                 # Pointer can't point forwards
                 raise BufferError(
                     f"Invalid pointer in DNSLabel [offset={self.offset:d},pointer={pointer:d},"
                     f"length={len(self.data):d}]")
             label.extend(self.decode_name(save).label)
             self.offset = save
             done = True
         else:
             if length > 0:
                 l = self.get(length)
                 try:
                     l.decode()
                 except:
                     l.decode('iso-8859-1')
                 label.append(l)
             else:
                 done = True
     return DNSLabel(label)
Beispiel #2
0
 def decode_name(self, last=-1):
     """
         Decode label at current offset in buffer (following pointers
         to cached elements where necessary)
     """
     label = []
     done = False
     while not done:
         (length, ) = self.unpack("!B")
         if get_bits(length, 6, 2) == 3:
             # Pointer
             self.offset -= 1
             pointer = get_bits(self.unpack("!H")[0], 0, 14)
             save = self.offset
             if last == save:
                 raise BufferError(
                     "Recursive pointer in DNSLabel [offset=%d,pointer=%d,length=%d]"
                     % (self.offset, pointer, len(self.data)))
             if pointer < self.offset:
                 self.offset = pointer
             else:
                 # Pointer can't point forwards
                 raise BufferError(
                     "Invalid pointer in DNSLabel [offset=%d,pointer=%d,length=%d]"
                     % (self.offset, pointer, len(self.data)))
             label.extend(self.decode_name(save).label)
             self.offset = save
             done = True
         else:
             if length > 0:
                 l = self.get(length)
                 try:
                     l.decode()
                 except UnicodeDecodeError:
                     raise BufferError("Invalid label <%s>" % l)
                 label.append(l)
             else:
                 done = True
     return DNSLabel(label)