Beispiel #1
0
    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
Beispiel #2
0
    def GSS_UnWrapEx(self, data):
        """
        @summary: decrypt data with key exchange in Authentication protocol
        @param data: {str}
        """
        signature = MessageSignatureEx()
        message = String()
        s = Stream(data)
        s.readType((signature, message))

        #decrypt message
        plaintextMessage = rc4.crypt(self._decryptHandle, message.value)
        checksum = rc4.crypt(self._decryptHandle, signature.Checksum.value)

        #recompute checksum
        t = Stream()
        t.writeType(signature.SeqNum)
        verify = HMAC_MD5(self._verifyKey, t.getvalue() + plaintextMessage)[:8]
        if verify != checksum:
            raise error.InvalidExpectedDataException("NTLMv2SecurityInterface : Invalid checksum")

        return plaintextMessage
Beispiel #3
0
    def recvPubKeyInc(self, data):
        """
        @summary: the server send the pubKeyBer + 1
        @param data : {str} all data available on buffer
        """
        request = decodeDERTRequest(data)
        pubKeyInc = self._interface.GSS_UnWrapEx(getPubKeyAuth(request))
        #check pubKeyInc = self._pubKeyBer + 1
        if not (self._pubKeyBer[1:] == pubKeyInc[1:]
                and ord(self._pubKeyBer[0]) + 1 == ord(pubKeyInc[0])):
            raise error.InvalidExpectedDataException(
                "CSSP : Invalid public key increment")

        domain, user, password = self._authenticationProtocol.getEncodedCredentials(
        )
        #send credentials
        self.transport.write(
            encodeDERTRequest(authInfo=self._interface.GSS_WrapEx(
                encodeDERTCredentials(domain, user, password))))
        #reset state back to normal state
        self.dataReceived = lambda x: self.__class__.dataReceived(self, x)
        if not self._callback is None:
            self._callback()