Fix: bad string length

This commit is contained in:
citronneur
2020-04-21 22:13:20 +02:00
parent 73b97d6929
commit 9550734743
3 changed files with 12 additions and 11 deletions

View File

@@ -256,7 +256,7 @@ class ClientCoreData(CompositeType):
self.sasSequence = UInt16Le(Sequence.RNS_UD_SAS_DEL) self.sasSequence = UInt16Le(Sequence.RNS_UD_SAS_DEL)
self.kbdLayout = UInt32Le(KeyboardLayout.US) self.kbdLayout = UInt32Le(KeyboardLayout.US)
self.clientBuild = UInt32Le(3790) self.clientBuild = UInt32Le(3790)
self.clientName = Buffer(b"rdpy" + b"\x00" * 11, read_len=lambda: 32) self.clientName = Buffer(("rdpy" + "\x00" * 12).encode("utf-16le"), read_len=lambda: 32)
self.keyboardType = UInt32Le(KeyboardType.IBM_101_102_KEYS) self.keyboardType = UInt32Le(KeyboardType.IBM_101_102_KEYS)
self.keyboardSubType = UInt32Le(0) self.keyboardSubType = UInt32Le(0)
self.keyboardFnKeys = UInt32Le(12) self.keyboardFnKeys = UInt32Le(12)
@@ -310,13 +310,14 @@ class ServerSecurityData(CompositeType):
self.serverRandom = Buffer(read_len=lambda: self.serverRandomLen.value, conditional=lambda: not(self.encryptionMethod.value == 0 and self.encryptionLevel.value == 0)) self.serverRandom = Buffer(read_len=lambda: self.serverRandomLen.value, conditional=lambda: not(self.encryptionMethod.value == 0 and self.encryptionLevel.value == 0))
self.serverCertificate = ServerCertificate(readLen=lambda: self.serverCertLen.value, conditional=lambda: not(self.encryptionMethod.value == 0 and self.encryptionLevel.value == 0)) self.serverCertificate = ServerCertificate(readLen=lambda: self.serverCertLen.value, conditional=lambda: not(self.encryptionMethod.value == 0 and self.encryptionLevel.value == 0))
class ServerCertificate(CompositeType): class ServerCertificate(CompositeType):
""" """
@summary: Server certificate structure @summary: Server certificate structure
@see: http://msdn.microsoft.com/en-us/library/cc240521.aspx @see: http://msdn.microsoft.com/en-us/library/cc240521.aspx
""" """
def __init__(self, certData = None, readLen = None, conditional = lambda:True): def __init__(self, certData = None, read_len = None, conditional = lambda:True):
CompositeType.__init__(self, readLen = readLen, conditional = conditional) CompositeType.__init__(self, read_len=read_len, conditional = conditional)
self.dwVersion = UInt32Le(lambda:(self.certData.__class__._TYPE_)) self.dwVersion = UInt32Le(lambda:(self.certData.__class__._TYPE_))
def CertificateFactory(): def CertificateFactory():
@@ -492,7 +493,7 @@ class Settings(CompositeType):
""" """
def __init__(self, init=None, read_len=None): def __init__(self, init=None, read_len=None):
super().__init__(read_len=read_len) super().__init__(read_len=read_len)
self.settings = ArrayType(DataBlock, [DataBlock(i) for i in init]) self.settings = ArrayType(DataBlock, [DataBlock(i) for i in init or []])
def get_block(self, message_type): def get_block(self, message_type):
""" """

View File

@@ -273,11 +273,11 @@ def readOctetStream(s, octetStream, minValue = 0):
""" """
size = readLength(s) + minValue size = readLength(s) + minValue
if size != len(octetStream): if size != len(octetStream):
raise InvalidValue("incompatible size %d != %d"(len(octetStream), size)) raise InvalidValue("incompatible size %d != %d"%(len(octetStream), size))
for i in range(0, size): for i in range(0, size):
c = UInt8() c = UInt8()
s.read_type(c) s.read_type(c)
if ord(octetStream[i]) != c.value: if octetStream[i] != c.value:
return False return False
return True return True

View File

@@ -380,7 +380,7 @@ class CompositeType(Message):
s.read_type(self.__dict__[name]) s.read_type(self.__dict__[name])
read_len += sizeof(self.__dict__[name]) read_len += sizeof(self.__dict__[name])
# read is ok but read out of bound # read is ok but read out of bound
if self._read_len is not None and read_len > self._read_len.value: if self._read_len is not None and read_len > self._read_len():
# roll back # roll back
s.seek(-sizeof(self.__dict__[name]), 1) s.seek(-sizeof(self.__dict__[name]), 1)
# and notify if not optional # and notify if not optional
@@ -396,9 +396,9 @@ class CompositeType(Message):
s.seek(-sizeof(self.__dict__[tmp_name]), 1) s.seek(-sizeof(self.__dict__[tmp_name]), 1)
raise e raise e
if self._read_len is not None and read_len < self._read_len.value: if self._read_len is not None and read_len < self._read_len():
log.debug("Still have correct data in packet %s, read %s bytes as padding"%(self.__class__, self._read_len.value - read_len)) log.debug("Still have correct data in packet %s, read %s bytes as padding"%(self.__class__, self._read_len() - read_len))
s.read(self._read_len.value - read_len) s.read(self._read_len() - read_len)
def __write__(self, s): def __write__(self, s):
""" """
@@ -419,7 +419,7 @@ class CompositeType(Message):
@return: sum of sizeof of each Type attributes @return: sum of sizeof of each Type attributes
""" """
if self._is_readed and not self._read_len is None: if self._is_readed and not self._read_len is None:
return self._read_len.value return self._read_len()
size = 0 size = 0
for name in self._type_name: for name in self._type_name: