-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a78562
commit d2d0f67
Showing
3 changed files
with
31 additions
and
19 deletions.
There are no files selected for viewing
50 changes: 31 additions & 19 deletions
50
..._vulnerabilities/Web_shell_upload_via_Content-Type_restriction_bypass/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,58 @@ | ||
# Lab: Web shell upload via Content-Type restriction bypass | ||
# Write-up: Web shell upload via Content-Type restriction bypass @ PortSwigger Academy | ||
|
||
 | ||
|
||
This write-up for the lab *Web shell upload via Content-Type restriction bypass* is part of my walkthrough series for [PortSwigger's Web Security Academy](https://portswigger.net/web-security). | ||
|
||
**Learning path**: Server-side topics → File upload vulnerabilities | ||
|
||
Lab-Link: <https://portswigger.net/web-security/file-upload/lab-file-upload-web-shell-upload-via-content-type-restriction-bypass> | ||
Difficulty: APPRENTICE | ||
Python script: [script.py](script.py) | ||
|
||
## Known information | ||
## Lab description | ||
|
||
- Applications contains vulnerable image upload | ||
- Some validations are performed on user input files | ||
- Known good credentials: `wiener:peter` | ||
- Goals: | ||
- Upload a PHP web shell | ||
- Exfiltrate `/home/carlos/secret` with this webshell | ||
 | ||
|
||
## Steps | ||
|
||
### First look | ||
|
||
The lab application is the trusty blog system again. As it happens often, the public area shows nothing of immediate interest. Therefore I login with the known credentials of `wiener`. | ||
The lab application is a blog website. On the public pages, nothing interesting appears obvious and I proceed to log in with the known user account of `wiener`. | ||
|
||
In the account settings, I can set both an email address and an avatar image for the user. | ||
|
||
In the account setting I can set both email address and avatar image for the user. | ||
--- | ||
|
||
### Find out what is allowed to upload | ||
|
||
Trying to upload the PHP script of the [previous lab](../Remote_code_execution_via_web_shell_upload/README.md) results in an error message: | ||
First I try to upload the PHP script of the [previous lab](../Remote_code_execution_via_web_shell_upload/README.md). This time, some upload restrictions are in place and I receive an error message: | ||
|
||
 | ||
|
||
However, the error message is kind enough to point in the right direction of which content types are allowed. | ||
However, the error message is kind enough to point out some details | ||
|
||
1. The first check that fails verifies the Content-type, which is a user-provided value. | ||
2. It shows the values for Content-Type that are permitted. | ||
|
||
--- | ||
|
||
### Modify content type | ||
|
||
The next step is to modify the content type within the request to one of the allowed types. If it is the only check it will succeed. If not, the error message might again give instructions how to proceed. | ||
The next step is to modify the content type within the request to one of the allowed types. | ||
|
||
If this is the only check that is performed, I will succeed. If not, the error message might again give instructions on how to proceed. | ||
|
||
I load the upload request into Repeater and change the content type. | ||
|
||
So I put the upload request into Repeater, change the content type and fire. In this case the content type check appears to be the only check, as the response states 'success': | ||
The response indicates success. This means the content-type verification is the only check that is performed by the application: | ||
|
||
 | ||
 | ||
|
||
Calling the uploaded script shows the data: | ||
The file name remained as `shell.php` so that the server can execute it. Calling the uploaded script shows the secret data: | ||
|
||
 | ||
 | ||
|
||
Submitting the secret results in | ||
After submitting the secret, the lab updates to | ||
|
||
 | ||
 |
Binary file added
BIN
+15.8 KB
...es/Web_shell_upload_via_Content-Type_restriction_bypass/img/lab_description.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+37.5 KB
...lnerabilities/Web_shell_upload_via_Content-Type_restriction_bypass/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.