Skip to content
RCE Write-up Intermediate

From Comments to Command Execution: How an E-Book Platform Gave Me RCE

The e-book platform allowed users to upload files via comments, validating only the file signature (magic bytes) and not the extension, and stored them under the main domain. An attacker could upload a PHP file with an image signature, leading to stored XSS and remote code execution.

imooaaz Follow

Published on imooaaz.medium.com

The platform was polished and packed with functionality, including user accounts, a rich library, and even the ability to leave comments under specific passagesm, but these files needed approval from the admin before being published. Naturally, my first instinct was to test how secure it all was.

Moaaz Afifi, on imooaaz.medium.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

Impact

An attacker could execute arbitrary commands on the server, leading to full control, data breach, and pivoting to other systems.

What the attacker needed

A user account; ability to post comments with file attachments; admin approval of uploaded files

The fix

The report states the vulnerability was fixed, but does not detail the fix; recommended fixes include validating both file signatures and extensions, storing uploads on a separate domain, and restricting executable file types.

How it was found

  1. Upload an SVG file containing an XSS payload via the comment feature.
  2. Observe that the file is stored and the XSS payload executes when visited.
  3. Attempt to upload a PHP shell but receive a 403 Forbidden error.
  4. Rename the SVG file to .php and upload it; the server accepts it because it checks the file signature.
  5. Create a PNG image with PHP code appended and rename it to .php.
  6. Upload the file via the comment form; the server accepts it.

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 let people upload pictures in comments. It checked the file's content to see if it was an image, but didn't check the file name. So someone could upload a file that looked like an image but was actually a program, and then run commands on 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 imooaaz

View all

1 more disclosed report, 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.