Пример #1
0
 def host_key_fingerprint_data(self) -> bytes:
     # pylint: disable=protected-access
     mod = WriteBuf._create_mpint(self.host_key_public_modulus, False)
     e = WriteBuf._create_mpint(self.host_key_public_exponent, False)
     return mod + e
Пример #2
0
 def payload(self) -> bytes:
     wbuf = WriteBuf()
     self.write(wbuf)
     return wbuf.write_flush()
Пример #3
0
 def read_packet(self, sshv: int = 2) -> Tuple[int, bytes]:
     try:
         header = WriteBuf()
         self.ensure_read(4)
         packet_length = self.read_int()
         header.write_int(packet_length)
         # XXX: validate length
         if sshv == 1:
             padding_length = 8 - packet_length % 8
             self.ensure_read(padding_length)
             padding = self.read(padding_length)
             header.write(padding)
             payload_length = packet_length
             check_size = padding_length + payload_length
         else:
             self.ensure_read(1)
             padding_length = self.read_byte()
             header.write_byte(padding_length)
             payload_length = packet_length - padding_length - 1
             check_size = 4 + 1 + payload_length + padding_length
         if check_size % self.__block_size != 0:
             Output().fail('[exception] invalid ssh packet (block size)')
             sys.exit(exitcodes.CONNECTION_ERROR)
         self.ensure_read(payload_length)
         if sshv == 1:
             payload = self.read(payload_length - 4)
             header.write(payload)
             crc = self.read_int()
             header.write_int(crc)
         else:
             payload = self.read(payload_length)
             header.write(payload)
         packet_type = ord(payload[0:1])
         if sshv == 1:
             rcrc = SSH1.crc32(padding + payload)
             if crc != rcrc:
                 Output().fail(
                     '[exception] packet checksum CRC32 mismatch.')
                 sys.exit(exitcodes.CONNECTION_ERROR)
         else:
             self.ensure_read(padding_length)
             padding = self.read(padding_length)
         payload = payload[1:]
         return packet_type, payload
     except SSH_Socket.InsufficientReadException as ex:
         if ex.args[0] is None:
             header.write(self.read(self.unread_len))
             e = header.write_flush().strip()
         else:
             e = ex.args[0].encode('utf-8')
         return -1, e