From File Upload to Shell: A Deep Dive into RCE Exploits
The file upload feature only checked file extensions and not the actual content type, allowing the upload of a PHP web shell. An attacker could then execute commands on the server and obtain a reverse shell.
medium.com
Published on medium.com
File upload features are everywhere — profile pictures, documents, banners, resumes. But what if I told you that one poorly secured upload form can let an attacker gain full control of your 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 server relied on client-supplied file extensions and MIME types without validating the actual file content or restricting execution.
Impact
An attacker could execute arbitrary commands on the server and gain a reverse shell, leading to full server compromise.
What the attacker needed
Access to an upload form; server executes uploaded files
The fix
The upload should validate file content, restrict executable extensions, and store uploads outside the web root.
How it was found
- Identify the server technology and programming language.
- Find an image upload feature that only allows certain extensions.
- Upload a text file with a spoofed image content type to confirm the bypass.
- Upload a PHP web shell with a PHP content type.
- Access the uploaded shell via its public URL.
- Upload a PHP reverse shell file to gain a shell.
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 form that only looks at the file name (like .jpg) can be tricked. The attacker changes the file's declared type to something the server trusts, uploads a script, and then runs it to take over the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.