> For the complete documentation index, see [llms.txt](https://gitbook.cdxiaodong.life/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.cdxiaodong.life/web-ying-yong-an-quan/cookie-security/cookie-tossing.md).

# Cookie竞争

如果您控制子域或在子域中发现XSS，则可以设置将在域及其子域中使用的cookie。这可能导致以下攻击向量：

* 为受害者设置攻击者cookie并收集受害者在使用攻击者账户时将添加的敏感数据
* 如果cookie在登录后不更改，则固定cookie
* 如果cookie设置初始值，您可以设置已知值并滥用它。例如，cookie在Flask中设置会话的CSRF令牌，并且此值在登录后保持不变，因此，您可以使用已知值执行CSRF
* 执行[Cookie bomb](/web-ying-yong-an-quan/cookie-security/cookie-bomb.md)攻击

即使已经设置了cookie，cookie投掷也是可能的，因为当浏览器接收到两个具有相同名称且部分影响相同范围（域、子域和路径）的cookie时，浏览器将在对请求有效时发送两个cookie。如果应用程序只使用第一个cookie，您可以通过添加具有较长路径的 `Path` 属性来强制它使用您的cookie，请查看 [Cookie Security: Cookie-list sorting](/web-ying-yong-an-quan/cookie-security.md#cookie-list-sorting)。

如果应用程序不接受具有相同名称但不同值的cookie的请求，您可以尝试以下技巧：

* 用攻击者的cookie溢出合法cookie，请查看 [Cookie Jar Overflow](/web-ying-yong-an-quan/cookie-security/cookie-jar-overflow.md)
* 更改cookie名称：使用URL编码，使用不同的大小写，添加额外符号，如 `%00`、`%20`、`%09` 等。

## 参考资料

* [HackTricks: Cookie Tossing](https://book.hacktricks.xyz/pentesting-web/hacking-with-cookies/cookie-tossing)


---

# 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://gitbook.cdxiaodong.life/web-ying-yong-an-quan/cookie-security/cookie-tossing.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.
