TL;DR
Some servers incorrectly block files based on their Content-Type header (e.g., text/plain) even if the file content itself is executable code like PHP or JavaScript. This guide shows how to bypass this restriction by manipulating the request and server response.
Solution
- Understand the Problem: Servers sometimes rely too heavily on
Content-Typeheaders instead of actually examining file content. If a server seestext/plain, it might refuse to execute the file, even if it’s valid PHP or JavaScript.- This is often a security measure gone wrong – it’s easy to circumvent and doesn’t reliably protect against malicious uploads.
- Attempt Direct Execution (First Try): Before trying anything complex, simply try accessing the uploaded file directly in your browser.
- If this works, you’re lucky! The server might not be enforcing the
Content-Typerestriction as strictly.
- If this works, you’re lucky! The server might not be enforcing the
- Manipulate the Request with a Different Extension: Try changing the file extension in the URL.
- If your uploaded file is named
shell.txt, try accessing it asshell.phporshell.js. The server might ignore the original extension and execute based on the new one. - Example: If you upload
shell.txtcontaining PHP code, tryhttp://example.com/uploads/shell.php.
- If your uploaded file is named
- Use a Different Content-Type Header (Client-Side): You can attempt to trick the server by sending a different
Content-Typeheader with your request.- This is best done using tools like
curlor browser developer tools. - Using curl:
curl -H "Content-Type: application/php" http://example.com/uploads/shell.txt(Replace
application/phpwith the appropriate MIME type for your file content, e.g.,application/javascript).
- This is best done using tools like
- Exploit Server-Side Parsing Vulnerabilities: Some servers may have vulnerabilities in how they parse files.
- PHP Code Injection (if the server parses PHP): If the server is configured to parse PHP code within HTML or other file types, you might be able to inject PHP code directly into your
text/plainfile. For example, if the server allows PHP tags in .html files, you could upload a file like:<?php system($_GET['cmd']); ?>and access it as
http://example.com/uploads/shell.html?cmd=whoami.
- JavaScript Injection (if the server executes JavaScript): Similar to PHP, if the server allows JavaScript execution in HTML or other file types, you can inject JavaScript code.
<script>alert('XSS');</script>
- PHP Code Injection (if the server parses PHP): If the server is configured to parse PHP code within HTML or other file types, you might be able to inject PHP code directly into your
- File Inclusion Vulnerabilities (if applicable): If the server has a file inclusion vulnerability, you might be able to include your
text/plainfile as part of another script.- Example: If there’s a vulnerable parameter like
file=in a URL:http://example.com/index.php?file=/uploads/shell.txt
- Example: If there’s a vulnerable parameter like
- Double Extension Bypass (if the server only checks the last extension): Some servers only check the final file extension.
- Upload a file named
shell.txt.phporshell.php.txt. The server might execute it as PHP if it sees the.phpextension at the end.
- Upload a file named

