diff --git a/rdpy/protocol/rdp/rdp.py b/rdpy/protocol/rdp/rdp.py index 2ca41e0..3ec9cf7 100644 --- a/rdpy/protocol/rdp/rdp.py +++ b/rdpy/protocol/rdp/rdp.py @@ -8,10 +8,10 @@ class Factory(protocol.Factory): Factory of RDP protocol ''' def __init__(self): - self._protocol = tpkt.TPKT(tpdu.TPDU(mcs.MCS(sil.SIL()))) + pass def buildProtocol(self, addr): - return self._protocol; + return tpkt.TPKT(tpdu.TPDU(mcs.MCS(sil.SIL()))); def startedConnecting(self, connector): print 'Started to connect.' diff --git a/rdpy/protocol/rdp/tpdu.py b/rdpy/protocol/rdp/tpdu.py index 622ec15..cf98b30 100644 --- a/rdpy/protocol/rdp/tpdu.py +++ b/rdpy/protocol/rdp/tpdu.py @@ -146,6 +146,35 @@ class TPDU(LayerAutomata): self.setNextState(self.recvData) #connection is done send to presentation LayerAutomata.connect(self) + + def recvConnectionRequest(self, data): + ''' + read connection confirm packet + next state is send connection confirm + @param data: stream + @see : http://msdn.microsoft.com/en-us/library/cc240470.aspx + ''' + message = TPDUConnectMessage() + data.readType(message) + if message.code != MessageType.X224_TPDU_CONNECTION_REQUEST: + raise InvalidExpectedDataException("expect connection packet") + + if not message.protocolNeg._is_readed or message.protocolNeg.failureCode._is_readed: + raise InvalidExpectedDataException("too older rdp client") + + self._requestedProtocol = message.protocolNeg.selectedProtocol + + if not self._requestedProtocol | Protocols.PROTOCOL_SSL: + #send error message and quit + message = TPDUConnectMessage() + message.code = MessageType.X224_TPDU_CONNECTION_CONFIRM + message.protocolNeg.code = NegociationType.TYPE_RDP_NEG_FAILURE + message.protocolNeg.failureCode = NegotiationFailureCode.SSL_REQUIRED_BY_SERVER + self._transport.send(message) + raise InvalidExpectedDataException("rdpy needs ssl client compliant") + + self._selectedProtocol = Protocols.PROTOCOL_SSL + self.sendConnectionConfirm() def recvData(self, data): ''' @@ -175,6 +204,19 @@ class TPDU(LayerAutomata): self._transport.send(message) self.setNextState(self.recvConnectionConfirm) + def sendConnectionConfirm(self): + ''' + write connection confirm message + next state is recvData + @see : http://msdn.microsoft.com/en-us/library/cc240501.aspx + ''' + message = TPDUConnectMessage() + message.code = MessageType.X224_TPDU_CONNECTION_CONFIRM + message.protocolNeg.code = NegociationType.TYPE_RDP_NEG_REQ + message.protocolNeg.selectedProtocol = self._selectedProtocol + self._transport.send(message) + self.setNextState(self.recvConnectionConfirm) + def send(self, message): ''' write message packet for TPDU layer