FTP path trickery leads to NIL byte out of bounds write
Project curl Security Advisory, March 14th 2018 - Permalink
curl can be fooled into writing a zero byte out of bounds.
This bug can trigger when curl is told to work on an FTP URL, with the setting to only issue a single CWD command (
--ftp-method singlecwd or the libcurl alternative
curl then URL-decodes the given path, calls strlen() on the result and deducts the length of the file name part to find the end of the directory within the buffer. It then writes a zero byte on that index, in a buffer allocated on the heap.
If the directory part of the URL contains a "%00" sequence, the directory length might end up shorter than the file name path, making the calculation
size_t index = directory_len - filepart_len end up with a huge index variable for where the zero byte gets stored:
heap_buffer[index] = 0. On several architectures that huge index will wrap and work as a negative value, thus overwriting memory before the intended heap buffer.
By using different file part lengths and putting %00 in different places in the URL, an attacker that can control what paths a curl-using application uses can write that zero byte on different indexes.
The Common Vulnerabilities and Exposures (CVE) project has assigned the name CVE-2018-1000120 to this issue.
CWE-122: Heap-based Buffer Overflow
- Affected versions: curl 7.12.3 to and including curl 7.58.0
- Not affected versions: curl < 7.12.3 and curl >= 7.59.0
- Introduced-in: https://github.com/curl/curl/commit/6e1e9caa32da0995
libcurl is used by many applications, but not always advertised as such.
In curl version 7.59.0, curl rejects FTP URLs that contain any "control characters". That is byte values below ascii 32.
We suggest you take one of the following actions immediately, in order of preference:
A - Upgrade curl to version 7.59.0
B - Apply the patch to your version and rebuild
C - Do not enable singlecwd mode for FTP transfers
It was reported to the curl project on January 29, 2018
We contacted distros@openwall on March 7, 2018.
curl 7.59.0 was released on March 14 2018, coordinated with the publication of this advisory.
- Reported-by: Duy Phan Thanh
- Patched-by: Daniel Stenberg
Thanks a lot!