> 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/ja/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://2001299964-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://2001299964-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. クーポンを2回目に適用しようとすると、アプリケーションは次のように応答します: **クーポンはすでに適用されています**.

<figure><img src="https://2001299964-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>

クーポン適用クエリは次のようになります（フォームURLエンコード）:

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

### 手動での悪用（Burp Repeater）

1. アプリケーション要求を **Repeater**.
2. 作成する **グループのメンバーになれます** に送信します。

<figure><img src="https://2001299964-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://2001299964-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://2001299964-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://2001299964-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://2001299964-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）

次へ移動 **Extensions → Bambda library** して、次を追加します:

* **id**: `eb57d5bd-33e2-4a8c-bf51-bc81bd26613a`
* **name**: `競合状態を調べる`
* **関数**: `CUSTOM_ACTION`
* **場所**: `REPEATER`

```javascript
id: eb57d5bd-33e2-4a8c-bf51-bc81bd26613a
name: 競合状態を調べる
function: CUSTOM_ACTION
location: REPEATER
source: |+
  /**
  * 競合状態やリクエスト・スマグリングを引き起こすために、HTTP/2 では single-packet attack を、HTTP/1 では last-byte synchronisation を使用して、リクエストを10回繰り返します
  *
  * @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://2001299964-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://2001299964-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://2001299964-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://2001299964-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/ja/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.
