File upload vulnerabilities
PortSwigger Web Security Academy · Practitioner
- #File upload

Web Shell Upload via Path Traversal
The vulnerability
PHP files aren’t executed in the upload folder. With an encoded ../ in the filename, the file ends up one folder higher, where they are.
Fix: Create the filename yourself instead of using the one from the request.
The lab
This lab contains a vulnerable image upload function. The server is configured to prevent execution of user-supplied files, but this restriction can be bypassed by exploiting a secondary vulnerability.
To solve the lab, upload a basic PHP web shell and use it to exfiltrate the contents of the file
/home/carlos/secret. Submit this secret using the button provided in the lab banner.You can log in to your own account using the following credentials: wiener:peter
Solution
1. Create a PHP Web Shell: Create a simple PHP file (e.g., exploit.php) with the following content.
<?php echo file_get_contents('/home/carlos/secret'); ?>
2. Upload and Intercept Request: Log in as wiener:peter and try to upload the exploit.php file. In Burp Suite's Proxy → HTTP history, find the POST /my-account/avatar request and Send to Repeater.
3. Bypass Path Traversal Restriction: In Repeater, modify the filename parameter in the request body. Change exploit.php to a path traversal payload like ../exploit.php. The server should block this. Now, try URL-encoding the forward slash (/) in the filename: filename="../exploit.php". An HTTP/2 200 OK response indicates a successful bypass.
4. Execute the Web Shell and Solve: The file has been uploaded to a new, executable location. Right-click on your avatar and select “Open Image in New Tab.” Modify the URL of the new tab to include the path traversal sequence (e.g., change /files/avatars/exploit.php to /files/avatars/../exploit.php) and reload. The PHP code will execute, and the content of /home/carlos/secret will be displayed, and the lab is solved.
Web Shell Upload via Extension Blacklist Bypass
The vulnerability
The server blocks .php, but not .htaccess. With that file you tell Apache to run your own file extension as PHP.
Fix: Use a list of allowed extensions instead of a list of forbidden ones.
The lab
This lab contains a vulnerable image upload function. Certain file extensions are blacklisted, but this defense can be bypassed due to a fundamental flaw in the configuration of this blacklist.
To solve the lab, upload a basic PHP web shell, then use it to exfiltrate the contents of the file
/home/carlos/secret. Submit this secret using the button provided in the lab banner.You can log in to your own account using the following credentials: wiener:peter
Solution
1. Create a Malicious .htaccess File: Create a file named .htaccess with the following content. This rule tells the server to execute any file with a .clawhak extension as a PHP script.
AddType application/x-httpd-php .clawhak
2. Create a PHP Web Shell: Create a PHP file with a .clawhak extension (e.g., exploit.clawhak) with the following content.
<?php echo file_get_contents('/home/carlos/secret'); ?>
3. Upload the .htaccess File: Log in as wiener:peter and upload the .htaccess file as your avatar. An HTTP/2 200 OK response confirms the successful upload.
4. Upload the Web Shell: Now, upload the exploit.clawhak file. The server will accept it since .clawhak is not on the blacklist.
5. Execute the Web Shell and Solve: Right-click on the new avatar and select “Open Image in New Tab.” The server will execute the exploit.clawhak file as PHP, and the content of /home/carlos/secret will be displayed, and the lab is solved.
Web Shell Upload via Obfuscated File Extension
The vulnerability
The check sees a filename that ends in .jpg. When the server saves the file, it stops at the null byte, and the name ends in .php.
Fix: Reject null bytes, and create the filename yourself.
The lab
This lab contains a vulnerable image upload function. Certain file extensions are blacklisted, but this defense can be bypassed using a classic obfuscation technique.
To solve the lab, upload a basic PHP web shell, then use it to exfiltrate the contents of the file
/home/carlos/secret. Submit this secret using the button provided in the lab banner.You can log in to your own account using the following credentials: wiener:peter
Solution
1. Create a PHP Web Shell: Create a PHP file (e.g., exploit.php) with the following content.
<?php echo file_get_contents('/home/carlos/secret'); ?>
2. Intercept the Upload Request: Log in as wiener:peter and try to upload your exploit.php file. The upload will be blocked. In Burp Suite's Proxy → HTTP history, find the POST /my-account/avatar request and Send to Repeater.
3. Bypass with Null Byte: In Repeater, modify the filename parameter in the request body. Change the filename to exploit.php followed by a URL-encoded null byte (%00) and a permitted extension like .jpg: filename="exploit.php%00.jpg". Send the request. An HTTP/2 200 OK response confirms that the file was uploaded.
4. Execute the Web Shell and Solve: Right-click on the new avatar and select “Open Image in New Tab.” Remove the %00.jpg from the end of the filename in the URL bar and reload the page. The PHP code will execute, displaying the content of /home/carlos/secret, and the lab is solved.
Remote Code Execution via Polyglot Web Shell Upload
The vulnerability
This time the server really checks whether the file is an image. An image can also contain PHP code in its metadata, and the server runs it if the extension is .php.
Fix: Only allow image extensions, and re-encode uploaded images.
The lab
This lab contains a vulnerable image upload function. Although it checks the contents of the file to verify that it is a genuine image, it is still possible to upload and execute server-side code.
To solve the lab, upload a basic PHP web shell, then use it to exfiltrate the contents of the file
/home/carlos/secret. Submit this secret using the button provided in the lab banner.You can log in to your own account using the following credentials: wiener:peter
Solution
1. Create a Polyglot File: Use a tool like exiftool to embed a PHP payload into a valid image file. Open your terminal and run the following command on a sample image file (e.g., image.png) to create a polyglot file named polyglot.php.
exiftool -Comment="<?php echo 'START ' . file_get_contents('/home/carlos/secret') . ' END'; ?>" image.png -o polyglot.php
- The resulting
polyglot.phpfile will be a valid image but will also contain the PHP code in its metadata.
3. Upload the Polyglot File: Log in as wiener:peter and upload the polyglot.php file as your avatar. The application will accept it as a valid image. An HTTP/2 200 OK response confirms the successful upload.
4. Execute the Web Shell and Solve: Right-click on the new avatar and select “Open Image in New Tab.” The PHP code will be executed, and the content of /home/carlos/secret will be displayed between the "START" and "END" markers you added. Submit this content to solve the lab.