Skip to content
File upload Write-up Intermediate

RCE through Zip Unarchiving

A file upload feature in an admin panel blocked direct PHP uploads and renamed .php files to .php_ when a ZIP was unarchived, but other PHP-executable extensions such as .phtml were not renamed. An attacker could upload a ZIP containing a .phtml script, unarchive it, and run commands on the server, leading to a reverse shell.

medium.com

Published on medium.com

In a recent pentest I found an interesting way to obtain remote code execution and eventually a reverse shell on the underlying system.

Cristi Vlad, 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 whitelist and the unarchive renaming logic only handled the .php extension, so other PHP-executable extensions passed through unchanged.

Impact

An attacker with access to the admin upload feature could run commands on the server and get a reverse shell, and because the machine hosted multiple vhosts and held AWS credentials, other environments and cloud resources could be reached.

What the attacker needed

Access to the admin panel upload feature; ability to unarchive uploaded ZIPs

The fix

The upload whitelist and the unarchive renaming should have covered every extension the server can execute, not just .php.

How it was found

  1. Try uploading a PHP file and observe that it is blocked.
  2. Upload a ZIP containing a PHP file and unarchive it, noting the extension becomes .php_.
  3. Build a ZIP with the same command script saved under several PHP-friendly extensions.
  4. Upload and unarchive the ZIP, and find that some extensions keep their original name.
  5. Visit the unarchived .phtml file with a command parameter to run commands.
  6. Start a listener and run a Python reverse shell command to get 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.

The site let admins upload files, and it tried to stop dangerous scripts by blocking or renaming files ending in .php. But the server also runs other file endings as code, and the unzip step only renamed .php, so a script with a different ending survived and could be run by visiting it. That gave 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.