> 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/url-normalization.md).

# URL 规范化

URL 规范化，PortSwigger Web Security Academy 实验笔记，包括利用流程、载荷测试、Burp Suite 验证以及修复上下文。

### URL 规范化

这个实验包含一个 **跨站脚本攻击** 无法直接利用的漏洞，因为浏览器会自动进行 **dURL** 编码。/ 因此， **缓存 URL 规范化过程** 必须使用来利用这个漏洞。

目标是注入一个可运行的有效载荷 `alert(1)` 到受害者的浏览器中，然后向其提供恶意 URL。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-924dc3b440ac56cd48934f83f912310005d50560%2F%7B52591DD1-9E12-45A2-812C-3E47D549F1AB%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 1）注入点识别

当你访问一个不存在的页面（例如 `/test`），网站会返回一个 **错误页面** ，在 HTML 响应中重用请求的路径。

如果一个 HTML 标签被闭合并注入脚本，它会被解释为：

```javascript
/test</p><script>alert(1)</script>
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-42e0199c3c5daab9da221f946c67f82e554a1326%2F%7BACB59D9B-3776-4314-A88D-599A8DC970A4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 2）遇到的问题

如果直接在浏览器中输入该 URL，有效载荷 **n 不会执行**。/ 原因是浏览器 **会自动编码** 特殊字符（`<`, `>`, `/`，等等），从而阻止脚本执行。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f1c4f08d1dd4ac265a27d642342ef2312b5e1d7f%2F%7B3A9DB60A-3A74-4826-80B7-FB0F49F6D1A2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 3）通过缓存规范化进行操作

为了绕过这种保护， **缓存** 会使用：

* 恶意请求通过 **Burp Suite**发送，而不经过浏览器地址栏。
* 缓存 **规范化** URL 并存储关联的响应。
* 然后缓存的响应中包含有效载荷 **未编码的**.

#### （4）触发 XSS

一旦响应被污染到缓存中：

* 将该 URL 提供给受害者。
* 缓存返回页面的标准版本。
* 脚本被解释并 `alert(1)` 在受害者的浏览器中运行。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-08eb81aca79a89302f4550dbba0975de9ce5b2d8%2F%7B2A6C09FF-C1B0-4EAB-A5E8-A248B6FB611F%7D.png?alt=media" alt="" width="507"><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/url-normalization.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.
