> 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/authentication/broken-2fa-logic.md).

# Ошибочная логика 2FA

### Нарушенная логика 2FA

Приложение внедряет двухфакторную аутентификацию: / После логина/пароля, a **код 2FA** отправляется через **email**. / У нас есть:

* Наши учетные данные: `wiener:peter`
* Имя пользователя жертвы: `carlos`

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

Доступ к **почтовому серверу** для получения кодов 2FA

<figure><img src="/files/61566b04eac288b87790101217c6232e3032f06b" alt=""><figcaption></figcaption></figure>

#### Наблюдаемая операция

1. После первого шага входа приложение отправляет код 2FA по электронной почте.
2. Второй шаг (`/login2`) проверяет этот код.
3. Пользователь, для которого 2FA действительна, определяется через **`verify`** cookie.

Пример запроса ко второму шагу:

```http
GET /login2 HTTP/2
Host: 0a7500ab0376700f81a18e2c00f200a8.web-security-academy.net
Cookie: session=cNFHPofUz1wxXQpsZZN7yIiKQklG1Ygd; verify=carlos
```

Здесь мы принудительно устанавливаем `verify` cookie в `carlos` так, чтобы проверка 2FA выполнялась в учетной записи жертвы.

#### Подбор кода 2FA методом грубой силы

1. Запрос на проверку 2FA отправляется в **Intruder** (или эквивалент) путем нацеливания на запрос, содержащий:

```bash
mfa-code=XXXXX
```

<figure><img src="/files/51adfa74179eddd49a1563cdfa0cd92dc9d277e2" alt=""><figcaption></figcaption></figure>

* У **полезная нагрузка** настроена на проверку всех возможных комбинаций кода, от `0000` на `9999` (то есть 10 000 значений).

Мы используем cookie:

```bash
verify=carlos
```

* чтобы все проверки кода выполнялись в учетной записи **carlos**.

<figure><img src="/files/7465068498527556795592c0d91029285443272b" alt=""><figcaption></figcaption></figure>

* В настройках к ответу добавляется \*\*условие фильтрации\*\*, чтобы игнорировать те, которые содержат сообщение:
* `Неверный код безопасности`

<figure><img src="/files/1971ee2dae6b81dbf023ed9f98560b05ab9b4285" alt=""><figcaption></figcaption></figure>

1. Мы запускаем атаку перебором.
2. Среди ответов мы находим тот, который больше не содержит сообщение об ошибке и возвращает \*\*HTTP-код 302\*\* (перенаправление). / → Этот ответ соответствует **правильному коду 2FA** от имени **carlos**.

<figure><img src="/files/9e29266d2c80520399581b81fbd9235793bd2644" 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/authentication/broken-2fa-logic.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.
