def getPayLoadField(message, length, bufferOffset): if length == 0: return None offset = sizeof(message) - sizeof(message.Payload) start = bufferOffset - offset end = start + length return message.Payload.value[start:end]
def __init__(self, extendedInfoConditional): CompositeType.__init__(self) #code page self.codePage = UInt32Le() #support flag self.flag = UInt32Le(InfoFlag.INFO_MOUSE | InfoFlag.INFO_UNICODE | InfoFlag.INFO_LOGONNOTIFY | InfoFlag.INFO_LOGONERRORS | InfoFlag.INFO_DISABLECTRLALTDEL) self.cbDomain = UInt16Le(lambda: sizeof(self.domain) - 2) self.cbUserName = UInt16Le(lambda: sizeof(self.userName) - 2) self.cbPassword = UInt16Le(lambda: sizeof(self.password) - 2) self.cbAlternateShell = UInt16Le( lambda: sizeof(self.alternateShell) - 2) self.cbWorkingDir = UInt16Le(lambda: sizeof(self.workingDir) - 2) #microsoft domain self.domain = String( readLen=CallableValue(lambda: self.cbDomain.value + 2), unicode=True) self.userName = String( readLen=CallableValue(lambda: self.cbUserName.value + 2), unicode=True) self.password = String( readLen=CallableValue(lambda: self.cbPassword.value + 2), unicode=True) #shell execute at start of session self.alternateShell = String( readLen=CallableValue(lambda: self.cbAlternateShell.value + 2), unicode=True) #working directory for session self.workingDir = String( readLen=CallableValue(lambda: self.cbWorkingDir.value + 2), unicode=True) self.extendedInfo = RDPExtendedInfo( conditional=extendedInfoConditional)
def __init__(self): CompositeType.__init__(self) self.dwVersion = UInt32Le() self.cbCompanyName = UInt32Le(lambda:sizeof(self.pbCompanyName)) #may contain "Microsoft Corporation" from server microsoft self.pbCompanyName = String("Microsoft Corporation", readLen = self.cbCompanyName, unicode = True) self.cbProductId = UInt32Le(lambda:sizeof(self.pbProductId)) #may contain "A02" from microsoft license server self.pbProductId = String("A02", readLen = self.cbProductId, unicode = True)
def __init__(self, readLen = None): CompositeType.__init__(self, readLen = readLen) self.lenUsername = UInt16Le(lambda:sizeof(self.username)) self.username = String(readLen = self.lenUsername) self.lenPassword = UInt16Le(lambda:sizeof(self.password)) self.password = String(readLen = self.lenPassword) self.lenDomain = UInt16Le(lambda:sizeof(self.domain)) self.domain = String(readLen = self.lenDomain) self.lenHostname = UInt16Le(lambda:sizeof(self.hostname)) self.hostname = String(readLen = self.lenHostname)
def __init__(self, readLen=None): CompositeType.__init__(self, readLen=readLen) self.lenUsername = UInt16Le(lambda: sizeof(self.username)) self.username = String(readLen=self.lenUsername) self.lenPassword = UInt16Le(lambda: sizeof(self.password)) self.password = String(readLen=self.lenPassword) self.lenDomain = UInt16Le(lambda: sizeof(self.domain)) self.domain = String(readLen=self.lenDomain) self.lenHostname = UInt16Le(lambda: sizeof(self.hostname)) self.hostname = String(readLen=self.lenHostname)
def __init__(self): CompositeType.__init__(self) self.shareId = UInt32Le() self.originatorId = UInt16Le(0x03EA, constant = True) self.lengthSourceDescriptor = UInt16Le(lambda:sizeof(self.sourceDescriptor)) self.lengthCombinedCapabilities = UInt16Le(lambda:(sizeof(self.numberCapabilities) + sizeof(self.pad2Octets) + sizeof(self.capabilitySets))) self.sourceDescriptor = String("rdpy", readLen = self.lengthSourceDescriptor) self.numberCapabilities = UInt16Le(lambda:len(self.capabilitySets._array)) self.pad2Octets = UInt16Le() self.capabilitySets = ArrayType(caps.Capability, readLen = self.numberCapabilities)
def __init__(self, readLen): CompositeType.__init__(self, readLen = readLen) #magic is RSA1(0x31415352) self.magic = UInt32Le(0x31415352, constant = True) self.keylen = UInt32Le(lambda:(sizeof(self.modulus) + sizeof(self.padding))) self.bitlen = UInt32Le(lambda:((self.keylen.value - 8) * 8)) self.datalen = UInt32Le(lambda:((self.bitlen.value / 8) - 1)) self.pubExp = UInt32Le() self.modulus = String(readLen = CallableValue(lambda:(self.keylen.value - 8))) self.padding = String("\x00" * 8, readLen = CallableValue(8))
def __init__(self, conditional): CompositeType.__init__(self, conditional = conditional) self.clientAddressFamily = UInt16Le(AfInet.AF_INET) self.cbClientAddress = UInt16Le(lambda:sizeof(self.clientAddress)) self.clientAddress = String(readLen = self.cbClientAddress, unicode = True) self.cbClientDir = UInt16Le(lambda:sizeof(self.clientDir)) self.clientDir = String(readLen = self.cbClientDir, unicode = True) #TODO make tiomezone self.clientTimeZone = String("\x00" * 172) self.clientSessionId = UInt32Le() self.performanceFlags = UInt32Le()
def __init__(self): CompositeType.__init__(self) self.dwSigAlgId = UInt32Le(0x00000001, constant = True) self.dwKeyAlgId = UInt32Le(0x00000001, constant = True) self.wPublicKeyBlobType = UInt16Le(0x0006, constant = True) self.wPublicKeyBlobLen = UInt16Le(lambda:sizeof(self.PublicKeyBlob)) self.PublicKeyBlob = RSAPublicKey(readLen = self.wPublicKeyBlobLen) self.wSignatureBlobType = UInt16Le(0x0008, constant = True) self.wSignatureBlobLen = UInt16Le(lambda:(sizeof(self.SignatureBlob) + sizeof(self.padding))) self.SignatureBlob = String(readLen = CallableValue(lambda:(self.wSignatureBlobLen.value - sizeof(self.padding)))) self.padding = String(b"\x00" * 8, readLen = CallableValue(8))
def __init__(self): CompositeType.__init__(self) self.dwSigAlgId = UInt32Le(0x00000001, constant=True) self.dwKeyAlgId = UInt32Le(0x00000001, constant=True) self.wPublicKeyBlobType = UInt16Le(0x0006, constant=True) self.wPublicKeyBlobLen = UInt16Le(lambda: sizeof(self.PublicKeyBlob)) self.PublicKeyBlob = RSAPublicKey(readLen=self.wPublicKeyBlobLen) self.wSignatureBlobType = UInt16Le(0x0008, constant=True) self.wSignatureBlobLen = UInt16Le(lambda: (sizeof(self.SignatureBlob) - 8)) self.SignatureBlob = String(readLen=self.wSignatureBlobLen) self.padding = String(b"\x00" * 8, readLen=UInt8(8))
def __init__(self, readLen): CompositeType.__init__(self, readLen=readLen) #magic is RSA1(0x31415352) self.magic = UInt32Le(0x31415352, constant=True) self.keylen = UInt32Le(lambda: (sizeof(self.modulus) + sizeof(self.padding))) self.bitlen = UInt32Le(lambda: ((self.keylen.value - 8) * 8)) self.datalen = UInt32Le(lambda: ((self.bitlen.value / 8) - 1)) self.pubExp = UInt32Le() self.modulus = String( readLen=CallableValue(lambda: (self.keylen.value - 8))) self.padding = String("\x00" * 8, readLen=CallableValue(8))
def __init__(self): CompositeType.__init__(self) self.shareId = UInt32Le() self.originatorId = UInt16Le(0x03EA, constant=True) self.lengthSourceDescriptor = UInt16Le( lambda: sizeof(self.sourceDescriptor)) self.lengthCombinedCapabilities = UInt16Le( lambda: (sizeof(self.numberCapabilities) + sizeof(self.pad2Octets) + sizeof(self.capabilitySets))) self.sourceDescriptor = String("rdpy", readLen=self.lengthSourceDescriptor) self.numberCapabilities = UInt16Le( lambda: len(self.capabilitySets._array)) self.pad2Octets = UInt16Le() self.capabilitySets = ArrayType(caps.Capability, readLen=self.numberCapabilities)
def __init__(self, userId=0, pduMessage=None): CompositeType.__init__(self) self.shareControlHeader = ShareControlHeader( lambda: sizeof(self), lambda: pduMessage.__class__._PDUTYPE_, userId) def PDUMessageFactory(): """ @summary: build message in accordance of type self.shareControlHeader.pduType.value """ for c in [ DemandActivePDU, ConfirmActivePDU, DataPDU, DeactiveAllPDU ]: if self.shareControlHeader.pduType.value == c._PDUTYPE_: return c() log.debug("unknown PDU type : %s" % hex(self.shareControlHeader.pduType.value)) #read entire packet return String() if pduMessage is None: pduMessage = FactoryType(PDUMessageFactory) elif not "_PDUTYPE_" in pduMessage.__class__.__dict__: raise InvalidExpectedDataException("Try to send an invalid PDU") self.pduMessage = pduMessage
def __init__(self, updateData=None): CompositeType.__init__(self) self.updateHeader = UInt8( lambda: updateData.__class__._FASTPATH_UPDATE_TYPE_) self.compressionFlags = UInt8(conditional=lambda: ( (self.updateHeader.value >> 4 ) & FastPathOutputCompression.FASTPATH_OUTPUT_COMPRESSION_USED)) self.size = UInt16Le(lambda: sizeof(self.updateData)) def UpdateDataFactory(): """ @summary: Create correct object in accordance to self.updateHeader field """ for c in [FastPathBitmapUpdateDataPDU]: if (self.updateHeader.value & 0xf) == c._FASTPATH_UPDATE_TYPE_: return c() log.debug("unknown Fast Path PDU update data type : %s" % hex(self.updateHeader.value & 0xf)) return String() if updateData is None: updateData = FactoryType(UpdateDataFactory) elif not "_FASTPATH_UPDATE_TYPE_" in updateData.__class__.__dict__: raise InvalidExpectedDataException( "Try to send an invalid fast path data update PDU") self.updateData = updateData
def __init__(self): #in old version this packet is empty i don't know #and not specified CompositeType.__init__(self, optional = True) self.shareId = UInt32Le() self.lengthSourceDescriptor = UInt16Le(lambda:sizeof(self.sourceDescriptor)) self.sourceDescriptor = String("rdpy", readLen = self.lengthSourceDescriptor)
def test_tpkt_layer_recv_fastpath_ext_length(self): """ @summary: test receive in fastpath case with extended length """ class FastPathLayer(tpkt.IFastPathListener): def setFastPathSender(self, fastPathSender): pass def recvFastPath(self, secflag, fastPathS): fastPathS.readType( type.String("test_tpkt_layer_recv_fastpath_ext_length", constant=True)) raise TPKTTest.TPKT_PASS() message = type.String("test_tpkt_layer_recv_fastpath_ext_length") s = type.Stream() s.writeType( (type.UInt8(tpkt.Action.FASTPATH_ACTION_FASTPATH), type.UInt16Be((type.sizeof(message) + 3) | 0x8000), message)) layer = tpkt.TPKT(None) layer.initFastPath(FastPathLayer()) layer.connect() self.assertRaises(TPKTTest.TPKT_PASS, layer.dataReceived, s.getvalue())
def __init__(self, pduData=None, shareId=0): CompositeType.__init__(self) self.shareDataHeader = ShareDataHeader( lambda: sizeof(self), lambda: self.pduData.__class__._PDUTYPE2_, shareId) def PDUDataFactory(): """ @summary: Create object in accordance self.shareDataHeader.pduType2 value """ for c in [ UpdateDataPDU, SynchronizeDataPDU, ControlDataPDU, ErrorInfoDataPDU, FontListDataPDU, FontMapDataPDU, PersistentListPDU, ClientInputEventPDU, ShutdownDeniedPDU, ShutdownRequestPDU, SupressOutputDataPDU ]: if self.shareDataHeader.pduType2.value == c._PDUTYPE2_: return c() log.debug("unknown PDU data type : %s" % hex(self.shareDataHeader.pduType2.value)) return String() if pduData is None: pduData = FactoryType(PDUDataFactory) elif not "_PDUTYPE2_" in pduData.__class__.__dict__: raise InvalidExpectedDataException( "Try to send an invalid data PDU") self.pduData = pduData
def __init__(self): CompositeType.__init__(self) self.shareId = UInt32Le() self.lengthSourceDescriptor = UInt16Le( lambda: sizeof(self.sourceDescriptor)) self.sourceDescriptor = String("rdpy", readLen=self.lengthSourceDescriptor)
def __init__(self): CompositeType.__init__(self) self.len = UInt8(lambda:sizeof(self) - 1) self.code = UInt8(MessageType.X224_TPDU_CONNECTION_CONFIRM, constant = True) self.padding = (UInt16Be(), UInt16Be(), UInt8()) #read if there is enough data self.protocolNeg = Negotiation(optional = True)
def __init__(self, blobType=BinaryBlobType.BB_ANY_BLOB, optional=False): CompositeType.__init__(self, optional=optional) self.wBlobType = UInt16Le( blobType, constant=True if blobType != BinaryBlobType.BB_ANY_BLOB else False) self.wBlobLen = UInt16Le(lambda: sizeof(self.blobData)) self.blobData = String(readLen=self.wBlobLen)
def __init__(self, event=None): CompositeType.__init__(self) self.type = UInt16Le(lambda: event.__class__._TYPE_) self.timestamp = UInt32Le() self.length = UInt32Le(lambda: (sizeof(self) - 10)) def EventFactory(): """ @summary: Closure for event factory """ for c in [ UpdateEvent, ScreenEvent, InfoEvent, CloseEvent, KeyEventScancode, KeyEventUnicode ]: if self.type.value == c._TYPE_: return c(readLen=self.length) log.debug("unknown event type : %s" % hex(self.type.value)) #read entire packet return String(readLen=self.length) if event is None: event = FactoryType(EventFactory) elif not "_TYPE_" in event.__class__.__dict__: raise error.InvalidExpectedDataException( "Try to send an invalid event block") self.event = event
def __init__(self, capability=None): CompositeType.__init__(self) self.capabilitySetType = UInt16Le(lambda: capability.__class__._TYPE_) self.lengthCapability = UInt16Le(lambda: sizeof(self)) def CapabilityFactory(): """ Closure for capability factory """ for c in [ GeneralCapability, BitmapCapability, OrderCapability, BitmapCacheCapability, BitmapCacheRev2Capability, PointerCapability, InputCapability, BrushCapability, GlyphCapability, OffscreenBitmapCacheCapability, VirtualChannelCapability, SoundCapability, ControlCapability, WindowActivationCapability, FontCapability, ColorCacheCapability, ShareCapability, MultiFragmentUpdate ]: if self.capabilitySetType.value == c._TYPE_ and ( self.lengthCapability.value - 4) > 0: return c(readLen=self.lengthCapability - 4) log.debug("unknown Capability type : %s" % hex(self.capabilitySetType.value)) #read entire packet return String(readLen=self.lengthCapability - 4) if capability is None: capability = FactoryType(CapabilityFactory) elif not "_TYPE_" in capability.__class__.__dict__: raise InvalidExpectedDataException( "Try to send an invalid capability block") self.capability = capability
def __init__(self, message=None): CompositeType.__init__(self) #preambule self.bMsgtype = UInt8( lambda: self.licensingMessage.__class__._MESSAGE_TYPE_) self.flag = UInt8(Preambule.PREAMBLE_VERSION_3_0) self.wMsgSize = UInt16Le(lambda: sizeof(self)) def LicensingMessageFactory(): """ @summary: factory for message nego Use in read mode """ for c in [ LicensingErrorMessage, ServerLicenseRequest, ClientNewLicenseRequest, ServerPlatformChallenge, ClientPLatformChallengeResponse ]: if self.bMsgtype.value == c._MESSAGE_TYPE_: return c(readLen=self.wMsgSize - 4) log.debug("unknown license message : %s" % self.bMsgtype.value) return String() if message is None: message = FactoryType(LicensingMessageFactory) elif not "_MESSAGE_TYPE_" in message.__class__.__dict__: raise InvalidExpectedDataException( "Try to send an invalid license message") self.licensingMessage = message
def __init__(self, dataBlock=None): CompositeType.__init__(self) self.type = UInt16Le(lambda: self.dataBlock.__class__._TYPE_) self.length = UInt16Le(lambda: sizeof(self)) def DataBlockFactory(): """ @summary: build settings in accordance of type self.type.value """ for c in [ ClientCoreData, ClientSecurityData, ClientNetworkData, ServerCoreData, ServerNetworkData, ServerSecurityData ]: if self.type.value == c._TYPE_: return c(readLen=self.length - 4) log.debug("unknown GCC block type : %s" % hex(self.type.value)) #read entire packet return String(readLen=self.length - 4) if dataBlock is None: dataBlock = FactoryType(DataBlockFactory) elif not "_TYPE_" in dataBlock.__class__.__dict__: raise InvalidExpectedDataException( "Try to send an invalid GCC blocks") self.dataBlock = dataBlock
def send(self, message): """ @summary: Send encompassed data @param message: {network.Type} message to send """ RawLayer.send(self, (UInt8(Action.FASTPATH_ACTION_X224), UInt8(0), UInt16Be(sizeof(message) + 4), message))
def __init__(self, readLen = None): CompositeType.__init__(self, readLen = readLen) self.encryptionMethod = UInt32Le() self.encryptionLevel = UInt32Le() self.serverRandomLen = UInt32Le(0x00000020, constant = True, conditional = lambda:not(self.encryptionMethod.value == 0 and self.encryptionLevel == 0)) self.serverCertLen = UInt32Le(lambda:sizeof(self.serverCertificate), conditional = lambda:not(self.encryptionMethod.value == 0 and self.encryptionLevel == 0)) self.serverRandom = String(readLen = self.serverRandomLen, conditional = lambda:not(self.encryptionMethod.value == 0 and self.encryptionLevel == 0)) self.serverCertificate = ServerCertificate(readLen = self.serverCertLen, conditional = lambda:not(self.encryptionMethod.value == 0 and self.encryptionLevel == 0))
def __init__(self): CompositeType.__init__(self) self.len = UInt8(lambda:sizeof(self) - 1) self.code = UInt8(MessageType.X224_TPDU_CONNECTION_REQUEST, constant = True) self.padding = (UInt16Be(), UInt16Be(), UInt8()) self.cookie = String(until = "\x0d\x0a", conditional = lambda:(self.len._is_readed and self.len.value > 14)) #read if there is enough data self.protocolNeg = Negotiation(optional = True)
def sendFastPath(self, secFlag, fastPathS): """ @param fastPathS: type transform to stream and send as fastpath @param secFlag: {integer} Security flag for fastpath packet """ RawLayer.send( self, (UInt8(Action.FASTPATH_ACTION_FASTPATH | ((secFlag & 0x3) << 6)), UInt16Be((sizeof(fastPathS) + 3) | 0x8000), fastPathS))
def __init__(self): #in old version this packet is empty i don't know #and not specified CompositeType.__init__(self, optional=True) self.shareId = UInt32Le() self.lengthSourceDescriptor = UInt16Le( lambda: sizeof(self.sourceDescriptor)) self.sourceDescriptor = String("rdpy", readLen=self.lengthSourceDescriptor)
def __init__(self, destLeft=0, destTop=0, destRight=0, destBottom=0, width=0, height=0, bitsPerPixel=0, bitmapDataStream=""): """ @param destLeft: destination left coordinate @param destTop: destination top coordinate @param destRight: destination right coordinate @param destBottom: destination bottom coordinate @param width: width of image @param height: height of image @param bitsPerPixel: color depth @param bitmapDataStream: data """ CompositeType.__init__(self) self.destLeft = UInt16Le(destLeft) self.destTop = UInt16Le(destTop) self.destRight = UInt16Le(destRight) self.destBottom = UInt16Le(destBottom) self.width = UInt16Le(width) self.height = UInt16Le(height) self.bitsPerPixel = UInt16Le(bitsPerPixel) self.flags = UInt16Le() self.bitmapLength = UInt16Le(lambda: (sizeof(self.bitmapComprHdr) + sizeof(self.bitmapDataStream))) self.bitmapComprHdr = BitmapCompressedDataHeader( bodySize=lambda: sizeof(self.bitmapDataStream), scanWidth=lambda: self.width.value, uncompressedSize=lambda: (self.width.value * self.height.value * self.bitsPerPixel.value), conditional=lambda: ( (self.flags.value & BitmapFlag.BITMAP_COMPRESSION) and not ( self.flags.value & BitmapFlag.NO_BITMAP_COMPRESSION_HDR))) self.bitmapDataStream = String( bitmapDataStream, readLen=UInt16Le(lambda: (self.bitmapLength.value if ( not self.flags.value & BitmapFlag.BITMAP_COMPRESSION or self. flags.value & BitmapFlag.NO_BITMAP_COMPRESSION_HDR ) else self.bitmapComprHdr.cbCompMainBodySize.value)))
def send(self, channelId, data): """ @summary: Specific send function for channelId @param channelId: {integer} Channel use to send @param data: {type.type | tuple} message to send """ self._transport.send((self.writeMCSPDUHeader(UInt8(self._sendOpcode)), per.writeInteger16(self._userId, Channel.MCS_USERCHANNEL_BASE), per.writeInteger16(channelId), UInt8(0x70), per.writeLength(sizeof(data)), data))
def __init__(self, extendedInfoConditional): CompositeType.__init__(self) #code page self.codePage = UInt32Le() #support flag self.flag = UInt32Le(InfoFlag.INFO_MOUSE | InfoFlag.INFO_UNICODE | InfoFlag.INFO_LOGONNOTIFY | InfoFlag.INFO_LOGONERRORS | InfoFlag.INFO_DISABLECTRLALTDEL) self.cbDomain = UInt16Le(lambda:sizeof(self.domain) - 2) self.cbUserName = UInt16Le(lambda:sizeof(self.userName) - 2) self.cbPassword = UInt16Le(lambda:sizeof(self.password) - 2) self.cbAlternateShell = UInt16Le(lambda:sizeof(self.alternateShell) - 2) self.cbWorkingDir = UInt16Le(lambda:sizeof(self.workingDir) - 2) #microsoft domain self.domain = String(readLen = CallableValue(lambda:self.cbDomain.value + 2), unicode = True) self.userName = String(readLen = CallableValue(lambda:self.cbUserName.value + 2), unicode = True) self.password = String(readLen = CallableValue(lambda:self.cbPassword.value + 2), unicode = True) #shell execute at start of session self.alternateShell = String(readLen = CallableValue(lambda:self.cbAlternateShell.value + 2), unicode = True) #working directory for session self.workingDir = String(readLen = CallableValue(lambda:self.cbWorkingDir.value + 2), unicode = True) self.extendedInfo = RDPExtendedInfo(conditional = extendedInfoConditional)
def __init__(self, readLen=None): CompositeType.__init__(self, readLen=readLen) self.destLeft = UInt16Le() self.destTop = UInt16Le() self.destRight = UInt16Le() self.destBottom = UInt16Le() self.width = UInt16Le() self.height = UInt16Le() self.bpp = UInt8() self.format = UInt8() self.length = UInt32Le(lambda: sizeof(self.data)) self.data = String(readLen=self.length)
def __init__(self, readLen = None): CompositeType.__init__(self, readLen = readLen) self.destLeft = UInt16Le() self.destTop = UInt16Le() self.destRight = UInt16Le() self.destBottom = UInt16Le() self.width = UInt16Le() self.height = UInt16Le() self.bpp = UInt8() self.format = UInt8() self.length = UInt32Le(lambda:sizeof(self.data)) self.data = String(readLen = self.length)
def writeDomainParams(self, maxChannels, maxUsers, maxTokens, maxPduSize): """ @summary: Write a special domain parameter structure use in connection sequence @param maxChannels: {integer} number of MCS channel use @param maxUsers: {integer} number of MCS user used (1) @param maxTokens: {integer} unknown @param maxPduSize: {integer} unknown @return: {Tuple(type)} domain parameter structure """ domainParam = (ber.writeInteger(maxChannels), ber.writeInteger(maxUsers), ber.writeInteger(maxTokens), ber.writeInteger(1), ber.writeInteger(0), ber.writeInteger(1), ber.writeInteger(maxPduSize), ber.writeInteger(2)) return (ber.writeUniversalTag(ber.Tag.BER_TAG_SEQUENCE, True), writeLength(sizeof(domainParam)), domainParam)
def sendConnectResponse(self): """ @summary: Send connect response """ ccReq = gcc.writeConferenceCreateResponse(self._serverSettings) ccReqStream = Stream() ccReqStream.writeType(ccReq) tmp = (ber.writeEnumerated(0), ber.writeInteger(0), self.writeDomainParams(22, 3, 0, 0xfff8), ber.writeOctetstring(ccReqStream.getvalue())) self._transport.send( (ber.writeApplicationTag(Message.MCS_TYPE_CONNECT_RESPONSE, sizeof(tmp)), tmp))
def __init__(self, destLeft = 0, destTop = 0, destRight = 0, destBottom = 0, width = 0, height = 0, bitsPerPixel = 0, bitmapDataStream = ""): """ @param destLeft: destination left coordinate @param destTop: destination top coordinate @param destRight: destination right coordinate @param destBottom: destination bottom coordinate @param width: width of image @param height: height of image @param bitsPerPixel: color depth @param bitmapDataStream: data """ CompositeType.__init__(self) self.destLeft = UInt16Le(destLeft) self.destTop = UInt16Le(destTop) self.destRight = UInt16Le(destRight) self.destBottom = UInt16Le(destBottom) self.width = UInt16Le(width) self.height = UInt16Le(height) self.bitsPerPixel = UInt16Le(bitsPerPixel) self.flags = UInt16Le() self.bitmapLength = UInt16Le(lambda:(sizeof(self.bitmapComprHdr) + sizeof(self.bitmapDataStream))) self.bitmapComprHdr = BitmapCompressedDataHeader(bodySize = lambda:sizeof(self.bitmapDataStream), scanWidth = lambda:self.width.value, uncompressedSize = lambda:(self.width.value * self.height.value * self.bitsPerPixel.value), conditional = lambda:((self.flags.value & BitmapFlag.BITMAP_COMPRESSION) and not (self.flags.value & BitmapFlag.NO_BITMAP_COMPRESSION_HDR))) self.bitmapDataStream = String(bitmapDataStream, readLen = CallableValue(lambda:(self.bitmapLength.value if (not self.flags.value & BitmapFlag.BITMAP_COMPRESSION or self.flags.value & BitmapFlag.NO_BITMAP_COMPRESSION_HDR) else self.bitmapComprHdr.cbCompMainBodySize.value)))
def createAuthenticationMessage(NegFlag, domain, user, NtChallengeResponse, LmChallengeResponse, EncryptedRandomSessionKey, Workstation): """ @summary: Create an Authenticate Message @param domain: {str} domain microsoft @param user: {str} user microsoft @param NtChallengeResponse: {str} Challenge response @param LmChallengeResponse: {str} domain microsoft @param EncryptedRandomSessionKey: {str} EncryptedRandomSessionKey """ message = AuthenticateMessage() message.NegotiateFlags.value = NegFlag #fill message offset = sizeof(message) message.DomainNameLen.value = len(domain) message.DomainNameBufferOffset.value = offset message.Payload.value += domain offset += len(domain) message.UserNameLen.value = len(user) message.UserNameBufferOffset.value = offset message.Payload.value += user offset += len(user) message.WorkstationLen.value = len(Workstation) message.WorkstationBufferOffset.value = offset message.Payload.value += Workstation offset += len(Workstation) message.LmChallengeResponseLen.value = len(LmChallengeResponse) message.LmChallengeResponseBufferOffset.value = offset message.Payload.value += LmChallengeResponse offset += len(LmChallengeResponse) message.NtChallengeResponseLen.value = len(NtChallengeResponse) message.NtChallengeResponseBufferOffset.value = offset message.Payload.value += NtChallengeResponse offset += len(NtChallengeResponse) message.EncryptedRandomSessionLen.value = len(EncryptedRandomSessionKey) message.EncryptedRandomSessionBufferOffset.value = offset message.Payload.value += EncryptedRandomSessionKey offset += len(EncryptedRandomSessionKey) return message
def sendConnectInitial(self): """ @summary: Send connect initial packet client automata function """ ccReq = gcc.writeConferenceCreateRequest(self._clientSettings) ccReqStream = Stream() ccReqStream.writeType(ccReq) tmp = (ber.writeOctetstring("\x01"), ber.writeOctetstring("\x01"), ber.writeBoolean(True), self.writeDomainParams(34, 2, 0, 0xffff), self.writeDomainParams(1, 1, 1, 0x420), self.writeDomainParams(0xffff, 0xfc17, 0xffff, 0xffff), ber.writeOctetstring(ccReqStream.getvalue())) self._transport.send( (ber.writeApplicationTag(Message.MCS_TYPE_CONNECT_INITIAL, sizeof(tmp)), tmp))
def test_per_readInteger(self): """ @summary: test readInteger function in per module """ for t in [type.UInt8, type.UInt16Be, type.UInt32Be]: v = t(3) s = type.Stream() s.writeType((per.writeLength(type.sizeof(v)), v)) s.pos = 0 self.assertTrue(per.readInteger(s) == 3, "invalid readLength for type %s"%t) #error case for l in [0, 3, 5]: s = type.Stream() s.writeType(per.writeLength(l)) s.pos = 0 self.assertRaises(error.InvalidValue, per.readInteger, s)
def test_tpkt_layer_recv_fastpath(self): """ @summary: test receive in fastpath case """ class FastPathLayer(tpkt.IFastPathListener): def setFastPathSender(self, fastPathSender): pass def recvFastPath(self, secFlag, fastPathS): fastPathS.readType(type.String("test_tpkt_layer_recv_fastpath", constant = True)) raise TPKTTest.TPKT_PASS() message = type.String("test_tpkt_layer_recv_fastpath") s = type.Stream() s.writeType((type.UInt8(tpkt.Action.FASTPATH_ACTION_FASTPATH), type.UInt8(type.sizeof(message) + 2), message)) layer = tpkt.TPKT(None) layer.initFastPath(FastPathLayer()) layer.connect() self.assertRaises(TPKTTest.TPKT_PASS, layer.dataReceived, s.getvalue())
def __init__(self, pduData = None, shareId = 0): CompositeType.__init__(self) self.shareDataHeader = ShareDataHeader(lambda:sizeof(self), lambda:self.pduData.__class__._PDUTYPE2_, shareId) def PDUDataFactory(): """ @summary: Create object in accordance self.shareDataHeader.pduType2 value """ for c in [UpdateDataPDU, SynchronizeDataPDU, ControlDataPDU, ErrorInfoDataPDU, FontListDataPDU, FontMapDataPDU, PersistentListPDU, ClientInputEventPDU, ShutdownDeniedPDU, ShutdownRequestPDU, SupressOutputDataPDU]: if self.shareDataHeader.pduType2.value == c._PDUTYPE2_: return c() log.debug("unknown PDU data type : %s"%hex(self.shareDataHeader.pduType2.value)) return String() if pduData is None: pduData = FactoryType(PDUDataFactory) elif not "_PDUTYPE2_" in pduData.__class__.__dict__: raise InvalidExpectedDataException("Try to send an invalid data PDU") self.pduData = pduData
def __init__(self, userId = 0, pduMessage = None): CompositeType.__init__(self) self.shareControlHeader = ShareControlHeader(lambda:sizeof(self), lambda:pduMessage.__class__._PDUTYPE_, userId) def PDUMessageFactory(): """ @summary: build message in accordance of type self.shareControlHeader.pduType.value """ for c in [DemandActivePDU, ConfirmActivePDU, DataPDU, DeactiveAllPDU]: if self.shareControlHeader.pduType.value == c._PDUTYPE_: return c() log.debug("unknown PDU type : %s"%hex(self.shareControlHeader.pduType.value)) #read entire packet return String() if pduMessage is None: pduMessage = FactoryType(PDUMessageFactory) elif not "_PDUTYPE_" in pduMessage.__class__.__dict__: raise InvalidExpectedDataException("Try to send an invalid PDU") self.pduMessage = pduMessage
def __init__(self, capability = None): CompositeType.__init__(self) self.capabilitySetType = UInt16Le(lambda:capability.__class__._TYPE_) self.lengthCapability = UInt16Le(lambda:sizeof(self)) def CapabilityFactory(): """ Closure for capability factory """ for c in [GeneralCapability, BitmapCapability, OrderCapability, BitmapCacheCapability, PointerCapability, InputCapability, BrushCapability, GlyphCapability, OffscreenBitmapCacheCapability, VirtualChannelCapability, SoundCapability, ControlCapability, WindowActivationCapability, FontCapability, ColorCacheCapability, ShareCapability, MultiFragmentUpdate]: if self.capabilitySetType.value == c._TYPE_ and (self.lengthCapability.value - 4) > 0: return c(readLen = self.lengthCapability - 4) log.debug("unknown Capability type : %s"%hex(self.capabilitySetType.value)) #read entire packet return String(readLen = self.lengthCapability - 4) if capability is None: capability = FactoryType(CapabilityFactory) elif not "_TYPE_" in capability.__class__.__dict__: raise InvalidExpectedDataException("Try to send an invalid capability block") self.capability = capability
def __init__(self, updateData = None): CompositeType.__init__(self) self.updateHeader = UInt8(lambda:updateData.__class__._FASTPATH_UPDATE_TYPE_) self.compressionFlags = UInt8(conditional = lambda:((self.updateHeader.value >> 4) & FastPathOutputCompression.FASTPATH_OUTPUT_COMPRESSION_USED)) self.size = UInt16Le(lambda:sizeof(self.updateData)) def UpdateDataFactory(): """ @summary: Create correct object in accordance to self.updateHeader field """ for c in [FastPathBitmapUpdateDataPDU]: if (self.updateHeader.value & 0xf) == c._FASTPATH_UPDATE_TYPE_: return c() log.debug("unknown Fast Path PDU update data type : %s"%hex(self.updateHeader.value & 0xf)) return String() if updateData is None: updateData = FactoryType(UpdateDataFactory) elif not "_FASTPATH_UPDATE_TYPE_" in updateData.__class__.__dict__: raise InvalidExpectedDataException("Try to send an invalid fast path data update PDU") self.updateData = updateData
def __init__(self, dataBlock = None): CompositeType.__init__(self) self.type = UInt16Le(lambda:self.dataBlock.__class__._TYPE_) self.length = UInt16Le(lambda:sizeof(self)) def DataBlockFactory(): """ @summary: build settings in accordance of type self.type.value """ for c in [ClientCoreData, ClientSecurityData, ClientNetworkData, ServerCoreData, ServerNetworkData, ServerSecurityData]: if self.type.value == c._TYPE_: return c(readLen = self.length - 4) log.debug("unknown GCC block type : %s"%hex(self.type.value)) #read entire packet return String(readLen = self.length - 4) if dataBlock is None: dataBlock = FactoryType(DataBlockFactory) elif not "_TYPE_" in dataBlock.__class__.__dict__: raise InvalidExpectedDataException("Try to send an invalid GCC blocks") self.dataBlock = dataBlock
def __init__(self, event = None): CompositeType.__init__(self) self.type = UInt16Le(lambda:event.__class__._TYPE_) self.timestamp = UInt32Le() self.length = UInt32Le(lambda:(sizeof(self) - 10)) def EventFactory(): """ @summary: Closure for event factory """ for c in [UpdateEvent, ScreenEvent, InfoEvent, CloseEvent]: if self.type.value == c._TYPE_: return c(readLen = self.length) log.debug("unknown event type : %s"%hex(self.type.value)) #read entire packet return String(readLen = self.length) if event is None: event = FactoryType(EventFactory) elif not "_TYPE_" in event.__class__.__dict__: raise error.InvalidExpectedDataException("Try to send an invalid event block") self.event = event
def __init__(self, message = None): CompositeType.__init__(self) #preambule self.bMsgtype = UInt8(lambda:self.licensingMessage.__class__._MESSAGE_TYPE_) self.flag = UInt8(Preambule.PREAMBLE_VERSION_3_0) self.wMsgSize = UInt16Le(lambda: sizeof(self)) def LicensingMessageFactory(): """ @summary: factory for message nego Use in read mode """ for c in [LicensingErrorMessage, ServerLicenseRequest, ClientNewLicenseRequest, ServerPlatformChallenge, ClientPLatformChallengeResponse]: if self.bMsgtype.value == c._MESSAGE_TYPE_: return c(readLen = self.wMsgSize - 4) log.debug("unknown license message : %s"%self.bMsgtype.value) return String(readLen = self.wMsgSize - 4) if message is None: message = FactoryType(LicensingMessageFactory) elif not "_MESSAGE_TYPE_" in message.__class__.__dict__: raise InvalidExpectedDataException("Try to send an invalid license message") self.licensingMessage = message
def sendFastPath(self, secFlag, fastPathS): """ @param fastPathS: {Type | Tuple} type transform to stream and send as fastpath @param secFlag: {integer} Security flag for fastpath packet """ RawLayer.send(self, (UInt8(Action.FASTPATH_ACTION_FASTPATH | ((secFlag & 0x3) << 6)), UInt16Be((sizeof(fastPathS) + 3) | 0x8000), fastPathS))
def sendConnectResponse(self): """ @summary: Send connect response """ ccReq = gcc.writeConferenceCreateResponse(self._serverSettings) ccReqStream = Stream() ccReqStream.writeType(ccReq) tmp = (ber.writeEnumerated(0), ber.writeInteger(0), self.writeDomainParams(22, 3, 0, 0xfff8), ber.writeOctetstring(ccReqStream.getvalue())) self._transport.send((ber.writeApplicationTag(Message.MCS_TYPE_CONNECT_RESPONSE, sizeof(tmp)), tmp))
def sendConnectInitial(self): """ @summary: Send connect initial packet client automata function """ ccReq = gcc.writeConferenceCreateRequest(self._clientSettings) ccReqStream = Stream() ccReqStream.writeType(ccReq) tmp = (ber.writeOctetstring("\x01"), ber.writeOctetstring("\x01"), ber.writeBoolean(True), self.writeDomainParams(34, 2, 0, 0xffff), self.writeDomainParams(1, 1, 1, 0x420), self.writeDomainParams(0xffff, 0xfc17, 0xffff, 0xffff), ber.writeOctetstring(ccReqStream.getvalue())) self._transport.send((ber.writeApplicationTag(Message.MCS_TYPE_CONNECT_INITIAL, sizeof(tmp)), tmp))