> 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/bypassing-validation-by-connection-state.md).

# 通过连接状态绕过验证

通过连接状态绕过验证，PortSwigger Web Security Academy 实验笔记，包括利用流程、载荷测试、Burp Suite 验证以及修复上下文。

### 通过连接状态攻击绕过 Host 验证

**漏洞描述**

这个实验有一个 **基于通过 Host 路由的 SSRF 类型漏洞** 请求头，这与服务器端连接状态管理不善有关。

尽管前端服务器似乎会正确验证 `Host` 请求头，但它做出了一个危险的\*\*假设\*\*：

> 如果 **第一个请求** 有效，则在同一 TCP 连接上发送的所有请求都被视为可信。

这允许在同一连接上注入后续的恶意请求，从而绕过最初的验证。

**实验目标**

* 访问内部管理面板：/ `HTTP://192.168.0.1/admin`
* 删除用户 **carlos**

**初步观察**

对内部 IP 的直接请求被阻止：

```http
GET / HTTP/1.1
Host: 192.168.0.1
```

服务器拒绝了此请求，这证实 `Host` 存在验证机制 **在第一个请求处**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-716cd678495ba9f257aeef4663599d1781bb752d%2F%7B66EAD875-C290-48AB-86B2-6054CF9ECE86%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**操作：连接状态攻击**

思路是在同一个 TCP 连接上发送\*\*多个请求\*\*：

1. 向公共主机发送一个合法的第一个请求（被接受）。
2. 发送一个针对内部 IP 的第二个恶意请求， **在同一连接上**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c156f1764638d2ba4d002f1dd9ec42c8cc7b1aed%2F%7B7C1D0937-5E3E-4E83-8F29-42F59338EF12%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

在 Burp Suite 中，可以通过以下方式实现：

* 分组请求
* 使用 **Send group in single connection**

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-00d3a64b47a7ce1463445cb3ee7908241bb2af19%2F%7BE961F29C-9FAA-4C08-A8CE-75A3D270193E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**访问管理面板**

一旦使用有效请求建立了连接，随后发往内部管理端的请求就会被接受：

```http
GET /admin HTTP/1.1
Host: 192.168.0.1
```

随后即可访问内部管理面板。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-62e690af215289aa04969d98c4420d8f1d2616fa%2F%7BC76FC4FB-52F9-4BFD-B3F9-CE9040DB5411%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**删除用户**

删除该用户需要一个 POST 请求：

```http
POST /admin/delete HTTP/1.1
Host: 192.168.0.1

csrf=ppBVKn8wVrgZifEETHsn48Hykwiq8yFO&username=carlos
```

服务器响应：

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-586b97aeff5349a4a728d8a02e94a919b03e31eb%2F%7B2A1D959A-10BF-4B0A-A3FF-6907C0A91CD6%7D.png?alt=media" alt="" width="446"><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/host-header/bypassing-validation-by-connection-state.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.
