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.
- 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:
- Download the server script
- Run it and bind to an address:
$ python evil-server.py IP PORT - 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
--blksizeargument to a value inferior to 293.
Thus, the impact is not very high but it's still quite dangerous to not release a patch.
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
- Download the server script
- Run it and bind to an address
- 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.