Skip to content
File upload Write-up Intermediate

Bypassed! and uploaded a sweet reverse shell

The profile picture upload only checked the file's magic number to decide if it was an image, so a PHP reverse shell with a JPEG header prepended was accepted. The attacker could then execute the shell by viewing the profile, gaining remote command execution.

Ajay Sharma Follow

Published on infosecwriteups.com

Initially being a private program, lets call it target.com. They had a functionality to upload a profile pic which only accepts jpg, png, jpeg images.

Ajay Sharma, on infosecwriteups.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

The upload validation relied only on the file's magic number and did not verify the actual content or prevent execution of uploaded files.

Impact

An attacker could upload and execute a reverse shell, gaining remote control of the server.

What the attacker needed

Ability to upload a profile picture; a hex editor to modify the file

How it was found

  1. Try uploading a PHP reverse shell file directly, which fails.
  2. Try double extensions, content-type changes, case variations, and special characters, all of which fail.
  3. Prepend the JPEG magic number to the PHP reverse shell file using a hex editor.
  4. Upload the modified file, which is accepted.
  5. Click view profile to execute the reverse 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 website let people upload a profile picture and tried to block anything that was not an image by looking at the first few bytes of the file, called the magic number. The author put the bytes that mean 'this is a JPEG' at the start of a malicious PHP script, so the check passed. When the file was later opened, the server ran the PHP code, giving the attacker control of the server.

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.