> 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/race-conditions/race-conditions-that-bypass-limits.md).

# Состояния гонки, обходящие ограничения

Заметки о состояниях гонки, обходящих ограничения, для лабораторий PortSwigger Web Security Academy, включая рабочий процесс эксплуатации, тестирование полезных нагрузок, валидацию в Burp Suite и контекст устранения.

### Состояния гонки при превышении лимита

Поток покупки содержит **состояние гонки** которое позволяет получить **неожиданную цену** на момент оплаты.

#### Цель

Успешно купите **Лёгкая кожаная куртка L33t**.

#### Данные / Предварительные условия

* Учётные данные: `wiener:peter`
* Код скидки (20%): `PROMO20`
* Доступный кредит: **$50**

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0ece9370cb2bdf79fababb3fc8b1d2f0722dd6d2%2F%7B944C81AC-4354-4BC2-8DE1-F965C756CC1A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Стоимость куртки: **$1300**

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1ecb32fb317fcf10e235a2128b20fb9da81c1978%2F%7BE59C4756-54D8-443B-A799-75A464062A67%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Наблюдение за поведением

1. Добавьте куртку в корзину.
2. Примените `PROMO20` купон.
3. Если вы попытаетесь применить купон во второй раз, приложение отвечает: **Купон уже применён**.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-46405c4b9854c6996abcf9adb4bdf076da7f1597%2F%7BF3777B3E-48EE-4557-B9BC-429A5151C008%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Запрос на применение купона выглядит так (form URL-encoded):

```bash
csrf=7QYFGBaACc8P5YOfUHR4S85oo95uA0Vb&coupon=PROMO20
```

### Ручная эксплуатация (Burp Repeater)

1. Отправьте запрос на применение в **Repeater**.
2. Создайте **группы** в Repeater.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c5f75c5fc6d82386e6bbbf1eb44f3843b38d9a0e%2F%7B7930725F-7452-4FEB-9AE5-5A3B6689234F%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

* Дублируйте вкладку запроса примерно 20 раз (**Дублировать вкладку**).

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8922ebbefcbb65751bccbd3b31cae3edc7946042%2F%7B584C98C5-87B5-4093-BA1A-FDFF28468AC2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8844568de87af86ef85247fe800333c30c28ca03%2F%7B5D6306B5-1BEB-4008-BB05-D50E1309FFB1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Отправить запросы **параллельно**.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-73f329e096684bf1d66b78855deaaeb158b89d87%2F%7BE6CDA436-5E4B-491A-ACA0-74973BB14353%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

В результате большинство запросов **валидируются**, и сумма становится **/\~37**, что позволяет совершить покупку, несмотря на первоначальную цену ($1300) и ограниченный кредит.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bec1d11878b2c95d4318eec35e1b4c591ae6461f%2F%7BBF3732E3-06D8-4A81-B5B6-2190386B9AC9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Автоматизированная эксплуатация (пользовательское действие Burp Suite Pro)

Лабораторная работа рекомендует использовать **Запускать состояния гонки** (Burp Suite Professional) через **Пользовательское действие**.

#### 1) Добавьте скрипт (Bambda Library)

Перейдите в **Расширения → библиотека Bambda** и добавьте:

* **id**: `eb57d5bd-33e2-4a8c-bf51-bc81bd26613a`
* **имя**: `Проверка на состояние гонки`
* **функция**: `CUSTOM_ACTION`
* **расположение**: `REPEATER`

```javascript
id: eb57d5bd-33e2-4a8c-bf51-bc81bd26613a
name: Проверка на состояние гонки
function: CUSTOM_ACTION
location: REPEATER
source: |+
  /**
  * Повторяет запрос 10 раз, чтобы вызвать состояния гонки или request smuggling, используя атаку одним пакетом для HTTP/2 и синхронизацию по последнему байту для HTTP/1
  *
  * @author James Kettle
  **/
  int NUMBER_OF_REQUESTS = 10;
  var reqs = new ArrayList<HttpRequest>();
  for (int i = 0; i < NUMBER_OF_REQUESTS; i++) {
      reqs.add(requestResponse.request());
  }

  var responses = api().http().sendRequests(reqs);
  var codes = responses.stream().map(HttpRequestResponse::response).map(HttpResponse::statusCode).toList();
  logging().logToOutput(codes);
```

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-74efc545ee462780971b4d839986b812e11b584b%2F%7B69D346CD-E49B-46B1-8F5F-11E850ED3E03%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 2) Запустите из Repeater

1. В Repeater: **Пользовательское действие** → добавьте из примеров.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ea08324571f36fe57d59d511920f146ea06edb4b%2F%7B668FF286-DE9E-4B8E-BAFC-3EDBE64C17AA%7D.png?alt=media" alt="" width="548"><figcaption></figcaption></figure>

* Загрузите созданное пользовательское действие.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-aca5636ca6c2b8a5d09483aa20b52a1190edbe92%2F%7BC0F85A68-691D-45D2-B99A-C14886278A6A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Проверьте с **30 запросов**.

мы видим **коды статуса** (для 30 запросов) и мы можем легче вызвать состояние гонки

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e192221becf971242f3dc030aefede5444517248%2F%7B4BB4F25E-E949-44D6-9EE7-C487F778830E%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/ru/web/race-conditions/race-conditions-that-bypass-limits.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.
