Python Web Penetration Testing — Day 11: Remote Code Execution
The application accepted any file type in its uploader and saved it to a web-accessible directory, so an uploaded PHP file was executed by the server. The author used this to run commands and obtain a reverse shell as the web server user.
Published on osintteam.blog
Free Link
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 upload handler did not check the file type or extension and stored files in a directory from which the web server executes scripts.
Impact
An attacker could execute arbitrary commands on the server, read files, access database credentials, and pivot to the internal network.
What the attacker needed
A file upload feature; server executes uploaded files
How it was found
- Upload a PHP file disguised as an image to the file uploader.
- The server saves the file and executes it when accessed.
- Set up a listener and send a reverse shell command through the uploaded file.
- Receive a connection back as the www-data user.
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.
A file upload feature that lets you put any kind of file on the server is dangerous if the server then runs that file as a program. Here, the author uploaded a small script written in PHP (a language many websites use) and the server ran it, giving the author a way to type commands on the machine. This is called remote code execution because the attacker can run their own code on someone else's computer.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.