Persistent PHP Payloads In PNGs: How To Inject PHP Code In An Image – And Keep It There !
A PHP application allowed users to upload PNG images that were stored with the original filename, so an attacker could name the file with a .php extension and embed PHP code in the image. When the file was requested, the server executed the PHP code, leading to remote code execution.
Published on synacktiv.com
Rédigé par Quentin Roland - 10/10/2022 - dans Pentest - 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
Impact
An attacker could execute arbitrary PHP code on the server, leading to remote code execution.
What the attacker needed
A valid PNG file; ability to upload files; the server executes PHP in the upload directory
How it was found
- Create a valid PNG file and inject PHP code into it, for example by adding a comment or appending code after the image data.
- Rename the PNG file to have a .php extension.
- Upload the file through the application's form.
- Access the uploaded file via its public URL to trigger execution of the PHP code.
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.
When you upload a picture, the website usually saves it with a name you provide. If the website also runs PHP code, an attacker can name the picture something ending in .php and hide PHP code inside the picture file. When someone visits that file, the server runs the hidden code instead of just showing the picture.
What is File upload?
An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.