Skip to content
File upload Write-up Beginner

Incorrect solution to disable script execution by .htaccess

The .htaccess rule intended to block script execution uses a case-sensitive regular expression, so an attacker can upload a file with a mixed-case extension such as .PhP and have it executed. This bypasses the protection and allows arbitrary code execution on the server.

soroush.me

Published on soroush.me

I saw some people using this code in the “.htaccess” file to disable script execution:

The author, on soroush.me

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 regular expression in the .htaccess rule is case-sensitive, so it fails to match uppercase or mixed-case file extensions.

Impact

An attacker who can upload files could execute arbitrary code on the server, bypassing the intended restriction.

What the attacker needed

Ability to upload files to the server

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 can use a configuration file called .htaccess to stop uploaded files from running as programs. The rule shown here only blocks lowercase extensions like .php, so a file named with uppercase letters (for example .PhP) slips through and runs. That means someone who can upload files could run their own code on 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.