Skip to content
Memory corruption Disclosed report Advanced

Heap Buffer Overflow in TFTP

libcurl's TFTP client accepts an OACK with a larger blksize but does not resize its receive and send buffers, so later data transfer writes past the heap allocation. A malicious TFTP server could crash the client or possibly achieve code execution.

helspy Follow

Originally disclosed on HackerOne

Critical View original
  • Disclosed after 39 hours

Summary:

A heap buffer overflow vulnerability exists in the TFTP implementation of libcurl. The vulnerability is triggered when a malicious TFTP server sends an OACK (Option acknowledgment) packet with a blksize option that is larger than the default block size (512 bytes). libcurl updates its internal block size variable but fails to reallocate the receive and send buffers (rpacket and spacket). When the application subsequently receives data (in tftp_rx) or sends data (in tftp_tx) using the larger block size, it writes past the end of the allocated buffer, leading to a heap buffer overflow.

Affected version

curl 8.18.0-DEV (based on LIBCURL_VERSION in include/curl/curlver.h) Platform: Windows (reproduced on)

Steps To Reproduce:

  1. Save the provided reproduction script as tftp_repro.py.
  2. Run the script: python tftp_repro.py. This starts a malicious TFTP server on port 6969.
  3. In another terminal, run a curl command to fetch a file from this server: curl tftp://localhost:6969/test (Note: Ensure you are using a curl build that includes this vulnerable code. If testing with a system curl, it might not be vulnerable or might be a different version).
  4. The server will send an OACK with blksize=2048 and then a DATA packet of 2048 bytes.
  5. The curl client will crash or exhibit undefined behavior due to the heap overflow.

Supporting Material/References:

Vulnerable Code Location: lib/tftp.c, function: tftp_parse_option_ack updates state->blksize without reallocating state->spacket.data and state->rpacket.data. Reproduction Script: tftp_repro.py

Impact

Summary:

This vulnerability allows a malicious TFTP server to cause a heap buffer overflow on the client.

Remote Code Execution (RCE): By carefully crafting the payload in the DATA packet, an attacker could overwrite critical heap metadata or function pointers, potentially leading to arbitrary code execution on the victim's machine with the privileges of the curl process.

Denial of Service (DoS): The overflow can corrupt memory structures, causing the curl application to crash or behave unpredictably, leading to a denial of service.

Impact

Summary:

This vulnerability allows a malicious TFTP server to cause a heap buffer overflow on the client.

Remote Code Execution (RCE): By carefully crafting the payload in the DATA packet, an attacker could overwrite critical heap metadata or function pointers, potentially leading to arbitrary code execution on the victim's machine with the privileges of the curl process. Denial of Service (DoS): The overflow can corrupt memory structures, causing the curl application to crash or behave unpredictably, leading to a denial of service.

The original report as published on HackerOne, by helspy. 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 option-acknowledgement parser updates the negotiated block size without reallocating the packet buffers that were sized for the previous block size.

Impact

A malicious TFTP server could crash the client (denial of service) and, by crafting the DATA packet, potentially overwrite heap metadata or function pointers to achieve code execution with the curl process's privileges.

What the attacker needed

Victim connects to a malicious TFTP server; curl build contains the vulnerable code

How it was found

  1. Save the reproduction script and run it to start a malicious TFTP server on port 6969.
  2. In another terminal, use a vulnerable curl build to fetch a file from that server.
  3. The server replies with an OACK advertising a 2048-byte block size, then sends a 2048-byte DATA packet.
  4. The curl client crashes or behaves unpredictably because of the heap overflow.

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.

When curl downloads a file over TFTP, it agrees a block size with the server and allocates memory for blocks of that size. Here it agreed a bigger block size but kept the old, smaller memory, so incoming or outgoing data spills past the end of that memory. That memory corruption can crash curl and, in theory, let an attacker run their own code.

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 curl

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.