CVE-2018–17057 writeup
A PDF-conversion website used an outdated TCPDF library that deserialises PHP objects when a phar:// path is passed as the image location. An attacker could craft a JPEG carrying a serialised object so that, on destruction, the server reads and prints an arbitrary file such as the flag.
medium.com
Published on medium.com
ใน website นี้จะใช้ lib TCPDF version < 6.2.22 ซึ่งจะมีช่องโหว่ PHP deserialization อยู่ ทำให้ attacker สามารถอ่าน file บน server ได้ตามใจชอบ
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
Likely the application passed user-controlled input into a PHP file function that resolves phar:// paths, triggering object deserialisation of a gadget class whose destructor reads a file.
Impact
An attacker could read arbitrary files on the server, including the flag, limited to files the web process can access.
What the attacker needed
PHP 7 to build the payload; ability to upload an image; control over the image path input
The fix
The library should be upgraded to a version that does not deserialise phar:// paths, and user input should not be passed into file functions unchecked.
How it was found
- Set up a PHP 7 environment and download the phpggc tool.
- Modify the gadget chain so the serialised object is the PDFCreator class with tmpfile pointing at the target file.
- Generate a JPEG that hides the serialised payload using phpggc.
- Upload the crafted JPEG to the target website.
- Change the image path input to a phar:// dynamic path so the library deserialises it.
- Read the flag printed when the PDFCreator object is destroyed.
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.
Some PHP code can turn a specially formatted text string back into a live object, a process called deserialisation. If an attacker controls that string, they can pick which class gets rebuilt and which file it touches. Here the image path was fed into a function that triggers this, so a crafted image made the server print a file the attacker chose.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.