Writeup: Blind OS command injection with output redirection @ PortSwigger Academy

This is a writeup for the Lab “Blind OS command injection with output redirection” from PortSwiggers Web Security Academy:

Python script: script.py

Lab description

  • OS command injection vulnerability in the feedback feature
  • Application call a shell command with user input
  • Output is not returned, but can be redirected
  • Writeable folder at /var/www/images/

Goals

  • Retrieve the output of whoami

Steps

Analysis

As usual, the first step is to browse the application to find out what it does. Like in the previous lab, it contains a vulnerable feedback feature.

Craft the payload

The command to execute is whoami > /var/www/images/whoami to write the file. I will again try straight to inject into the email argument. And as in the previous lab, commenting out the remainder results in a 200 OK, while not doing so results in 500 Internal Server Error. Both ways work though.

Access the file

Now the file is in /var/www/images, but the path to it within the application is unknown and perhaps not even accessible directly. But I can utilize the way the application includes its images with a GET request to /image?filename=

At the same time, the lab page updates to

--

--

Tech nerd, doing security stuff for fun and some as a job | CISSP, OSCP. Read all stories on medium and support me: https://medium.com/@frank.leitner/membership

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Frank Leitner

Tech nerd, doing security stuff for fun and some as a job | CISSP, OSCP. Read all stories on medium and support me: https://medium.com/@frank.leitner/membership