begining of mcs layer

This commit is contained in:
sylvain
2013-10-17 22:09:33 +02:00
parent 798076ff29
commit 0bc573c938
5 changed files with 129 additions and 55 deletions

View File

@@ -31,6 +31,7 @@ if __name__ == '__main__':
#w.show() #w.show()
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.135.160", 3389, factory.RfbFactory(tpkt.TPKT(tpdu.TPDU()))) #reactor.connectTCP("192.168.135.160", 3389, factory.RfbFactory(tpkt.TPKT(tpdu.TPDU())))
reactor.connectTCP("192.168.122.184", 3389, factory.RfbFactory(tpkt.TPKT(tpdu.TPDU())))
reactor.run() reactor.run()
sys.exit(app.exec_()) sys.exit(app.exec_())

22
rdpy/protocol/rdp/ber.py Normal file
View File

@@ -0,0 +1,22 @@
'''
@author: sylvain
'''
from rdpy.protocol.network.type import UInt16Le
from rdpy.utils.const import ConstAttributes
@ConstAttributes
class BerPc(object):
BER_PC_MASK = UInt16Le(0x20)
BER_PRIMITIVE = UInt16Le(0x00)
BER_CONSTRUCT = UInt16Le(0x20)
def berPC(pc):
'''
return BER_CONSTRUCT if true
BER_PRIMITIVE if false
'''
if pc:
return BerPc.BER_CONSTRUCT
else:
return BerPc.BER_PRIMITIVE

View File

@@ -2,24 +2,36 @@
@author sylvain @author sylvain
@summary gcc language @summary gcc language
''' '''
#constants declaration from rdpy.utils.const import ConstAttributes
#server data from rdpy.protocol.network.type import UInt32Le, UInt16Le, String, CompositeType
SC_CORE = 0x0C01
SC_SECURITY = 0x0C02
SC_NET = 0x0C03
#client data
CS_CORE = 0xC001
CS_SECURITY = 0xC002
CS_NET = 0xC003
CS_CLUSTER = 0xC004
CS_MONITOR = 0xC005
#depth color @ConstAttributes
RNS_UD_COLOR_8BPP = 0xCA01 class ServerToClientMessage(object):
RNS_UD_COLOR_16BPP_555 = 0xCA02 SC_CORE = UInt16Le(0x0C01)
RNS_UD_COLOR_16BPP_565 = 0xCA03 SC_SECURITY = UInt16Le(0x0C02)
RNS_UD_COLOR_24BPP = 0xCA04 SC_NET = UInt16Le(0x0C03)
@ConstAttributes
class ClientToServerMessage(object):
'''
Client to Server message
'''
CS_CORE = UInt16Le(0xC001)
CS_SECURITY = UInt16Le(0xC002)
CS_NET = UInt16Le(0xC003)
CS_CLUSTER = UInt16Le(0xC004)
CS_MONITOR = UInt16Le(0xC005)
@ConstAttributes
class ColorDepth(object):
'''
depth color
'''
RNS_UD_COLOR_8BPP = UInt16Le(0xCA01)
RNS_UD_COLOR_16BPP_555 = UInt16Le(0xCA02)
RNS_UD_COLOR_16BPP_565 = UInt16Le(0xCA03)
RNS_UD_COLOR_24BPP = UInt16Le(0xCA04)
RNS_UD_24BPP_SUPPORT = 0x0001 RNS_UD_24BPP_SUPPORT = 0x0001
RNS_UD_16BPP_SUPPORT = 0x0002 RNS_UD_16BPP_SUPPORT = 0x0002
@@ -28,29 +40,45 @@ RNS_UD_32BPP_SUPPORT = 0x0008
RNS_UD_SAS_DEL = 0xAA03 RNS_UD_SAS_DEL = 0xAA03
#rdp version
RDP_VERSION_4 = 0x00080001
RDP_VERSION_5_PLUS = 0x00080004
RNS_UD_CS_SUPPORT_ERRINFO_PDU = 0x0001 RNS_UD_CS_SUPPORT_ERRINFO_PDU = 0x0001
class ClientCoreSettings: @ConstAttributes
class Version(object):
'''
supported version of RDP
'''
RDP_VERSION_4 = UInt32Le(0x00080001)
RDP_VERSION_5_PLUS = UInt32Le(0x00080004)
class ClientCoreSettings(CompositeType):
''' '''
class that represent core setting of client class that represent core setting of client
''' '''
rdpVersion = RDP_VERSION_5_PLUS def __init__(self):
desktopWidth = 800 CompositeType.__init__(self)
desktopHeight = 600 self.rdpVersion = Version.RDP_VERSION_5_PLUS
kbdLayout = 0x409 self.desktopWidth = UInt16Le(800)
clientBuild = 2100 self.desktopHeight = UInt16Le(600)
clientName = "rdpy" self.padding1 = (UInt16Le(), UInt16Le())
keyboardType = 4 self.kbdLayout = UInt32Le(0x409)
keyboardSubType = 0 self.clientBuild = UInt32Le(2100)
keyboardFnKeys = 12 self.clientName = "rdpy"
postBeta2ColorDepth = RNS_UD_COLOR_24BPP self.padding2 = UInt16Le()
self.keyboardType = UInt32Le(4)
self.keyboardSubType = UInt32Le(0)
self.keyboardFnKeys = UInt32Le(12)
self.padding3 = String(" "*64)
self.postBeta2ColorDepth = ColorDepth.RNS_UD_COLOR_24BPP
self.padding4 = (UInt16Le(), UInt32Le())
self.highColorDepth = UInt16Le(24)
self.padding5 = (UInt16Le(), UInt16Le())
self.padding3 = String(" "*64)
class ServerCoreSettings: class ServerCoreSettings(CompositeType):
''' '''
server side core settings structure server side core settings structure
''' '''
rdpVersion = RDP_VERSION_5_PLUS def __init__(self):
CompositeType.__init__(self)
self.rdpVersion = Version.RDP_VERSION_5_PLUS

View File

@@ -0,0 +1,25 @@
'''
@author: sylvain
'''
from rdpy.protocol.network.layer import LayerAutomata
class MCS(LayerAutomata):
'''
Multi Channel Service layer
the main layer of RDP protocol
is why he can do everything and more!
'''
def __init__(self, presentation = None):
'''
ctor call base class ctor
'''
LayerAutomata.__init__(self, presentation)
def connect(self):
'''
connection send for client mode
a write connect initial packet
'''

View File

@@ -47,13 +47,12 @@ class TPDUConnectHeader(CompositeType):
self.padding = (UInt16Be(), UInt16Be(), UInt8()) self.padding = (UInt16Be(), UInt16Be(), UInt8())
class NegotiationRequest(CompositeType): class Negotiation(CompositeType):
''' '''
negociation request message negociation request message
''' '''
def __init__(self, protocol = Protocols.PROTOCOL_SSL): def __init__(self, protocol = Protocols.PROTOCOL_SSL):
CompositeType.__init__(self) CompositeType.__init__(self)
self.header = NegociationType.TYPE_RDP_NEG_REQ
self.padding = UInt8() self.padding = UInt8()
#always 8 #always 8
self.len = UInt16Le(0x0008) self.len = UInt16Le(0x0008)
@@ -97,36 +96,29 @@ class TPDU(LayerAutomata):
''' '''
write connection request message write connection request message
''' '''
neqReq = NegotiationRequest(self._protocol) neqReq = Negotiation(self._protocol)
self._transport.send((TPDUConnectHeader(MessageType.X224_TPDU_CONNECTION_REQUEST, sizeof(neqReq)), neqReq)) self._transport.send((TPDUConnectHeader(MessageType.X224_TPDU_CONNECTION_REQUEST, sizeof(neqReq)), NegociationType.TYPE_RDP_NEG_REQ, neqReq))
self.setNextState(self.recvConnectionConfirm) self.setNextState(self.recvConnectionConfirm)
def send(self, data): def send(self, message):
''' '''
write message packet for TPDU layer write message packet for TPDU layer
add TPDU header add TPDU header
''' '''
s = Stream() self._transport.send((UInt8(2), MessageType.X224_TPDU_DATA, UInt8(0x80), message))
s.write_uint8(2)
s.write_uint8(TPDU.X224_TPDU_DATA)
s.write_uint8(0x80)
s.write(data.getvalue())
self._transport.send(data)
def readNeg(self, data): def readNeg(self, data):
''' '''
read neagotiation response read neagotiation response
''' '''
code = data.read_uint8() code = UInt8()
data.readType(code)
if code == TPDU.TYPE_RDP_NEG_FAILURE: if code == NegociationType.TYPE_RDP_NEG_FAILURE:
self.readNegFailure(data) self.readNegFailure(data)
elif code == TPDU.TYPE_RDP_NEG_RSP: elif code == NegociationType.TYPE_RDP_NEG_RSP:
self.readNegResp(data) self.readNegResp(data)
else: else:
raise InvalidExpectedDataException("bad protocol negotiation response code") raise InvalidExpectedDataException("bad protocol negotiation response code")
#_transport is TPKT and transport is TCP layer of twisted
self._transport.transport.startTLS(ClientTLSContext())
def readNegFailure(self, data): def readNegFailure(self, data):
''' '''
@@ -138,16 +130,22 @@ class TPDU(LayerAutomata):
''' '''
read negotiation response packet read negotiation response packet
''' '''
flag = data.read_uint8() negResp = Negotiation()
len = data.read_leuint16() data.readType(negResp)
if len != 0x0008: if negResp.len != UInt16Le(0x0008):
raise InvalidExpectedDataException("invalid size of negotiation response") raise InvalidExpectedDataException("invalid size of negotiation response")
protocol = data.read_leuint32() protocol = negResp.protocol
if protocol != self._protocol: if protocol != self._protocol:
raise NegotiationFailure("protocol negotiation failure") raise NegotiationFailure("protocol negotiation failure")
#_transport is TPKT and transport is TCP layer of twisted
if self._protocol == Protocols.PROTOCOL_SSL:
self._transport.transport.startTLS(ClientTLSContext())
else:
raise NegotiationFailure("protocol negociation failure")
#open ssl needed #open ssl needed
from twisted.internet import ssl from twisted.internet import ssl