Skip to content
On this page

# Blind OS command injection with output redirection (ENG 🇬🇧 | PL 🇵🇱)

Link: https://portswigger.net/web-security/os-command-injection/lab-blind-output-redirection

After clicking "Access the lab," we see a store page.

blind os welcome page

We click "Submit feedback."

submit feedback page

While executing the command during this exercise, we will try to redirect the result of this command to a file located in the directory:

/var/www/images

We fill out the form with data and submit:

form with data

We go to Burp Suite, find our request, and send it to "Repeater":

send to Repeater

Here we can test individual parameters:

repeater

Let's now check if we are able to execute any command. We will adjust our payload to see if this is possible. Our payload looks like this:

csrf=Obk1aI10DvBcnBIIm4cW4jcUTL7pZIU9&name=Adrian&email=adrian%40maryniewski.pl;sleep 10;&subject=SUBJECT&message=EVEN+BETTER+MESSAGE%21%2111oneone

And it works. I waited 10 seconds for this response:

response

The goal of this exercise is to check which user I have and save it to a file that will be in the directory:

/var/www/images

Let's therefore change the command to whoami and redirect the result of this command, with the greater-than sign (">"), to the file output.txt:

/www/var/images/output.txt

So we change our command in this way:

csrf=pebQ5r7IcCmvSHnFar8ftsin5Zg7iCk4&name=Adrian&email=adrian%40maryniewski.pl;whoami > /var/www/images/output.txt;&subject=OH+SO+CLEVER+SUBJECT&message=EVEN+BETTER+MESSAGE%21%2111oneone

In response from the server, we get a 500, but there is a good chance that the command was executed:

500 but command used

We can now go to any request that allows us to load, for example, images. We click on Home to go to the main page (where images are loaded). We have this disabled in our proxy, so let's deal with it first:

proxy tab

We click on "Filter settings: Hiding CSS, image and general binary content." We select the "images" option, then "Apply":

images

We refresh the main page ("Home").

We can now see what file display looks like - in the "Logger" tab: logger tab images

We see that we have such a request as:

GET /image?filename=47.jpg HTTP/2

GET image filename

We send it to the "Repeater" tab.

We change the file name from 47.jpg to output.txt:

47 image

output text

We see the information that we completed the task:

lab solved


Link: https://portswigger.net/web-security/os-command-injection/lab-blind-output-redirection

Po kliknięciu "Access the lab", widzimy stronę sklepu.

blind os welcome page

Klikamy "Submit feedback".

submit feedback page

Wykonując komendę podczas wykonywania tego ćwiczenia, będziemy starali się przekierować wynik tej komendy do pliku, który znajduje się w katalogu:

/var/www/images

Wypełniamy formularz danymi i wysyłamy:

form with data

Przechodzimy do Burp Suite, odnajdujemy nasz request i wysyłamy go do "Repetera":

send to Repeater

Tutaj możemy testować poszczególne parametry:

repeater

Sprawdźmy teraz, czy jesteśmy w stanie wykonać jakąś komendę. Dostosujemy nasz payload tak, aby sprawdzić, czy jest to możliwe. Nasz payload wygląda tak:

csrf=Obk1aI10DvBcnBIIm4cW4jcUTL7pZIU9&name=Adrian&email=adrian%40maryniewski.pl;sleep 10;&subject=SUBJECT&message=EVEN+BETTER+MESSAGE%21%2111oneone

I działa. Czekałem 10 sekund na tę odpowiedź:

response

Celem tego ćwiczenia jest to, żeby sprawdzić jakiego mam użytkownika i zapisać go do pliku, który będzie w katalogu:

/var/www/images

Zmieńmy zatem komendę na whoami i przekierujmy wynik działania tej komendy, znakiem większości (">") do pliku output.txt:

/www/var/images/output.txt

Zmieniamy zatem naszą komendę w ten sposób:

csrf=pebQ5r7IcCmvSHnFar8ftsin5Zg7iCk4&name=Adrian&email=adrian%40maryniewski.pl;whoami > /var/www/images/output.txt;&subject=OH+SO+CLEVER+SUBJECT&message=EVEN+BETTER+MESSAGE%21%2111oneone

W odpowiedzi od serwera dostajemy 500, ale istnieje spora szansa, że komenda się wykonała:

500 but command used

Możemy teraz przejść do jakiegoś requestu, który pozwala nam zaczytywać na przykład obrazki. Klikamy w Home, aby przejść na stronę główną (gdzie ładują się obrazki). W naszym proxy mamy to wyłączone, więc najpierw zajmijmy się tym:

proxy tab

Klikamy na "Filter settings: Hiding CSS, image and general binary content." Zaznaczamy opcję "images", a następnie "Apply":

images

Odświeżamy stronę główną ("Home").

Możemy teraz zobaczyć jak wygląda wyświetlanie plików - w zakładce "Logger": logger tab images

Widzimy, że mamy taki request jak:

GET /image?filename=47.jpg HTTP/2

GET image filename

Wysyłamy go do zakładki "Repeater".

Zmieniamy nazwę pliku z 47.jpg na output.txt:

47 image

output text

Widzimy informację, że ukończyliśmy zadanie:

lab solved