Skip to content
Path traversal Disclosed report Advanced

[HIGH] CWE-22 — Path Traversal in FTP Wildcard Download via Unencoded `.` in Escaped Filenames

A malicious or intercepted FTP server can return a LIST response with a filename containing path-traversal sequences, causing a client using wildcard matching to download files outside the intended remote directory. The escaping step leaves dots unencoded, and a later URL-decode step reconstructs the traversal sequence without filtering it.

mrtomato Follow

Originally disclosed on HackerOne

  • Disclosed after 35 hours

Summary

A malicious or MITM'd FTP server can cause a client using CURLOPT_WILDCARDMATCH to download files outside the intended remote directory, by returning a LIST response with a filename containing .. path-traversal sequences.

Details

In the CURLWC_DOWNLOADING state (lib/ftp.c:4079-4095), each filename returned by the server's LIST response is escaped with curl_easy_escape() before being appended to the current wildcard path:

`char *enc = curl_easy_escape(NULL, finfo->filename, 0);`
...
`tmp_path = curl_maprintf("%s%s", wildcard->path, enc);`
...
`ftp->pathalloc = ftp->path = tmp_path;`

curl_easy_escape() percent-encodes everything except the RFC 3986 unreserved character set (A-Za-z0-9-._~), critically, . is NOT encoded. A filename of ../etc/passwd therefore escapes to ..%2Fetc%2Fpasswd (dots preserved literally, only the / gets encoded).

Immediately afterward, ftp_parse_url_path() (lib/ftp.c:207-227) is called on this same path, and its very first step is:

`result = Curl_urldecode(ftp->path, 0, &ftpc->rawpath, &pathLen, REJECT_CTRL);`

This URL-decodes the path, reconstructing the literal ../etc/passwd sequence. REJECT_CTRL only rejects control characters (confirmed by reading Curl_urldecode's REJECT_CTRL handling), there is no ..-component filtering or path-normalization check anywhere in this flow before the resulting path is used to drive the subsequent CWD/RETR sequence.

PoC

  1. Attacker controls or MITMs an FTP server.
  2. The client application uses wildcard matching: curl_easy_setopt(curl, CURLOPT_WILDCARDMATCH, 1L) against a URL like ftp://server/pub/*.txt
  3. The attacker's FTP LIST response includes a filename such as "../../etc/passwd" (or an absolute-looking component).
  4. curl_easy_escape() encodes it to "..%2F..%2Fetc%2Fpasswd" (dots preserved, slashes encoded).
  5. It is concatenated onto the current wildcard path.
  6. ftp_parse_url_path() -> Curl_urldecode() decodes it straight back to "../../etc/passwd" (or similar), with only control-character filtering.
  7. The resulting path drives the client's CWD/RETR sequence, traversing outside the directory the calling application intended to browse.

Suggested patch:

Diff
After URL-decoding in ftp_parse_url_path(), validate that the resulting
path does not contain ".." components that traverse outside the intended
directory. Alternatively, validate finfo->filename in the
CURLWC_DOWNLOADING state before it is ever escaped reject filenames
containing "/", "..", or an absolute-path leading "/".

Impact

Summary:

An application using CURLOPT_WILDCARDMATCH against an untrusted or compromised FTP server can be made to download files from arbitrary paths on that server, outside the directory the calling code intended, an information-disclosure / path-confinement bypass. Requires the calling application to have opted into wildcard matching; does not affect the default (non-wildcard) FTP/SFTP/HTTP transfer paths.

The original report as published on HackerOne, by mrtomato. 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 filename from the server's LIST response is escaped with a function that does not encode dots, then URL-decoded again without any check for '..' path components before the path is used.

Impact

An application using wildcard matching against an untrusted or compromised FTP server could be made to download files from arbitrary paths on that server, outside the intended directory; the default non-wildcard transfer paths are not affected.

What the attacker needed

Client enables wildcard matching; attacker controls or intercepts FTP server

The fix

The report suggests validating after URL-decoding that the path has no '..' components, or rejecting filenames with '/', '..' or a leading '/' before escaping.

How it was found

  1. The attacker controls or intercepts an FTP server.
  2. The client application enables wildcard matching against a URL with a wildcard pattern.
  3. The server's LIST response includes a filename containing path-traversal sequences.
  4. The client escapes the filename, leaving the dots unencoded.
  5. The escaped name is appended to the wildcard path and then URL-decoded back to a traversal sequence.
  6. The resulting path drives the client's directory-change and file-retrieval sequence outside the intended directory.

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 a program downloads files from an FTP server using a wildcard pattern, it asks the server for a list of matching filenames. This report shows that a hostile server can put a name like '../etc/passwd' in that list, and the client library will follow it and fetch a file from outside the folder the program meant to use. The library tries to make the name safe by encoding it, but it leaves the dots alone, so the '..' still works after a later decoding step.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.