LFI to RCE: Weaponizing File Uploads with PHP Shells
A file upload feature allowed uploading files with PHP code disguised as images, and a local file inclusion vulnerability in a language parameter executed those files, leading to remote code execution. An attacker could upload a malicious file and then include it to run arbitrary commands on the server.
medium.com
Published on medium.com
Everything we did before was either injecting code through the URL or fetching it from our own machine. This section takes a different approach.
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 application uses an include() statement on user-controlled input without validating that the included file is safe, and the upload feature does not prevent files containing executable code from being stored.
Impact
An attacker could execute arbitrary commands on the server, leading to full compromise.
What the attacker needed
A file upload feature; a local file inclusion vulnerability; knowledge of the upload directory
The fix
The include() function should validate and restrict which files can be included, and the upload feature should verify file contents and store uploads outside the web root with non-executable permissions.
How it was found
- Create a file that starts with GIF magic bytes and contains PHP code.
- Upload the file through the profile picture upload form.
- Find the uploaded file's location by viewing the page source.
- Include the uploaded file via the vulnerable language parameter and execute a command.
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.
The website lets you upload a profile picture, but it doesn't check the file's contents carefully. Another part of the site includes files based on a URL parameter, and if that file contains PHP code, the server runs it. So an attacker can upload a file that looks like an image but contains code, then trick the site into running it.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.