start server side app

This commit is contained in:
citronneur@gmail.com
2014-02-09 22:03:51 +01:00
parent 120f142926
commit ec971361c1
7 changed files with 30 additions and 19 deletions

View File

@@ -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 @@ class Layer(object):
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

View File

@@ -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.'

View File

@@ -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

View File

@@ -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 @@ class TPDU(LayerAutomata):
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):
'''

View File

@@ -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 @@ class TPKT(RawLayer):
'''
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

View File

@@ -4,12 +4,12 @@ Created on 4 sept. 2013
@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()

View File

@@ -7,8 +7,9 @@ import sys, os
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()