add connect response reading

This commit is contained in:
speyrefitte
2013-10-25 17:36:34 +02:00
parent 1070ea8b6a
commit 963e20dc9f
8 changed files with 182 additions and 65 deletions

View File

@@ -3,7 +3,8 @@
'''
from rdpy.protocol.network.type import UInt8, UInt16Be, UInt32Be, String
from rdpy.utils.const import ConstAttributes
from rdpy.protocol.network.error import InvalidExpectedDataException
from rdpy.protocol.network.error import InvalidExpectedDataException,\
InvalidSize
@ConstAttributes
class BerPc(object):
@@ -228,9 +229,8 @@ def readEnumerated(s):
'''
if not readUniversalTag(s, Tag.BER_TAG_ENUMERATED, False):
raise InvalidExpectedDataException("invalid ber tag")
size = readLength(s)
if size != UInt32Be(1):
raise InvalidExpectedDataException("enumerate size is wrong")
if readLength(s) != 1:
raise InvalidSize("enumerate size is wrong")
enumer = UInt8()
s.readType(enumer)
return enumer.value

View File

@@ -2,28 +2,30 @@
@author: sylvain
'''
from rdpy.utils.const import ConstAttributes
from rdpy.utils.const import ConstAttributes, TypeAttributes
from rdpy.protocol.network.layer import LayerAutomata
from rdpy.protocol.network.type import sizeof, Stream, UInt8
from rdpy.protocol.rdp.ber import writeLength
from rdpy.protocol.network.error import InvalidExpectedDataException, InvalidValue, InvalidSize
import ber, gcc
@ConstAttributes
@TypeAttributes(UInt8)
class Message(object):
'''
message type
'''
MCS_TYPE_CONNECT_INITIAL = UInt8(0x65)
MCS_TYPE_CONNECT_RESPONSE = UInt8(0x66)
MCS_EDRQ = UInt8(1)
MCS_DPUM = UInt8(8)
MCS_AURQ = UInt8(10)
MCS_AUCF = UInt8(11)
MCS_CJRQ = UInt8(14)
MCS_CJCF = UInt8(15)
MCS_SDRQ = UInt8(25)
MCS_SDIN = UInt8(26)
MCS_TYPE_CONNECT_INITIAL = 0x65
MCS_TYPE_CONNECT_RESPONSE = 0x66
MCS_EDRQ = 1
MCS_DPUM = 8
MCS_AURQ = 10
MCS_AUCF = 11
MCS_CJRQ = 14
MCS_CJCF = 15
MCS_SDRQ = 25
MCS_SDIN = 26
class Channel:
MCS_GLOBAL_CHANNEL = 1003
@@ -66,6 +68,8 @@ class MCS(LayerAutomata):
self.writeDomainParams(0xffff, 0xfc17, 0xffff, 0xffff),
ber.writeOctetstring(ccReqStream.getvalue()))
self._transport.send((ber.writeApplicationTag(Message.MCS_TYPE_CONNECT_INITIAL, sizeof(tmp)), tmp))
#we must receive a connect response
self.setNextState(self.recvConnectResponse)
def writeDomainParams(self, maxChannels, maxUsers, maxTokens, maxPduSize):
'''
@@ -81,5 +85,34 @@ class MCS(LayerAutomata):
ber.writeInteger(1), ber.writeInteger(0), ber.writeInteger(1),
ber.writeInteger(maxPduSize), ber.writeInteger(2))
return (ber.writeUniversalTag(ber.Tag.BER_TAG_SEQUENCE, True), writeLength(sizeof(domainParam)), domainParam)
def readDomainParams(self, s):
'''
read domain params structure
'''
if not ber.readUniversalTag(s, ber.Tag.BER_TAG_SEQUENCE, True):
raise InvalidValue("bad BER tags")
length = ber.readLength(s)
max_channels = ber.readInteger(s)
max_users = ber.readInteger(s)
max_tokens = ber.readInteger(s)
ber.readInteger(s)
ber.readInteger(s)
ber.readInteger(s)
max_pdu_size = ber.readInteger(s)
ber.readInteger(s)
def recvConnectResponse(self, data):
ber.readApplicationTag(data, Message.MCS_TYPE_CONNECT_RESPONSE)
ber.readEnumerated(data)
ber.readInteger(data)
self.readDomainParams(data)
if not ber.readUniversalTag(data, ber.Tag.BER_TAG_OCTET_STRING, False):
raise InvalidExpectedDataException("invalid expected tag")
gccRequestLength = ber.readLength(data)
if data.dataLen() != gccRequestLength:
raise InvalidSize("gcc request have ")
from rdpy.protocol.network.type import hexDump
hexDump(data.getvalue())

View File

@@ -2,7 +2,7 @@
@author: sylvain
'''
from rdpy.protocol.network.type import UInt8, UInt16Be, UInt32Be, String, Stream
from rdpy.protocol.network.type import UInt8, UInt16Be, UInt32Be, String
from rdpy.protocol.network.error import InvalidValue, InvalidExpectedDataException
def readLength(s):

View File

@@ -4,37 +4,40 @@
from rdpy.protocol.network.layer import LayerAutomata
from rdpy.protocol.network.type import UInt8, UInt16Le, UInt16Be, UInt32Le, CompositeType, sizeof
from rdpy.protocol.network.error import InvalidExpectedDataException, NegotiationFailure
from rdpy.utils.const import ConstAttributes
from rdpy.utils.const import ConstAttributes, TypeAttributes
@ConstAttributes
@TypeAttributes(UInt8)
class MessageType(object):
'''
message type
'''
X224_TPDU_CONNECTION_REQUEST = UInt8(0xE0)
X224_TPDU_CONNECTION_CONFIRM = UInt8(0xD0)
X224_TPDU_DISCONNECT_REQUEST = UInt8(0x80)
X224_TPDU_DATA = UInt8(0xF0)
X224_TPDU_ERROR = UInt8(0x70)
X224_TPDU_CONNECTION_REQUEST = 0xE0
X224_TPDU_CONNECTION_CONFIRM = 0xD0
X224_TPDU_DISCONNECT_REQUEST = 0x80
X224_TPDU_DATA = 0xF0
X224_TPDU_ERROR = 0x70
@ConstAttributes
@TypeAttributes(UInt8)
class NegociationType(object):
'''
negotiation header
'''
TYPE_RDP_NEG_REQ = UInt8(0x01)
TYPE_RDP_NEG_RSP = UInt8(0x02)
TYPE_RDP_NEG_FAILURE = UInt8(0x03)
TYPE_RDP_NEG_REQ = 0x01
TYPE_RDP_NEG_RSP = 0x02
TYPE_RDP_NEG_FAILURE = 0x03
@ConstAttributes
@TypeAttributes(UInt32Le)
class Protocols(object):
'''
protocols available for TPDU layer
'''
PROTOCOL_RDP = UInt32Le(0x00000000)
PROTOCOL_SSL = UInt32Le(0x00000001)
PROTOCOL_HYBRID = UInt32Le(0x00000002)
PROTOCOL_HYBRID_EX = UInt32Le(0x00000008)
PROTOCOL_RDP = 0x00000000
PROTOCOL_SSL = 0x00000001
PROTOCOL_HYBRID = 0x00000002
PROTOCOL_HYBRID_EX = 0x00000008
class TPDUConnectHeader(CompositeType):
'''
@@ -46,6 +49,15 @@ class TPDUConnectHeader(CompositeType):
self.code = code
self.padding = (UInt16Be(), UInt16Be(), UInt8())
class TPDUDataHeader(CompositeType):
'''
header send when tpdu exchange application data
'''
def __init__(self):
CompositeType.__init__(self)
self.header = UInt8(2)
self.messageType = MessageType.X224_TPDU_DATA
self.separator = UInt8(0x80)
class Negotiation(CompositeType):
'''
@@ -69,7 +81,6 @@ class TPDU(LayerAutomata):
@param presentation: MCS layer
'''
LayerAutomata.__init__(self, presentation)
#default protocol is SSl because is the only supported
#in this version of RDPY
self._protocol = Protocols.PROTOCOL_SSL
@@ -103,9 +114,19 @@ class TPDU(LayerAutomata):
LayerAutomata.connect(self)
def recvData(self, data):
print "TPDU data"
from rdpy.protocol.network.type import hexDump
hexDump(data.getvalue())
'''
read data header from packet
and pass to presentation layer
@param data: stream
'''
header = TPDUDataHeader()
data.readType(header)
if header.messageType == MessageType.X224_TPDU_DATA:
LayerAutomata.recv(self, data)
elif header.messageType == MessageType.X224_TPDU_ERROR:
raise Exception("receive error from tpdu layer")
else:
raise InvalidExpectedDataException("unknow tpdu code %s"%header.messageType)
def sendConnectionRequest(self):
'''
@@ -121,7 +142,7 @@ class TPDU(LayerAutomata):
write message packet for TPDU layer
add TPDU header
'''
self._transport.send((UInt8(2), MessageType.X224_TPDU_DATA, UInt8(0x80), message))
self._transport.send((TPDUDataHeader(), message))
def readNeg(self, data):
'''