Skip to content
Memory corruption Disclosed report Advanced CVE-2019-5436

CVE-2019-5436: Heap Buffer Overflow at lib/tftp.c

A heap buffer overflow occurs in curl's TFTP client when the user sets a block size below 293, because the code uses the default block size instead of the user-specified one. An attacker controlling a TFTP server could crash the client and potentially achieve remote code execution if a memory leak is also present.

l00p3r Follow

Originally disclosed on HackerOne

  • Triaged in 3 hours
  • Fixed in 23 days
  • Paid in 10 days
  • Disclosed after 32 days

Summary:

A heap buffer overflow can occur at line 1114 in file lib/tftp.c due to the fact of state->blksize containing the default size instead of containing the one specified in the --tftp-blksize parameter.

This bug could lead to a crash or maybe to RCE in the case the attacker also had a memory leak.

Vulnerable line:

state->rbytes = (int)recvfrom(state->sockfd,
                                (void *)state->rpacket.data,
                                state->blksize + 4,
                                0,
                                (struct sockaddr *)&fromaddr,
                                &fromlen);

Steps To Reproduce:

  1. Download the server script
  2. Run it and bind to an address: $ python evil-server.py IP PORT
  3. Connect to that server with curl: $ curl --tftp-blksize N tftp://IP:PORT

Where N should be a number lower than 293.

Impact

  • An attacker would also need a memory leak in order to gain full RCE.
  • The victim should explicitly set the --blksize argument to a value inferior to 293.

Thus, the impact is not very high but it's still quite dangerous to not release a patch.

The original report as published on HackerOne, by l00p3r. 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

Likely the code uses the default block size instead of the user-specified one when calculating the receive buffer size, leading to a heap overflow.

Impact

The bug could cause a crash, and possibly remote code execution if the attacker also has a memory leak, but the victim must explicitly set a block size below 293.

What the attacker needed

Victim sets --tftp-blksize below 293; attacker controls TFTP server

How it was found

  1. Download the server script
  2. Run it and bind to an address
  3. Connect to that server with curl using a block size lower than 293

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 reads data into a buffer sized according to a block size setting. If you set that block size very small, the program still uses the default larger size, so it writes more data than the buffer can hold. This can crash curl, and in rare cases an attacker might exploit it to 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.