Phar Deserialization (CVE-2023-28115 Patch Bypass)
The patch for CVE-2023-28115 in the Snappy PHP library only checked for the lowercase 'phar://' string, but PHP wrappers are case-insensitive, so an attacker could use 'PHAR://' to trigger PHAR deserialization and achieve remote code execution. This allows arbitrary code execution and filesystem access if the attacker can control the output filename and upload a malicious PHAR file.
Published on synacktiv.com
18/09/2023 - Téléchargement
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The patch used a case-sensitive check for the 'phar://' string, but PHP stream wrappers are case-insensitive, so the check could be bypassed with different capitalisation.
Impact
A successful exploitation allows executing arbitrary code and accessing the underlying filesystem, but the attacker must be able to upload a file and the server must run PHP prior to version 8.
What the attacker needed
Attacker can control output filename; attacker can upload a file; server runs PHP < 8
The fix
The fix should ensure that the check for the 'phar://' wrapper is case-insensitive, for example by using a case-insensitive comparison or by normalising the string before checking.
How it was found
- Generate a malicious PHAR file using phpggc with the -f option to force fast destruct.
- Create a PHP script that instantiates the Snappy Pdf class and calls generateFromHtml() with the malicious PHAR path as the second argument.
- Run the PHP script, which triggers deserialization and executes the payload, creating a file on the filesystem.
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 write-up has not been written yet. The Original tab links to the source.
This report describes a way to bypass a security fix in a PHP library. The library lets developers generate PDFs from HTML, and it takes a filename for the output. The original bug allowed an attacker to use a special 'phar://' file path to trick PHP into running hidden code inside a malicious file. The fix tried to block that by checking for the exact text 'phar://', but because PHP ignores case in these paths, an attacker could simply write 'PHAR://' and the check would miss it, allowing the same attack again.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.