start server side app
This commit is contained in:
@@ -2,13 +2,18 @@
|
|||||||
@author: sylvain
|
@author: sylvain
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
class LayerMode(object):
|
||||||
|
NONE = 0
|
||||||
|
SERVER = 1
|
||||||
|
CLIENT = 2
|
||||||
|
|
||||||
class Layer(object):
|
class Layer(object):
|
||||||
'''
|
'''
|
||||||
Network abstraction for protocol
|
Network abstraction for protocol
|
||||||
Try as possible to divide user protocol in layer
|
Try as possible to divide user protocol in layer
|
||||||
default implementation is a transparent layer
|
default implementation is a transparent layer
|
||||||
'''
|
'''
|
||||||
def __init__(self, presentation = None):
|
def __init__(self, mode = LayerMode.NONE, presentation = None):
|
||||||
'''
|
'''
|
||||||
Constructor
|
Constructor
|
||||||
@param presentation: Layer which handled connect and recv messages
|
@param presentation: Layer which handled connect and recv messages
|
||||||
@@ -17,6 +22,8 @@ class Layer(object):
|
|||||||
self._presentation = presentation
|
self._presentation = presentation
|
||||||
#transport layer under layer in model
|
#transport layer under layer in model
|
||||||
self._transport = None
|
self._transport = None
|
||||||
|
#register layer mode
|
||||||
|
self._mode = mode
|
||||||
#auto set transport layer of own presentation layer
|
#auto set transport layer of own presentation layer
|
||||||
if not self._presentation is None:
|
if not self._presentation is None:
|
||||||
self._presentation._transport = self
|
self._presentation._transport = self
|
||||||
@@ -62,13 +69,13 @@ class LayerAutomata(Layer):
|
|||||||
layer with automata state
|
layer with automata state
|
||||||
we can set next recv function used
|
we can set next recv function used
|
||||||
'''
|
'''
|
||||||
def __init__(self, presentation = None):
|
def __init__(self, mode, presentation = None):
|
||||||
'''
|
'''
|
||||||
Constructor
|
Constructor
|
||||||
@param presentation: presentation Layer
|
@param presentation: presentation Layer
|
||||||
'''
|
'''
|
||||||
#call parent constructor
|
#call parent constructor
|
||||||
Layer.__init__(self, presentation)
|
Layer.__init__(self, mode, presentation)
|
||||||
|
|
||||||
def setNextState(self, callback = None):
|
def setNextState(self, callback = None):
|
||||||
'''
|
'''
|
||||||
@@ -93,12 +100,12 @@ class RawLayer(protocol.Protocol, LayerAutomata):
|
|||||||
allow this protocol to wait until expected size of packet
|
allow this protocol to wait until expected size of packet
|
||||||
and use Layer automata to call next automata state
|
and use Layer automata to call next automata state
|
||||||
'''
|
'''
|
||||||
def __init__(self, presentation = None):
|
def __init__(self, mode, presentation = None):
|
||||||
'''
|
'''
|
||||||
Constructor
|
Constructor
|
||||||
'''
|
'''
|
||||||
#call parent automata
|
#call parent automata
|
||||||
LayerAutomata.__init__(self, presentation)
|
LayerAutomata.__init__(self, mode, presentation)
|
||||||
#data buffer received from twisted network layer
|
#data buffer received from twisted network layer
|
||||||
self._buffer = ""
|
self._buffer = ""
|
||||||
#len of next packet pass to next state function
|
#len of next packet pass to next state function
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ class Factory(protocol.Factory):
|
|||||||
'''
|
'''
|
||||||
Factory of RDP protocol
|
Factory of RDP protocol
|
||||||
'''
|
'''
|
||||||
def __init__(self):
|
def __init__(self, mode):
|
||||||
pass
|
self._mode = mode
|
||||||
|
|
||||||
def buildProtocol(self, addr):
|
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):
|
def startedConnecting(self, connector):
|
||||||
print 'Started to connect.'
|
print 'Started to connect.'
|
||||||
|
|||||||
@@ -391,11 +391,11 @@ class SIL(LayerAutomata):
|
|||||||
Global channel for mcs that handle session
|
Global channel for mcs that handle session
|
||||||
identification user, licensing management, and capabilities exchange
|
identification user, licensing management, and capabilities exchange
|
||||||
'''
|
'''
|
||||||
def __init__(self):
|
def __init__(self, mode):
|
||||||
'''
|
'''
|
||||||
Constructor
|
Constructor
|
||||||
'''
|
'''
|
||||||
LayerAutomata.__init__(self, None)
|
LayerAutomata.__init__(self, mode, None)
|
||||||
#set by mcs layer channel init
|
#set by mcs layer channel init
|
||||||
self._channelId = UInt16Be()
|
self._channelId = UInt16Be()
|
||||||
#logon info send from client to server
|
#logon info send from client to server
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'''
|
'''
|
||||||
@author: sylvain
|
@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.type import UInt8, UInt16Le, UInt16Be, UInt32Le, CompositeType, sizeof
|
||||||
from rdpy.network.error import InvalidExpectedDataException
|
from rdpy.network.error import InvalidExpectedDataException
|
||||||
from rdpy.network.const import ConstAttributes, TypeAttributes
|
from rdpy.network.const import ConstAttributes, TypeAttributes
|
||||||
@@ -95,12 +95,12 @@ class TPDU(LayerAutomata):
|
|||||||
TPDU layer management
|
TPDU layer management
|
||||||
there is an connection automata
|
there is an connection automata
|
||||||
'''
|
'''
|
||||||
def __init__(self, presentation = None):
|
def __init__(self, presentation):
|
||||||
'''
|
'''
|
||||||
Constructor
|
Constructor
|
||||||
@param presentation: MCS layer
|
@param presentation: MCS layer
|
||||||
'''
|
'''
|
||||||
LayerAutomata.__init__(self, presentation)
|
LayerAutomata.__init__(self, presentation._mode, presentation)
|
||||||
#default selectedProtocol is SSl because is the only supported
|
#default selectedProtocol is SSl because is the only supported
|
||||||
#in this version of RDPY
|
#in this version of RDPY
|
||||||
#client requested selectedProtocol
|
#client requested selectedProtocol
|
||||||
@@ -113,7 +113,10 @@ class TPDU(LayerAutomata):
|
|||||||
connection request
|
connection request
|
||||||
for client send a connection request packet
|
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):
|
def recvConnectionConfirm(self, data):
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'''
|
'''
|
||||||
@author: sylvain
|
@author: sylvain
|
||||||
'''
|
'''
|
||||||
from rdpy.network.layer import RawLayer
|
from rdpy.network.layer import RawLayer, LayerMode
|
||||||
from rdpy.network.type import UInt8, UInt16Be, sizeof
|
from rdpy.network.type import UInt8, UInt16Be, sizeof
|
||||||
|
|
||||||
class TPKT(RawLayer):
|
class TPKT(RawLayer):
|
||||||
@@ -17,7 +17,7 @@ class TPKT(RawLayer):
|
|||||||
'''
|
'''
|
||||||
Constructor
|
Constructor
|
||||||
'''
|
'''
|
||||||
RawLayer.__init__(self, presentation)
|
RawLayer.__init__(self, LayerMode.NONE, presentation)
|
||||||
#last packet version read from header
|
#last packet version read from header
|
||||||
self._lastPacketVersion = UInt8()
|
self._lastPacketVersion = UInt8()
|
||||||
#length may be coded on more than 1 bytes
|
#length may be coded on more than 1 bytes
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ Created on 4 sept. 2013
|
|||||||
@author: sylvain
|
@author: sylvain
|
||||||
'''
|
'''
|
||||||
from rdpy.protocol.rdp import rdp
|
from rdpy.protocol.rdp import rdp
|
||||||
|
from rdpy.network.layer import LayerMode
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
#reactor.connectTCP("127.0.0.1", 5901, factory.RfbFactory(protocol))
|
#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.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()
|
reactor.run()
|
||||||
@@ -7,8 +7,9 @@ import sys, os
|
|||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||||
|
|
||||||
from rdpy.protocol.rdp import rdp
|
from rdpy.protocol.rdp import rdp
|
||||||
|
from rdpy.network.layer import LayerMode
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
reactor.listenTCP(33389, rdp.Factory())
|
reactor.listenTCP(33389, rdp.Factory(LayerMode.SERVER))
|
||||||
reactor.run()
|
reactor.run()
|
||||||
Reference in New Issue
Block a user