CVE-2024-32040: FreeRDP Integer Underflow Vulnerability in NSC Codec; Update to 3.5. or 2.11.6 Now!

FreeRDP is a widely-used, open-source implementation of the Remote Desktop Protocol (RDP) that enables users to access remote graphical environments via secure protocol. However, a major security vulnerability has been discovered in older versions of FreeRDP. Clients utilizing a version prior to 3.5. or 2.11.6 and connecting to servers that use the NSC codec are exposed to an integer underflow issue that can be potentially exploited by attackers. This vulnerability has been assigned the identifier CVE-2024-32040.

In this detailed post, we will discuss the vulnerability, provide code snippets demonstrating the issue, link to original references, and share details about potential exploits. We highly recommend updating FreeRDP to version 3.5. or 2.11.6 immediately to patch this issue.

Vulnerability Details

The CVE-2024-32040 vulnerability originates when the FreeRDP client attempts to process data from a server using the NSC codec (Network Screen Codec). An integer underflow occurs during the decoding process, which can ultimately lead to memory corruption, crashes, and potentially result in arbitrary code execution.

The following code snippet demonstrates how the integer underflow can take place in the vulnerable versions of FreeRDP:

/* FreeRDP: A Remote Desktop Protocol Implementation
 * NSCodec Codec
 *
 * Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
 * Copyright 2014 Erich E. Hoover <erich.e.hoover@gmail.com>
 *
 * Licensed under the Apache License, Version 2. (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

...

static BOOL nsc_process_message(NSC_CONTEXT* context, wStream* s)
{
	UINT32 length;
	length = Stream_GetRemainingLength(s);

	while (length >= 4)
	{
		const BYTE peek = *Stream_Pointer(s);
		const UINT32 channelId = peek;
		UINT32 channelSize;

		/* Integer underflow vulnerability here */
		Stream_Read_UINT32(s, channelSize);

		...
	}
}

Here, length is the size of the remaining stream, and channelSize is read from the incoming stream. The integer underflow occurs when the size of the NSC data is smaller than the reserved space, resulting in memory corruption.

Original References

1. FreeRDP Official Repository: https://github.com/FreeRDP/FreeRDP
2. CVE-2024-32040 NVD: https://nvd.nist.gov/vuln/detail/CVE-2024-32040

Exploit Details

As the vulnerability potentially allows arbitrary code execution, it could be exploited by an attacker to execute malicious code on the victim's system, leading to unauthorized access, data theft, and other severe consequences. The attacker would need to somehow induce the victim into connecting to a malicious RDP server using a FreeRDP client with an outdated, vulnerable version.

Mitigation

To patch this vulnerability, update your FreeRDP client to version 3.5. or 2.11.6 immediately. Additionally, as a temporary workaround, you can disable the NSC codec when using FreeRDP. To disable the NSC codec, pass the -nsc flag when initiating a client connection:

xfreerdp -nsc /v:<hostname> /u:<username>

It is crucial to understand the potential risks of using outdated software, especially when connecting to remote environments. By keeping your software up-to-date and following security best practices, you can minimize the attack surface and protect your systems from such vulnerabilities.

Timeline

Published on: 04/22/2024 21:15:49 UTC
Last modified on: 06/10/2024 18:15:32 UTC