From ec971361c1800d63260b80880ce755bef2834bf2 Mon Sep 17 00:00:00 2001 From: "citronneur@gmail.com" Date: Sun, 9 Feb 2014 22:03:51 +0100 Subject: [PATCH] start server side app --- rdpy/network/layer.py | 17 ++++++++++++----- rdpy/protocol/rdp/rdp.py | 6 +++--- rdpy/protocol/rdp/sil.py | 4 ++-- rdpy/protocol/rdp/tpdu.py | 11 +++++++---- rdpy/protocol/rdp/tpkt.py | 4 ++-- rdpy/rdpclient.py | 4 ++-- rdpy/rdpserver.py | 3 ++- 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/rdpy/network/layer.py b/rdpy/network/layer.py index aa6a474..a20a3ab 100644 --- a/rdpy/network/layer.py +++ b/rdpy/network/layer.py @@ -2,13 +2,18 @@ @author: sylvain ''' +class LayerMode(object): + NONE = 0 + SERVER = 1 + CLIENT = 2 + class Layer(object): ''' Network abstraction for protocol Try as possible to divide user protocol in layer default implementation is a transparent layer ''' - def __init__(self, presentation = None): + def __init__(self, mode = LayerMode.NONE, presentation = None): ''' Constructor @param presentation: Layer which handled connect and recv messages @@ -17,6 +22,8 @@ def __init__(self, presentation = None): self._presentation = presentation #transport layer under layer in model self._transport = None + #register layer mode + self._mode = mode #auto set transport layer of own presentation layer if not self._presentation is None: self._presentation._transport = self @@ -62,13 +69,13 @@ class LayerAutomata(Layer): layer with automata state we can set next recv function used ''' - def __init__(self, presentation = None): + def __init__(self, mode, presentation = None): ''' Constructor @param presentation: presentation Layer ''' #call parent constructor - Layer.__init__(self, presentation) + Layer.__init__(self, mode, presentation) def setNextState(self, callback = None): ''' @@ -93,12 +100,12 @@ class RawLayer(protocol.Protocol, LayerAutomata): allow this protocol to wait until expected size of packet and use Layer automata to call next automata state ''' - def __init__(self, presentation = None): + def __init__(self, mode, presentation = None): ''' Constructor ''' #call parent automata - LayerAutomata.__init__(self, presentation) + LayerAutomata.__init__(self, mode, presentation) #data buffer received from twisted network layer self._buffer = "" #len of next packet pass to next state function diff --git a/rdpy/protocol/rdp/rdp.py b/rdpy/protocol/rdp/rdp.py index 3ec9cf7..3b815c8 100644 --- a/rdpy/protocol/rdp/rdp.py +++ b/rdpy/protocol/rdp/rdp.py @@ -7,11 +7,11 @@ class Factory(protocol.Factory): ''' Factory of RDP protocol ''' - def __init__(self): - pass + def __init__(self, mode): + self._mode = mode def buildProtocol(self, addr): - return tpkt.TPKT(tpdu.TPDU(mcs.MCS(sil.SIL()))); + return tpkt.TPKT(tpdu.TPDU(mcs.MCS(sil.SIL(self._mode)))); def startedConnecting(self, connector): print 'Started to connect.' diff --git a/rdpy/protocol/rdp/sil.py b/rdpy/protocol/rdp/sil.py index 8dc9e14..40944f2 100644 --- a/rdpy/protocol/rdp/sil.py +++ b/rdpy/protocol/rdp/sil.py @@ -391,11 +391,11 @@ class SIL(LayerAutomata): Global channel for mcs that handle session identification user, licensing management, and capabilities exchange ''' - def __init__(self): + def __init__(self, mode): ''' Constructor ''' - LayerAutomata.__init__(self, None) + LayerAutomata.__init__(self, mode, None) #set by mcs layer channel init self._channelId = UInt16Be() #logon info send from client to server diff --git a/rdpy/protocol/rdp/tpdu.py b/rdpy/protocol/rdp/tpdu.py index cf98b30..93aef2e 100644 --- a/rdpy/protocol/rdp/tpdu.py +++ b/rdpy/protocol/rdp/tpdu.py @@ -1,7 +1,7 @@ ''' @author: sylvain ''' -from rdpy.network.layer import LayerAutomata +from rdpy.network.layer import LayerAutomata, LayerMode from rdpy.network.type import UInt8, UInt16Le, UInt16Be, UInt32Le, CompositeType, sizeof from rdpy.network.error import InvalidExpectedDataException from rdpy.network.const import ConstAttributes, TypeAttributes @@ -95,12 +95,12 @@ class TPDU(LayerAutomata): TPDU layer management there is an connection automata ''' - def __init__(self, presentation = None): + def __init__(self, presentation): ''' Constructor @param presentation: MCS layer ''' - LayerAutomata.__init__(self, presentation) + LayerAutomata.__init__(self, presentation._mode, presentation) #default selectedProtocol is SSl because is the only supported #in this version of RDPY #client requested selectedProtocol @@ -113,7 +113,10 @@ def connect(self): connection request for client send a connection request packet ''' - self.sendConnectionRequest() + if self._mode == LayerMode.CLIENT: + self.sendConnectionRequest() + else: + self.setNextState(self.recvConnectionRequest) def recvConnectionConfirm(self, data): ''' diff --git a/rdpy/protocol/rdp/tpkt.py b/rdpy/protocol/rdp/tpkt.py index f8de06c..2100872 100644 --- a/rdpy/protocol/rdp/tpkt.py +++ b/rdpy/protocol/rdp/tpkt.py @@ -1,7 +1,7 @@ ''' @author: sylvain ''' -from rdpy.network.layer import RawLayer +from rdpy.network.layer import RawLayer, LayerMode from rdpy.network.type import UInt8, UInt16Be, sizeof class TPKT(RawLayer): @@ -17,7 +17,7 @@ def __init__(self, presentation = None): ''' Constructor ''' - RawLayer.__init__(self, presentation) + RawLayer.__init__(self, LayerMode.NONE, presentation) #last packet version read from header self._lastPacketVersion = UInt8() #length may be coded on more than 1 bytes diff --git a/rdpy/rdpclient.py b/rdpy/rdpclient.py index 8584742..7864d5a 100644 --- a/rdpy/rdpclient.py +++ b/rdpy/rdpclient.py @@ -4,12 +4,12 @@ @author: sylvain ''' from rdpy.protocol.rdp import rdp - +from rdpy.network.layer import LayerMode if __name__ == '__main__': from twisted.internet import reactor #reactor.connectTCP("127.0.0.1", 5901, factory.RfbFactory(protocol)) #reactor.connectTCP("192.168.1.90", 3389, factory.RfbFactory(tpkt.TPKT(tpdu.TPDU(mcs.MCS())))) - reactor.connectTCP("192.168.135.165", 3389, rdp.Factory()) + reactor.connectTCP("192.168.135.165", 3389, rdp.Factory(LayerMode.CLIENT)) reactor.run() \ No newline at end of file diff --git a/rdpy/rdpserver.py b/rdpy/rdpserver.py index ad61525..9a2cd26 100644 --- a/rdpy/rdpserver.py +++ b/rdpy/rdpserver.py @@ -7,8 +7,9 @@ sys.path.insert(1, os.path.join(sys.path[0], '..')) from rdpy.protocol.rdp import rdp +from rdpy.network.layer import LayerMode if __name__ == '__main__': from twisted.internet import reactor - reactor.listenTCP(33389, rdp.Factory()) + reactor.listenTCP(33389, rdp.Factory(LayerMode.SERVER)) reactor.run() \ No newline at end of file