Skip to content
RCE Write-up Beginner

The Accidental RCE: How a Simple File Upload Led to Remote Code

A file upload feature accepted a file with a double extension and then executed the PHP code inside it when the file was accessed via its URL. An attacker could run system commands and read sensitive files on the server.

Krish_cyber Follow

Published on cybersecuritywriteups.com

Imagine uploading what seems like a harmless image, only to gain full control over a web server. Sounds like a hacker’s dream, right?

Krish_cyber, on cybersecuritywriteups.com

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 validated only the file extension and stored uploaded files in a web-accessible directory where they could be executed.

What the attacker needed

Ability to upload a file; server executes uploaded files

The fix

The vulnerability was fixed by the company after responsible disclosure.

How it was found

  1. Check that the site only allows .jpg, .png, and .gif extensions.
  2. Try renaming a .php file to .jpg and observe that the backend rejects it.
  3. Notice that uploaded files are stored in an uploads directory and accessible via direct URL.
  4. Rename the payload file to have a double extension (.php.jpg) and upload it.
  5. Access the uploaded file via its URL and observe that the server executes 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.

A file upload feature let people send pictures, but the server did not properly check what kind of file it was. By naming a malicious file with two extensions, the attacker tricked the server into running it as a program, giving them control 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.

More by Krish_cyber

View all

12 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.