Skip to content
Disclosed report Advanced

TFTP accepts a first response from an IP other than the requested server

curl's TFTP client pins the first response packet's sender as the transfer peer without checking that its IP matches the server address in the URL. An attacker who can send UDP packets to the client's ephemeral port and answer first can receive uploaded file bytes or supply the download contents.

sushiikan Follow

Originally disclosed on HackerOne

  • Disclosed after 5 days

Summary:

When curl sends a TFTP request to the IP in the URL, it accepts the first valid response from any source IP and pins that sender as the transfer peer. A host that can get UDP packets to the client's ephemeral port and win this first-response race can receive bytes from a TFTP upload or provide the contents of a download

Affected version

Tested with curl 8.22.0 and master commit 098d3a0d4044d8a3f0a8617a5a5a30cde90fba26, on Linux in isolated network namespaces, with TFTP enabled. The release test recorded 5/5 synthetic uploads reaching the competing responder and 3/5 downloads returning its data, these are results from this isolated environment setup, not a general success rate.

Steps To Reproduce:

  1. Build curl 8.22.0 with TFTP support on Linux
  2. In an isolated Linux environment that supports unprivileged user and network namespaces, place tftp-test.py and tftp-test-spray.c from the attachments in the same directory.
  3. Run python3 tftp-test.py /path/to/curl-8.22.0/curl --seconds 2 --trials 5 --start-delays-ms 0,250,500,750,1000.
  4. Review the harness output and ftft-testing.log
  5. For the control, repeat the run with --drop-attacker, the competing responder should no longer win.

Root cause

The initial RRQ/WRQ is sent to the URL-selected address obtained from Curl_conn_get_remote_addr() (lib/tftp.c:754-761). On receive, recvfrom() supplies a sender address. The current logic checks it only after a peer has already been pinned; the first sender is copied directly into state->remote_addr. This simplified excerpt is from tftp_receive_packet() (lib/tftp.c:1057-1071):

C
if(state->remote_pinned) {
  if((state->remote_addrlen != fromlen) ||
     memcmp(&remote_addr, &state->remote_addr, fromlen))
    return CURLE_RECV_ERROR;
}
else {
  state->remote_pinned = TRUE;
  state->remote_addrlen = fromlen;
  memcpy(&state->remote_addr, &remote_addr, fromlen);
}

This pins the first packet's complete endpoint, including its source IP and UDP port, but does not compare that IP with the address used for the request. The later comparison only ensures subsequent packets match the first responder; it cannot reject a different host that wins the first-response race. TFTP servers use a new UDP transfer port, so curl should allow that port change while requiring the first response's address family and IP (and IPv6 scope, where applicable) to match the URL selected endpoint. It can then pin the accepted transfer port and validate later packets against that transfer endpoint.

Limitations

The attack requires unsolicited UDP packets to reach curl's ephemeral TFTP port and the competing response to arrive before the selected server's response. Stateful firewalls and NAT can prevent that reachability.

Impact

If an application relies on the TFTP URL's IP to select a trusted endpoint, an attacker able to reach the client's ephemeral UDP port and win the race can read the file being uploaded or make the application consume attacker-chosen download data as a successful transfer.

The original report as published on HackerOne, by sushiikan. 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 first received packet's full endpoint is pinned as the peer without comparing its source IP to the address the request was sent to.

Impact

An attacker able to reach the client's ephemeral UDP port and win the race could read an uploaded file or make the application accept attacker-chosen download data; stateful firewalls and NAT can prevent this reachability.

What the attacker needed

Attacker can send UDP to client's ephemeral port; attacker response arrives before the real server's; no stateful firewall or NAT blocking it

The fix

curl should require the first response's address family and IP (and IPv6 scope) to match the URL-selected endpoint, then pin the accepted transfer port and validate later packets against it.

How it was found

  1. Build curl 8.22.0 with TFTP support on Linux.
  2. Place the provided test harness files in one directory inside an isolated Linux environment with user and network namespaces.
  3. Run the Python harness against the built curl with several trials and start delays.
  4. Review the harness output and its log file.
  5. Repeat with the attacker responder dropped as a control; it should no longer win.

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.

TFTP is a simple file transfer protocol over UDP, where the client asks a server for a file and the server replies from a new port. curl remembered whoever replied first as the real server, without checking the reply came from the address it had asked. Someone on the network who replies faster than the real server can then take over the transfer.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.