Skip to content
File upload Write-up Beginner

Ketika Validasi MIME Type Tak Cukup: Perbaikan Aman untuk Upload

A PHP file-upload handler that checked only the MIME type could be bypassed by editing the multipart request in an intercepting proxy, so a file named with a .php.png double extension was accepted and then executed. An attacker who can upload could therefore run PHP code on the server.

Ferizco Follow

Published on medium.com

Halo Sobat! Pada video saya sebelumnya saya memberikan tips bagaimana cara mengamankan upload file di PHP dengan memvalidasi MIME Type file yang diupload.

Ferizco, 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 handler trusted the client-supplied MIME type and the original filename, and saved the file under a name whose extension the web server still executes.

Impact

An uploaded file could be executed by the server, giving the uploader code execution on the host.

What the attacker needed

Ability to upload a file; an intercepting proxy

The fix

The author proposes renaming the stored file to a base64-encoded name with the correct extension before saving it, so a tampered name cannot end in an executable extension.

How it was found

  1. Intercept the upload request in the browser using an intercepting proxy.
  2. Upload a file with a png format as usual to capture the request.
  3. Edit the captured request: remove some lines and add a php command.
  4. Rename the file to the name-file.php.png format and forward the request.
  5. The file is uploaded despite the MIME check and can be executed.

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 that lets people upload pictures should check what the file really is, not just the label the browser sends. Here the check trusted that label, so someone could rename a script to look like an image and the server would still run it as code. Running your own code on a server is a serious problem because it can lead to reading data or taking the site over.

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.