Skip to content
File upload Write-up Beginner

Exploiting Remote code execution via polygot web shell upload

The lab's avatar upload accepted a PHP file that was also a valid JPEG because the server only checked image magic bytes and allowed a .php extension. An attacker could upload a web shell and execute it from the avatars directory to read a secret file.

medium.com

Published on medium.com

Yo fellas today ill be walking you through how I exploited a web shell vulnerability in a safe lab using ExifTool on linux. The lab can be found here

Cybernerddd, on 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

Root cause

Likely the upload validation trusted the file's magic bytes and extension separately, and the avatars directory executed PHP files.

Impact

An attacker could execute code on the server and read files such as the secret in the user's home directory.

What the attacker needed

A free account; ability to upload an avatar

The fix

Uploads should be served from a non-executable directory, metadata should be stripped, and both content and extension should be validated.

How it was found

  1. Use ExifTool to inject PHP code into the metadata of a valid JPEG and save the output with a .php extension.
  2. Log in and upload the resulting file as the avatar; the server accepts it.
  3. Find the stored path of the uploaded file, for example under /files/avatars/.
  4. Request the uploaded file so the PHP executes and returns the secret between the START and END markers.

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 web shell is a small script an attacker uploads to a server so they can run commands on it later. Here the upload check only looked at the first few bytes of the file to confirm it was an image, so a file that was both a picture and a PHP script slipped through. Because the server also allowed the .php extension and ran files in that folder, the script executed and revealed a secret file.

What is File upload?

An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.

Similar reports

View all

Same bug class and techniques, clearest first.

Unrestricted file upload

The lesson behind this report.

An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.