RDP
Remote Desktop Protocol, MS-RDPBCGR, added in 11.6.0 (#100). It rides on the stack that 10.0.0 tooled for S7comm, TPKT (RFC 1006) and COTP X.224 (RFC 905), with T.125 MCS above it. Segment by segment, the decoder reads what a stateless parser can see of a connection: the X.224 connection, where the client sends its cookie and the security protocols it offers and the server selects one or refuses, then the MCS PDUs that follow when standard RDP security is kept. Module: packet_parser::parse::application::protocols::rdp.
Detection: port 3389, then TLS
The rule is port-guarded, TCP 3389 (IANA ms-wbt-server) on either side:
#![allow(unused)] fn main() { port_rule(ApplicationProtocol::Rdp, Guard::Tcp, is_rdp_tcp_port, ProbeId::Rdp), // 3389 }
A blind probe is ruled out because none of the three layers is RDP's own: TPKT, COTP and MCS are also the stack of T.120 and of ISO over TCP. A server on another port is declared with ParseConfig::decode_as(port, DecodeAsProtocol::Rdp), which runs the same probe under the same TCP guard (Decode As). The probe is RdpPacket::try_from, on the whole segment. classify_payload called with no port (None, None) never answers "RDP".
After a TLS or CredSSP negotiation, the segments are labelled TLS. Once the server has selected TLS or CredSSP, the connection carries TLS records. Their first byte is a content type (0x16 for a handshake) where TPKT wants version 3, so the RDP probe refuses them and the blind TLS rule further down the table takes them. That is the decision of the issue, tested on rdp-to-ssl.pcap: a stateless parser sees TLS records and names them, and nothing ties them back to the RDP connection they belong to.
The Connection Request of frame 6 of rdp-x509.pcap, on its port, moved to another one, then on that port declared (tested):
#![allow(unused)] fn main() { #[test] fn rdp_on_port_3389_and_the_connection_request() { let raw = hex::decode(RDP_COOKIE_REQUEST_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "RDP"); // The label is a classification; RdpPacket is the decode. let payload = flow.transport.as_ref().unwrap().payload.unwrap(); let packet = RdpPacket::try_from(payload).unwrap(); assert_eq!(packet.pdus.len(), 1); // one TPKT in the segment assert!(!packet.truncated); let pdu = &packet.pdus[0]; assert_eq!(pdu.tpkt_length, 47); assert_eq!(pdu.cotp.pdu_type, CotpPduType::ConnectionRequest); assert_eq!(pdu.cotp.length_indicator, 42); assert_eq!((pdu.cotp.dst_ref, pdu.cotp.src_ref), (Some(0), Some(0))); assert_eq!(pdu.cotp.class, Some(0)); let RdpPayload::ConnectionRequest { token, negotiation } = &pdu.payload else { panic!("expected a Connection Request, got {:?}", pdu.payload); }; assert_eq!(*token, Some(&b"Cookie: mstshash=JOHN-PC "[..])); // without CR LF assert_eq!(pdu.payload.cookie_user(), Some("JOHN-PC ")); let negotiation = negotiation.expect("a negotiation request"); assert_eq!(negotiation.requested_protocols, 0); assert!(negotiation.standard_security_only()); // Bytes 36-37 are the TCP destination port (Ethernet, IPv4 without // options). On 3390 the port guard stays closed... let mut moved = raw.clone(); moved[36..38].copy_from_slice(&3390u16.to_be_bytes()); let flow = parse(LinkType::ETHERNET, &moved).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "Unknown"); // ... until the caller declares the port. let config = ParseConfig::new().decode_as(3390, DecodeAsProtocol::Rdp); let flow = parse_with(LinkType::ETHERNET, &moved, &config).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "RDP"); } }
The segment: TPKTs
#![allow(unused)] fn main() { pub struct RdpPacket<'a> { pub pdus: Vec<RdpPdu<'a>>, /// The last TPKT announces more than the segment holds. pub truncated: bool, } pub struct RdpPdu<'a> { /// Declared TPKT length, header included. pub tpkt_length: u16, pub cotp: X224Tpdu, pub payload: RdpPayload<'a>, } pub struct X224Tpdu { pub length_indicator: u8, pub pdu_type: CotpPduType, /// CR and CC only. pub dst_ref: Option<u16>, pub src_ref: Option<u16>, pub class: Option<u8>, /// DT only: last TPDU of the TSDU. pub end_of_tsdu: Option<bool>, } }
Every type of the module is #[non_exhaustive]: a match on RdpPayload or McsPduType needs a _ arm.
RdpPacket::try_from reads TPKTs back to back until the end of the segment, and the segment is RDP only if every one of them decodes. The last one may announce more bytes than the segment holds, because TCP cut it: as long as the headers the decoder reads are complete, it is decoded on what is there and truncated is set. Its continuation, in the next segment, has no header of its own and is not RDP: the crate does not reassemble, and tshark without reassembly calls those bytes data. TCP cuts 16 TPKTs of the corpus in two, and the 12 that start their segment are decoded that way: 11 Send Data Requests of 1 421 bytes whose first segment holds 1 260, and a Connect-Response of 1 405 bytes whose first segment holds 1 398. The other 4 start in the middle of a segment, after the end of the previous TPKT (frames 69, 71, 73 and 74 of rdp-proprietary-encryption.pcap): those segments do not start with a TPKT, and none of their bytes is decoded.
The TPKT header and the fixed part of the TPDU, on the Connection Request of frame 6 of rdp-x509.pcap (offsets in the TCP payload):
| Bytes | Field | Frame 6 | Check |
|---|---|---|---|
| 0 | TPKT version | 3 | must be 3, else InvalidTpkt |
| 1 | TPKT reserved | 0 | must be 0, else InvalidTpkt |
| 2–3 | tpkt_length, big-endian, header included | 47 | at least 7, else TpktTooShort |
| 4 | length_indicator | 42 | |
| 5 | pdu_type: high nibble E for CR, D for CC (the low nibble is the credit), F0 for DT | E0, CR | any other TPDU is UnexpectedTpdu |
| 6–7 | dst_ref (CR and CC) | 0 | |
| 8–9 | src_ref (CR and CC) | 0 | |
| 10 | class (CR and CC) | 0 | |
| 11… | X.224 user data, as far as the length indicator goes: the token, then the negotiation | see below |
In a DT, byte 6 holds the EOT bit (0x80), end_of_tsdu, and the MCS PDU starts length_indicator + 1 bytes into the TPDU, at byte 7 for the usual length indicator of 2.
MS-RDPBCGR counts the token and the negotiation of a CR or a CC in the length indicator, where the crate's generic COTP parser, cotp::CotpHeader (the module was misspelt copt until 12.0.0), would read variable-part parameters. The RDP decoder therefore reads the fixed part itself and reuses only CotpPduType.
The connection: Connection Request and Confirm
#![allow(unused)] fn main() { pub enum RdpPayload<'a> { /// X.224 Connection Request of the client. ConnectionRequest { /// `Cookie: mstshash=<user>` or a routing token, without its CR LF. token: Option<&'a [u8]>, negotiation: Option<NegotiationRequest>, }, /// X.224 Connection Confirm of the server. ConnectionConfirm { negotiation: Option<NegotiationResponse>, }, /// An MCS PDU in a Data TPDU. Mcs(McsPdu<'a>), } pub struct NegotiationRequest { pub flags: u8, /// Bits: 1 TLS, 2 CredSSP, 4 RDSTLS, 8 CredSSP with Early User /// Authorization Result, 0x10 RDS-AAD-Auth; zero for standard RDP /// security only. pub requested_protocols: u32, /// The correlationId of the correlation info, when the flags announce /// one and it follows the request. pub correlation_id: Option<[u8; 16]>, } pub enum NegotiationResponse { Accepted { flags: u8, selected_protocol: u32 }, Failure { failure_code: u32 }, } }
The X.224 user data of a Connection Request is a token, then a negotiation request, both optional. The token is everything before the first CR LF, kept raw: Cookie: mstshash=<user> from the usual client, or a routing token. RdpPayload::cookie_user() returns the user of a cookie as a &str, and None for anything else. After the token comes nothing, or an 8-byte negotiation request, which a correlation info may follow; anything that starts with a byte other than the request's type 0x01 is UnexpectedX224Data. The user data of a Connection Confirm is empty, or the server's response or failure, in the same 8-byte structure, with nothing after it:
| Byte | Field | Note |
|---|---|---|
| 0 | type | 0x01 request (in a CR), 0x02 response or 0x03 failure (in a CC) |
| 1 | flags | kept raw, not read for a failure |
| 2–3 | length, little-endian | must be 8, else InvalidNegotiation |
| 4–7 | requested_protocols, selected_protocol or failure_code | u32, little-endian |
Only the length field gives InvalidNegotiation. A structure that stops before its eighth byte, because TCP cut the TPKT or the length indicator ends early, is Truncated { expected: 8, .. }. Bytes after the structure are UnexpectedX224Data(n), n being their count, unless the request announces a correlation info (see the validations).
The protocols are bits (MS-RDPBCGR §2.2.1.1.1), and NegotiationRequest has a method for each but the last:
| Value | Security protocol | Method |
|---|---|---|
| 0 | standard RDP security only | standard_security_only() |
0x1 | TLS | tls() |
0x2 | CredSSP | credssp() |
0x4 | RDSTLS | rdstls() |
0x8 | CredSSP with Early User Authorization Result | credssp() |
0x10 | RDS-AAD-Auth | none: the bit stays in requested_protocols |
selected_protocol holds one of these values. The flags and failure_code stay numbers that the crate does not name, except the request flag 0x08, which correlation_info_present() reads. Since 11.7.0 the crate documents them (#188), after MS-RDPBCGR §2.2.1.1.1, §2.2.1.2.1 and §2.2.1.2.2:
| Field | Value | Meaning |
|---|---|---|
request flags | 0x01 | RESTRICTED_ADMIN_MODE_REQUIRED: a logon without credentials over CredSSP |
0x02 | REDIRECTED_AUTHENTICATION_MODE_REQUIRED: a logon without credentials, the authentication redirected over CredSSP (Remote Credential Guard) | |
0x08 | CORRELATION_INFO_PRESENT: a correlation info follows the request | |
response flags | 0x01 | EXTENDED_CLIENT_DATA_SUPPORTED |
0x02 | DYNVC_GFX_PROTOCOL_SUPPORTED (MS-RDPEGFX) | |
0x04 | NEGRSP_FLAG_RESERVED, which the client ignores | |
0x08 | RESTRICTED_ADMIN_MODE_SUPPORTED | |
0x10 | REDIRECTED_AUTHENTICATION_MODE_SUPPORTED | |
failure_code | 1 | SSL_REQUIRED_BY_SERVER: TLS or CredSSP required |
| 2 | SSL_NOT_ALLOWED_BY_SERVER: standard RDP security only | |
| 3 | SSL_CERT_NOT_ON_SERVER: no valid certificate on the server | |
| 4 | INCONSISTENT_FLAGS: the requested protocols contradict the one already in force | |
| 5 | HYBRID_REQUIRED_BY_SERVER: CredSSP required | |
| 6 | SSL_WITH_USER_AUTH_REQUIRED_BY_SERVER: TLS with a client certificate required | |
| 7 | ENTRA_AUTH_REQUIRED_BY_SERVER: Entra ID authentication by RDS-AAD-Auth required; tshark 4.6.6 does not name it |
The Connection Confirm of frame 9 of rdp-no-cookie-mstshash.pcap sets all five response flags, 0x1f. The negotiation is where the connection forks: standard security keeps TPKT and MCS on the wire, TLS or CredSSP turns the rest of it into TLS records. A refusal and a CredSSP selection, on real frames of two captures (tested):
#![allow(unused)] fn main() { #[test] fn the_negotiation_decides_what_follows() { // A client offers TLS (rdp-proprietary-encryption.pcap, frame 4)... let raw = hex::decode(RDP_TLS_REQUEST_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); let segment = flow.transport.as_ref().unwrap().payload.unwrap(); let request = RdpPacket::try_from(segment).unwrap(); let payload = &request.pdus[0].payload; assert_eq!(payload.cookie_user(), Some("FTBCO\\A70")); let RdpPayload::ConnectionRequest { negotiation: Some(offer), .. } = payload else { panic!("expected a negotiation request, got {payload:?}"); }; assert_eq!(offer.requested_protocols, 0x0000_0001); assert!(offer.tls() && !offer.credssp() && !offer.rdstls()); // ... and the server refuses it (frame 5): failure code 2, which // tshark names "TLS not allowed by server". let raw = hex::decode(RDP_NEGOTIATION_FAILURE_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "RDP"); let segment = flow.transport.as_ref().unwrap().payload.unwrap(); let confirm = RdpPacket::try_from(segment).unwrap(); assert_eq!(confirm.pdus[0].cotp.pdu_type, CotpPduType::ConnectionConfirm); assert_eq!(confirm.pdus[0].cotp.src_ref, Some(0x1234)); assert_eq!( confirm.pdus[0].payload, RdpPayload::ConnectionConfirm { negotiation: Some(NegotiationResponse::Failure { failure_code: 2 }) } ); // Another server selects CredSSP (rdp-to-ssl.pcap, frame 6)... let raw = hex::decode(RDP_CREDSSP_SELECTED_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); let segment = flow.transport.as_ref().unwrap().payload.unwrap(); let confirm = RdpPacket::try_from(segment).unwrap(); assert_eq!( confirm.pdus[0].payload, RdpPayload::ConnectionConfirm { negotiation: Some(NegotiationResponse::Accepted { flags: 0x01, selected_protocol: 2 }) } ); // ... so the client's next segment with a payload (frame 8) is a TLS // record: on port 3389 it fails the TPKT check, and the blind TLS rule // labels it. let raw = hex::decode(RDP_CLIENT_HELLO_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); let transport = flow.transport.as_ref().unwrap(); assert_eq!(transport.destination_port, Some(3389)); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "TLS"); assert_eq!( RdpPacket::try_from(transport.payload.unwrap()), Err(RdpParseError::InvalidTpkt { version: 0x16, reserved: 0x03 }) ); } }
The correlation info
A client may append to its negotiation request a 36-byte RDP_NEG_CORRELATION_INFO (MS-RDPBCGR §2.2.1.1.2), which it announces with the request flag 0x08, CORRELATION_INFO_PRESENT. The decoder has read it since 11.7.0 (#187). In 11.6.0, a Connection Request that carried one was refused with InvalidNegotiation ("declares 8 bytes, not 8"), and the segment came out "Unknown" on port 3389, its cookie and requested protocols lost. Offsets from the end of the request:
| Bytes | Field | Note |
|---|---|---|
| 0 | type | 0x06, else InvalidCorrelationInfo |
| 1 | flags | not read |
| 2–3 | length, little-endian | must be 36, else InvalidCorrelationInfo |
| 4–19 | correlationId | correlation_id |
| 20–35 | reserved | not read |
What may follow the request depends on its flag 0x08:
Flag 0x08 | After the request | Result |
|---|---|---|
| clear | nothing | accepted, correlation_id is None |
| clear | any byte | UnexpectedX224Data(n) |
| set | nothing | accepted, correlation_id is None |
| set | type 0x06, length 36, then 32 more bytes | accepted, correlation_id is Some(..) |
| set | from 4 bytes on, another type or another length | InvalidCorrelationInfo { structure_type, length } |
| set | type and length right, fewer than 36 bytes; or fewer than 4 bytes | Truncated { expected: 36, actual } |
| set | more than 36 bytes | UnexpectedX224Data(n), n counting the bytes after the 36 |
A flag without the structure is accepted, as it was in 11.6.0; tshark marks such a segment malformed. MS-RDPBCGR requires a correlationId whose first byte is neither 0x00 nor 0xF4 and which holds no 0x0D byte: the decoder does not check it, and neither does tshark. No capture of the corpus carries a correlation info; frame 6 of rdp-x509.pcap, given one by hand (tested):
#![allow(unused)] fn main() { #[test] fn a_correlation_info_after_the_negotiation_request() { // No capture of the corpus carries one. This Connection Request is the // 47-byte segment of frame 6 of rdp-x509.pcap, with the flag 0x08 set // and a correlation info appended (MS-RDPBCGR §2.2.1.1.2). let raw = hex::decode(RDP_COOKIE_REQUEST_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); let frame_6 = flow.transport.as_ref().unwrap().payload.unwrap(); let correlation_id = [ 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf6, 0x07, 0x18, 0x29, 0x3a, 0x4b, 0x5c, 0x6d, 0x7e, 0x8f, 0x90, ]; let mut segment = frame_6.to_vec(); segment[40] = 0x08; // flags of the request: CORRELATION_INFO_PRESENT segment.extend_from_slice(&[0x06, 0x00, 36, 0x00]); // type 0x06, length 36 segment.extend_from_slice(&correlation_id); segment.extend_from_slice(&[0; 16]); // reserved segment[3] = 47 + 36; // TPKT length segment[4] = 42 + 36; // length indicator let packet = RdpPacket::try_from(segment.as_slice()).unwrap(); let payload = &packet.pdus[0].payload; assert_eq!(payload.cookie_user(), Some("JOHN-PC ")); // the cookie is kept let RdpPayload::ConnectionRequest { negotiation: Some(request), .. } = payload else { panic!("expected a negotiation request, got {payload:?}"); }; assert!(request.correlation_info_present()); assert_eq!(request.correlation_id, Some(correlation_id)); assert!(request.standard_security_only()); // The flag without the structure is accepted, without an id. let mut flag_only = frame_6.to_vec(); flag_only[40] = 0x08; let packet = RdpPacket::try_from(flag_only.as_slice()).unwrap(); let RdpPayload::ConnectionRequest { negotiation: Some(request), .. } = &packet.pdus[0].payload else { panic!("expected a negotiation request, got {:?}", packet.pdus[0].payload); }; assert!(request.correlation_info_present()); assert_eq!(request.correlation_id, None); // The structure without the flag: 36 bytes after the request. let mut no_flag = segment.clone(); no_flag[40] = 0x00; assert_eq!( RdpPacket::try_from(no_flag.as_slice()), Err(RdpParseError::UnexpectedX224Data(36)) ); // A correlation info that declares 32 bytes... let mut length_32 = segment.clone(); length_32[49] = 32; assert_eq!( RdpPacket::try_from(length_32.as_slice()), Err(RdpParseError::InvalidCorrelationInfo { structure_type: 0x06, length: 32 }) ); // ... and one that TCP cuts 13 bytes in. assert_eq!( RdpPacket::try_from(&segment[..60]), Err(RdpParseError::Truncated { expected: 36, actual: 13 }) ); // InvalidNegotiation is left to a request that does not declare 8 // bytes; a request cut before its eighth byte is Truncated. let mut length_12 = frame_6.to_vec(); length_12[41] = 12; assert_eq!( RdpPacket::try_from(length_12.as_slice()), Err(RdpParseError::InvalidNegotiation { structure_type: 0x01, length: 12 }) ); assert_eq!( RdpPacket::try_from(&frame_6[..44]), Err(RdpParseError::Truncated { expected: 8, actual: 5 }) ); } }
MCS PDUs
#![allow(unused)] fn main() { pub struct McsPdu<'a> { pub kind: McsPduType, /// The whole PDU, choice or tag included. pub raw: &'a [u8], /// Decoded for Send Data. pub send_data: Option<McsSendData<'a>>, } pub enum McsPduType { ConnectInitial, ConnectResponse, ErectDomainRequest, DisconnectProviderUltimatum, AttachUserRequest, AttachUserConfirm, ChannelJoinRequest, ChannelJoinConfirm, SendDataRequest, SendDataIndication, } pub struct McsSendData<'a> { /// User id, from 1001. pub initiator: u16, pub channel_id: u16, /// Priority (two high bits) and segmentation (next two bits). pub priority_and_segmentation: u8, /// Declared length of the data. pub declared_length: Option<u16>, /// The data present in this segment. pub data: &'a [u8], } }
A Data TPDU carries one MCS PDU. The two connect PDUs of T.125 are BER: Connect-Initial is recognized by its tag 7F 65 ([APPLICATION 101]), Connect-Response by 7F 66 ([APPLICATION 102]), each followed by a readable BER length, short form or long form on one to four bytes, else InvalidBerLength. Their content, which tshark dissects further as T.124, stays in raw. Every other PDU is a DomainMCSPDU in PER, whose choice is the six high bits of the first byte:
| Choice | McsPduType |
|---|---|
| 1 | ErectDomainRequest |
| 8 | DisconnectProviderUltimatum |
| 10 | AttachUserRequest |
| 11 | AttachUserConfirm |
| 14 | ChannelJoinRequest |
| 15 | ChannelJoinConfirm |
| 25 | SendDataRequest |
| 26 | SendDataIndication |
Any other choice is UnknownMcsPdu(choice). The two Send Data PDUs, which carry the RDP traffic itself, are decoded further. On frame 32 of rdp-proprietary-encryption.pcap, offsets in the MCS PDU:
| Bytes | Field | Frame 32 |
|---|---|---|
| 0 | the choice, shifted left by 2 | 0x64: 25, Send Data Request |
| 1–2 | initiator, big-endian, plus 1001 | 7, so 1008 |
| 3–4 | channel_id, big-endian | 1003 |
| 5 | priority_and_segmentation | 0x70 |
| 6 | PER length, declared_length: one byte below 0x80, or two bytes 10xxxxxx xxxxxxxx (14 bits) | 80 |
| 7… | data, from the end of the length to the end of the TPKT, or of the segment if TCP cut it | 80 bytes |
A fragmented length (first byte 11xxxxxx) leaves declared_length at None, and data then starts right after the priority byte. The data are not decoded: they are the RDP payload as it travels, encrypted or not.
Frame 32, then a TPKT cut by TCP and its continuation (tested):
#![allow(unused)] fn main() { #[test] fn mcs_send_data_and_a_tpkt_cut_by_tcp() { // rdp-proprietary-encryption.pcap, frame 32: a Send Data Request, // whole in its segment. let raw = hex::decode(RDP_SEND_DATA_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "RDP"); let segment = flow.transport.as_ref().unwrap().payload.unwrap(); let packet = RdpPacket::try_from(segment).unwrap(); assert!(!packet.truncated); let pdu = &packet.pdus[0]; assert_eq!(pdu.tpkt_length, 94); assert_eq!(pdu.cotp.pdu_type, CotpPduType::Data); assert_eq!(pdu.cotp.end_of_tsdu, Some(true)); let RdpPayload::Mcs(mcs) = &pdu.payload else { panic!("expected an MCS PDU, got {:?}", pdu.payload); }; assert_eq!(mcs.kind, McsPduType::SendDataRequest); let send = mcs.send_data.expect("a Send Data is decoded"); assert_eq!(send.initiator, 1008); // 7 on the wire, plus 1001 assert_eq!(send.channel_id, 1003); assert_eq!(send.priority_and_segmentation, 0x70); assert_eq!(send.declared_length, Some(80)); assert_eq!(send.data.len(), 80); // Frame 43: the segment holds 1 260 bytes of a TPKT of 1 421. It is // decoded on what is there, and marked. let raw = hex::decode(RDP_CUT_TPKT_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "RDP"); let segment = flow.transport.as_ref().unwrap().payload.unwrap(); let packet = RdpPacket::try_from(segment).unwrap(); assert_eq!((segment.len(), packet.pdus[0].tpkt_length), (1260, 1421)); assert!(packet.truncated); let RdpPayload::Mcs(mcs) = &packet.pdus[0].payload else { panic!("expected an MCS PDU, got {:?}", packet.pdus[0].payload); }; let send = mcs.send_data.expect("a Send Data is decoded"); assert_eq!(send.declared_length, Some(1406)); assert_eq!(send.data.len(), 1245); // what this segment carries // Frame 44 carries the other 161 bytes, without a header of its own: // its first byte happens to be 3, but a reserved byte of 0x29 is not // a TPKT. let raw = hex::decode(RDP_TPKT_CONTINUATION_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "Unknown"); assert_eq!( RdpPacket::try_from(flow.transport.as_ref().unwrap().payload.unwrap()), Err(RdpParseError::InvalidTpkt { version: 3, reserved: 0x29 }) ); } }
Validations
All of them are RdpParseError, in packet_parser::errors::application::rdp:
| Error | When |
|---|---|
Truncated { expected, actual } | fewer than 7 bytes left for a TPKT, a TPDU shorter than its fixed part (3 bytes, 7 for a CR or CC), a negotiation structure shorter than its 8 bytes, a correlation info shorter than its 36, an empty MCS PDU, a Send Data shorter than 6 bytes, an empty segment |
InvalidTpkt { version, reserved } | a TPKT version other than 3, or a non-zero reserved byte |
TpktTooShort(u16) | a TPKT length below 7: the 4 bytes of its header and a TPDU of 3 |
UnexpectedTpdu(u8) | a TPDU other than CR, CC and DT |
InvalidNegotiation { structure_type, length } | a negotiation structure whose length field is not 8; the only case, since 11.7.0 |
InvalidCorrelationInfo { structure_type, length } | after a request with the flag 0x08, a structure whose type is not 0x06 or whose length field is not 36 (added in 11.7.0) |
UnexpectedX224Data(usize) | user data of a CR or CC that is neither a token nor a negotiation structure; bytes after a request without the flag 0x08, after a response or a failure, or after a correlation info |
UnknownMcsPdu(u8) | a DomainMCSPDU choice other than the eight above |
InvalidBerLength | an unreadable BER length after a connect tag |
Cotp(CotpParseError) | declared, never returned by the decoder |
A failure only means no label. On port 3389 or a declared port, the segment goes on down the table and comes out "Unknown" unless another rule takes it, TLS after the negotiation. Nothing is reported in corrupted: a port is a hint, and the payload may belong to something else.
Oracle: 861 segments, without reassembly
tests/rdp_golden.rs runs the five captures of pcaps_exemple/protocols/rdp/, taken from Zeek's test corpus (BSD 3-clause), and compares every segment that has a payload with tshark 4.6.6 run without TCP reassembly (tcp.desegment_tcp_streams:FALSE, the view of a stateless parser). tools/rdp_oracle.sh freezes, in tests/data/rdp_tshark_oracle.tsv, the highest layer tshark sees, the TPKT length, the COTP type, the token, the negotiation and the MCS PDU type. Zeek warns that many traces of its corpus are generated; the SOURCE.md of the folder settles the question for these five on their bytes, and sets aside rdp-invalid-length.pcap, whose bytes are fabricated.
| Segments | tshark | The crate |
|---|---|---|
| 83 | rdp, t125 or t124 | "RDP", with the same TPKT length, COTP type, token, negotiation and MCS type: 7 Connection Requests, 6 of them with a cookie, 7 Connection Confirms and 69 MCS PDUs |
| 481 | tls, or x509ce for a certificate | "TLS" for the 449 that start with a whole record; "Unknown" for the other 32: 27 continuations of a record cut by TCP, and 5 segments of rdp-to-ssl.pcap that start an Application Data record longer than themselves, which the TLS probe refuses |
| 287 | data for 278 segments that do not start with a TPKT, the 16 continuations of cut TPKTs among them; nothing above tcp for 9 segments it flags as out of order | "Unknown" |
| 10 | retransmissions, not dissected | not compared; labelled by their bytes, 6 "RDP" and 4 "TLS" |
The 69 MCS PDUs are 3 Connect-Initial, 2 Connect-Response, 1 Erect Domain Request, 1 Attach User Request, 1 Attach User Confirm, 6 Channel Join Requests, 6 Channel Join Confirms, 27 Send Data Requests, 21 Send Data Indications and 1 Disconnect Provider Ultimatum. In the golden histogram of the whole corpus, "RDP" counts 89 frames: these 83, and six of the retransmissions, two in each of rdp-no-cookie-mstshash.pcap, rdp-unknown-keyboard.pcap and rdp-x509.pcap, which the stateless parser labels by their bytes; the four others, copies of TLS records in rdp-no-cookie-mstshash.pcap, come out "TLS". The fuzz target parse_rdp runs nightly on the decoder: no panic, and on success the TPKTs tile the segment, the last one possibly cut, and every borrowed slice points into the input.
| Capture | Frames | Content |
|---|---|---|
rdp-x509.pcap | 15 | cookie mstshash=JOHN-PC, standard RDP security, Connect-Initial and Connect-Response |
rdp-unknown-keyboard.pcap | 11 | the same hosts and opening, a Connect-Initial with an unknown keyboard layout |
rdp-no-cookie-mstshash.pcap | 20 | no cookie; TLS, CredSSP and CredSSP with Early User Authorization Result offered, the last one selected, then TLS |
rdp-to-ssl.pcap | 658 | cookie mstshash=AWAKECODI, CredSSP selected, then the whole session in TLS |
rdp-proprietary-encryption.pcap | 542 | standard RDP security after a refused TLS: the whole MCS session, TPKTs of 1 421 bytes cut across two segments |
What is left out
The limits every protocol shares, reassembly and checksums among them, are on the Limits page. The ones below are this protocol's own.
- RDP over UDP (MS-RDPEUDP) is another transport, which the crate does not decode; the
rdpeudp*captures of Zeek's corpus were left out. - No reassembly: a TPKT cut by TCP is decoded on its first segment when it starts that segment, and its continuation stays
"Unknown", like the continuations of TLS records. A segment that starts with a continuation is refused whole, the complete TPKTs that follow it included: frame 77 ofrdp-proprietary-encryption.pcapholds two. - Fast-path PDUs, which MS-RDPBCGR sends without the TPKT, X.224 and MCS headers, fail the TPKT check and stay
"Unknown"; tshark leaves them atdataas well. Of the 262datasegments of the corpus that do not continue a cut TPKT, 241 start with a byte whose two low bits are clear, the mark of a fast-path PDU, where a TPKT has 3. - The correlation info is not checked further: the decoder keeps its
correlationIdwithout checking the bytes MS-RDPBCGR forbids in it, and reads neither its flags nor its reserved bytes. A request flag0x08without the structure is accepted. - No connection state: after a TLS or CredSSP negotiation the label is
"TLS", and nothing records that those records belong to an RDP connection, nor which protocol it selected. - The connect PDUs are not opened: the T.124 conference data of a Connect-Initial or Connect-Response, where the keyboard layout of
rdp-unknown-keyboard.pcapsits, stays inraw. - The Send Data contents are raw: the RDP PDUs they carry are
data. - Flags and failure codes are numbers; the crate documents them but does not name them.