Web Shell Upload via Content-Type Restriction Bypass (ENG 🇬🇧 | PL 🇵🇱 ) ​
🇬🇧 ENG:
In this lab, we will be uploading a shell and bypassing a certain security measure that involves checking the "Content-Type".
Click "Access the lab", we see a blog:

Exactly as described in the task, we log in to the account wiener:peter, previously going to "My Account".

Our task is to exploit a vulnerability in the file upload location, and then read the "secret" file in "carlos's" directory.

Click "Choose file". I have prepared a webshell (webshell.php) - for now, just to check if there are any protections regarding the extension of the given file. If we are to upload an avatar, a file with the .php extension should not pass.
We learn that there is validation:

Sorry, file type text/php is not allowed Only image/jpeg and image/png are allowed Sorry, there was an error uploading your file.Let's see if we can bypass this in Burp Suite. I find the request that was used to send the file:

Here you can see the file name:

I right-click and send to "Repeater":

In the "Repeater", I send our request again to check if everything works:

The application detected that it is a php file and correctly entered "Content-Type":


The question is whether we can modify the "Content-Type" and whether it will affect the security.
We have information in the response that image/jpeg and image/png files are allowed.
Let's replace the "Content-Type" in the request:

It turns out that this time after sending the request we receive a status code 200:

HTTP/2 200 OK
Date: Mon, 19 Feb 2024 18:06:05 GMT
Server: Apache/2.4.41 (Ubuntu)
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
X-Frame-Options: SAMEORIGIN
Content-Length: 133
The file avatars/webshell.php has been uploaded.<p><a href="/my-account" title="Return to previous page">« Back to My Account</a></p>In the browser, let's go back. We can see that something tried to load:

On the image, right-click and choose the option "Copy image address":

In a new tab, paste the image address:

The page loaded, but it's white:

We still need to provide the CMD parameter:
web-security-academy.net/files/avatars/webshell.php?cmd=whoamiClick "Enter".
Now we see that we are "carlos":

Let's change the "whoami" command to one that allows us to read "carlos's" secret:
web-security-academy.net/files/avatars/webshell.php?cmd=cat /home/carlos/secretSuccess:

8ZYWsxxNmgBMX6BTUfQlgQevsyvImkAMWe copy this value and submit it as the answer by clicking "Submit solution":

Lab solved:

🇵🇱 PL:
W tym labie będziemy uploadować shella i będziemy omijać pewne zabezpieczenie, które polega na tym, że sprawdzamy jest "Content-Type".
Klikamy "Access the lab", widzimy bloga:

Dokładnie tak, jak w opisie zadania, logujemy się na konto wiener:peter, wcześniej przechodząc do "My Account".

Naszym zadaniem jest wykorzystać podatność w miejscu uploadu pliku, a następnie przeczytać plik "secret" w katalogu "carlosa".

Klikamy "Choose file". Ja mam przygotowany webshell (webshell.php) - póki co tylko po to, aby sprawdzić, czy są zabezpieczenia odnośnie rozszerzenia danego pliku. Jeśli mamy wczytać avatar, plik z rozszerzeniem .php nie powinien przejść.
Dowiadujemy się, że jest walidacja:

Sorry, file type text/php is not allowed Only image/jpeg and image/png are allowed Sorry, there was an error uploading your file.Sprawdźmy, czy w Burp Suite możemy to obejść. Odnajduję request, który służył do wysyłania pliku:

Tutaj można zobaczyć, że jest nazwa pliku:

Klikam prawym przyciskiem myszy i wysyłam do "Repeatera":

W "Repeaterze" wysyłam jeszcze raz nasz request, aby sprawdzić, czy wszystko działa:

Aplikacja wykryła, że jest to plik php, oraz odpowiednio wpisała "Content-Type":


Pytanie, czy jesteśmy w stanie modyfikować "Content-Type" i czy to wpłynie na zabezpieczenie.
Mamy w responsie informację, że pliki image/jpeg i image/png są dozwolone.
Podmieńmy w requeście "Content-Type":

Okazuje się, że tym razem po wysłaniu requestu otrzymujemy status kod 200:

HTTP/2 200 OK
Date: Mon, 19 Feb 2024 18:06:05 GMT
Server: Apache/2.4.41 (Ubuntu)
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
X-Frame-Options: SAMEORIGIN
Content-Length: 133
The file avatars/webshell.php has been uploaded.<p><a href="/my-account" title="Return to previous page">« Back to My Account</a></p>W przeglądarce cofnijmy się. Widać, że coś próbowało się załadować:

Na obrazku klikamy prawym przyciskiem myszy i wybieramy opcjÄ™ "Copy image address":

W nowej karcie wklejamy adres obrazka:

Strona załadowała się, ale jest biało:

Musimy jeszcze podać parametr CMD:
web-security-academy.net/files/avatars/webshell.php?cmd=whoamiKlikamy "Enter".
Teraz widzimy, że jesteśmy "carlosem":

Zmieńmy komendę "whoami" na taką, która pozwoli na odczytanie sekretu "carlosa":
web-security-academy.net/files/avatars/webshell.php?cmd=cat /home/carlos/secretSukces:

8ZYWsxxNmgBMX6BTUfQlgQevsyvImkAMKopiujemy tę wartość i wysyłamy jako odpowiedź, klikając "Submit solution":

Lab rozwiÄ…zany:
