From 84a75f5dcb93189a6d813fb48452e57da212c157 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 23 Oct 2023 14:18:13 +0200 Subject: [PATCH] RdpNegociation::get_license: propagate no license packet to parent --- src/core/RDP/tpdu_buffer.hpp | 11 ++++++++--- src/core/RDP/x224.hpp | 4 ++-- src/core/buf64k.hpp | 5 +++++ src/mod/rdp/rdp.hpp | 8 ++++---- src/mod/rdp/rdp_negociation.cpp | 8 +++----- src/mod/rdp/rdp_negociation.hpp | 2 +- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/core/RDP/tpdu_buffer.hpp b/src/core/RDP/tpdu_buffer.hpp index 306a3c8984..f992237b7f 100644 --- a/src/core/RDP/tpdu_buffer.hpp +++ b/src/core/RDP/tpdu_buffer.hpp @@ -74,7 +74,7 @@ namespace Extractors struct X224Extractor { - HeaderResult read_header(Buf64k & buf) + HeaderResult read_header(Buf64k const & buf) { // fast path header occupies 2 or 3 octets, but assume then data len at least 2 octets. if (buf.remaining() < 4) @@ -175,7 +175,7 @@ namespace Extractors struct CreedsppExtractor { - static HeaderResult read_header(Buf64k & buf) + static HeaderResult read_header(Buf64k const & buf) { if (buf.remaining() < 4) { @@ -280,6 +280,11 @@ struct TpduBuffer this->pdu_len = 0; } + void rewind_current_packet() noexcept + { + this->pdu_len = 0; + } + private: enum class StateRead : bool { @@ -289,7 +294,7 @@ struct TpduBuffer struct Extractor // Extractor concept { - Extractors::HeaderResult read_header(Buf64k& buf); + Extractors::HeaderResult read_header(Buf64k const &); void check_data(Buf64k const &) const; }; diff --git a/src/core/RDP/x224.hpp b/src/core/RDP/x224.hpp index 16e1d79bca..81cc3613de 100644 --- a/src/core/RDP/x224.hpp +++ b/src/core/RDP/x224.hpp @@ -1503,8 +1503,8 @@ namespace X224 } uint8_t LI = stream.in_uint8(); - uint8_t code = stream.in_uint8(); - if (!(code == X224::DT_TPDU)){ + uint8_t code = stream.in_uint8(); + if (code != X224::DT_TPDU){ LOG(LOG_ERR, "Unexpected TPDU opcode, expected DT_TPDU, got %u", code); throw Error(ERR_X224); } diff --git a/src/core/buf64k.hpp b/src/core/buf64k.hpp index f1edecd6d2..92e192e04b 100644 --- a/src/core/buf64k.hpp +++ b/src/core/buf64k.hpp @@ -44,6 +44,11 @@ struct BasicStaticBuffer return writable_bytes_view{this->buf + this->idx, this->remaining()}; } + [[nodiscard]] bytes_view av() const noexcept + { + return {this->buf + this->idx, this->remaining()}; + } + writable_bytes_view av(std::size_t n) noexcept { assert(n <= this->remaining()); diff --git a/src/mod/rdp/rdp.hpp b/src/mod/rdp/rdp.hpp index 6acd8e05bc..7efacdbeba 100644 --- a/src/mod/rdp/rdp.hpp +++ b/src/mod/rdp/rdp.hpp @@ -3090,7 +3090,7 @@ class mod_rdp : public mod_api, public rdp_api, public sespro_api } case WAITING_SYNCHRONIZE: LOG_IF(bool(this->verbose & RDPVerbose::basic_trace), - LOG_WARNING, "WAITING_SYNCHRONIZE"); + LOG_INFO, "WAITING_SYNCHRONIZE"); { ShareData_Recv sdata(sctrl.payload, &this->mppc_dec); @@ -3149,7 +3149,7 @@ class mod_rdp : public mod_api, public rdp_api, public sespro_api break; case WAITING_CTL_COOPERATE: LOG_IF(bool(this->verbose & RDPVerbose::basic_trace), - LOG_WARNING, "WAITING_CTL_COOPERATE"); + LOG_INFO, "WAITING_CTL_COOPERATE"); this->connection_finalization_state = WAITING_GRANT_CONTROL_COOPERATE; { ShareData_Recv sdata(sctrl.payload, &this->mppc_dec); @@ -3159,7 +3159,7 @@ class mod_rdp : public mod_api, public rdp_api, public sespro_api break; case WAITING_GRANT_CONTROL_COOPERATE: LOG_IF(bool(this->verbose & RDPVerbose::basic_trace), - LOG_WARNING, "WAITING_GRANT_CONTROL_COOPERATE"); + LOG_INFO, "WAITING_GRANT_CONTROL_COOPERATE"); this->connection_finalization_state = WAITING_FONT_MAP; { ShareData_Recv sdata(sctrl.payload, &this->mppc_dec); @@ -3169,7 +3169,7 @@ class mod_rdp : public mod_api, public rdp_api, public sespro_api break; case WAITING_FONT_MAP: LOG_IF(bool(this->verbose & RDPVerbose::basic_trace), - LOG_WARNING, "PDUTYPE2_FONTMAP"); + LOG_INFO, "PDUTYPE2_FONTMAP"); this->connection_finalization_state = UP_AND_RUNNING; if (!this->deactivation_reactivation_in_progress) { diff --git a/src/mod/rdp/rdp_negociation.cpp b/src/mod/rdp/rdp_negociation.cpp index 3be25c2e72..c7ec6592e5 100644 --- a/src/mod/rdp/rdp_negociation.cpp +++ b/src/mod/rdp/rdp_negociation.cpp @@ -445,7 +445,7 @@ bool RdpNegociation::recv_data(TpduBuffer& buf) } break; default: - if (this->get_license(x224_data)) { + if (this->get_license(x224_data, buf)) { this->state = State::TERMINATED; return true; } @@ -1143,7 +1143,7 @@ bool RdpNegociation::channel_join_confirm(InStream & x224_data) return true; } -bool RdpNegociation::get_license(InStream & stream) +bool RdpNegociation::get_license(InStream & stream, TpduBuffer& buf) { LOG_IF(bool(this->verbose & RDPVerbose::license), LOG_INFO, "RdpNegociation: Licensing"); @@ -1489,10 +1489,8 @@ bool RdpNegociation::get_license(InStream & stream) } else { LOG(LOG_WARNING, "RdpNegociation: Failed to get expected license negotiation PDU. sec.flags=0x%X", sec.flags); - hexdump(x224.payload.get_data(), x224.payload.get_capacity()); - //throw Error(ERR_SEC); + buf.rewind_current_packet(); r = true; - hexdump(sec.payload.get_data(), sec.payload.get_capacity()); } return r; } diff --git a/src/mod/rdp/rdp_negociation.hpp b/src/mod/rdp/rdp_negociation.hpp index 9ef8d115b7..94fe6049ec 100644 --- a/src/mod/rdp/rdp_negociation.hpp +++ b/src/mod/rdp/rdp_negociation.hpp @@ -244,7 +244,7 @@ class RdpNegociation void send_connectInitialPDUwithGccConferenceCreateRequest(); bool channel_connection_attach_user(InStream & stream); bool channel_join_confirm(InStream & x224_data); - bool get_license(InStream & stream); + bool get_license(InStream & stream, TpduBuffer& buf); template void send_data_request(uint16_t channelId, WriterData... writer_data);