> 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/authentication/brute-forcing-a-stay-logged-in-cookie.md).

# 暴力破解持久会话 Cookie

暴力破解持久会话 Cookie，PortSwigger Web Security Academy 实验笔记，包括利用流程、载荷测试、Burp Suite 验证以及修复上下文。

### 暴力破解保持登录的 Cookie

这个实验允许用户在关闭浏览器后仍保持连接。用于此功能的 cookie 容易受到暴力破解。/ 要完成此实验，你需要暴力破解 Carlos 的 cookie，以访问其“我的账户”页面。

**提供的凭据：** `wiener:peter`/ \*\* 受害者姓名：\*\* `carlos`

### \*\*机制分析

当你勾选自动重新连接选项时，会发送以下请求：

```bash
username=wiener&password=peter&stay-logged-in=on
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0403a19dab402f3e97c579c9825f7331603d1b8d%2F%7B8D6D842C-F790-48A4-AC29-DCAC18AD2362%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

服务器随后返回一个名为 **stay-logged-in**的 cookie，其内容经过 Base64 编码：

```bash
d2llbmVyOjUxZGMzMGRkYzQ3M2Q0M2E2MDExZTllYmJhNmNhNzcw
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-359b0e421ac5ddfffd4149ee6cc04759e30e10ad%2F%7B469300F7-6C16-42BF-BFBF-D1F5254966AE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

解码后，我们得到：

```bash
wiener:51dc30ddc473d43a6011e9ebba6ca770
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9c73b15c956ca8704047869bd559bc5eb7e73112%2F%7BA01AF79D-B838-4252-9A86-46AF6B0F52A7%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

因此，cookie 结构为：

通过在 CrackStation 上检查该哈希，我们发现它对应于值 **peter** 的 MD5。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-439858b58f7b42121bd2e78a123370b0944bef21%2F%7BD57F01BA-3A29-45F7-941E-1FB71CEC1E8A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### **暴力破解设置**

1. 将 cookie 请求发送到 **Burp Intruder** 并将 cookie 值选择为注入区域。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-14892da393a82e18479182560f435303c07dc8dd%2F%7B76698D2C-E70F-4B1E-9243-AD759C812CBE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

在有效载荷处理：

* 添加一个生成哈希的转换 **MD5**;

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2f47e72581f4ed1e9c8c8d88dfb2c4e920c7831d%2F%7B37EC0F27-0B9F-452D-A041-F54DCC9686B5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* 添加前缀： `carlos:`

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-67bfb16b499114e6751f7ac5167d18f3b56eb047%2F%7B31EB1BB3-3F24-4857-8A42-9EB6DD7560B6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* 全部编码为 **Base64**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a3c5a693dee97c0392a326eb20651ba038f7c394%2F%7B66EDA515-67B1-4141-9D92-0F5468F7B5AB%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

1. 在有效载荷设置中加载密码列表。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-78de49eecd6ccd85f007c51cc67279ef03f78470%2F%7B384D96E6-8DA0-471A-B2E9-6322A26999EB%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

在攻击过程中，一个响应 **200** 表示 Carlos 的正确 cookie。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ef712dc2dd92f224f0787cee97ac036e501c22f3%2F%7B2EF935E2-69B3-4161-9DAA-A69B9D416457%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

获取到的 cookie 是：

```bash
Y2FybG9zOjdkOGJjNWYxYThkMzc4N2QwNmVmMTFjOTdkNDY1NWRm
```

解码

{% code overflow="wrap" %}

```bash
echo -n "Y2FybG9zOjdkOGJjNWYxYThkMzc4N2QwNmVmMTFjOTdkNDY1NWRm" | base64 -d ;echo
```

{% endcode %}

* carlos:7d8bc5f1a8d3787d06ef11c97d4655df

在 CrackStation 上检查此哈希后，我们发现对应的密码是 **taylor**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1ede348078088576176ffdbc5377f5a7933561f8%2F%7BC16A22DF-86A3-40CA-8F61-B58E8B3F5D69%7D.png?alt=media" 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 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/authentication/brute-forcing-a-stay-logged-in-cookie.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.
