> 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/xss-in-a-javascript-string-with-apostrophe-and-backslash-escaped.md).

# アポストロフィとバックスラッシュがエスケープされたJavaScript文字列内のXSS

PortSwigger Web Security Academy のラボ向けメモ。アポストロフィとバックスラッシュがエスケープされたJavaScript文字列内のXSSに関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策

### シングルクォートとバックスラッシュがエスケープされた、JavaScript文字列への反射型XSS

検索語追跡機能における反射型XSS。反映される値はJavaScript文字列に挿入される。シンプルなアポストロフィとバックスラッシュはエスケープされており、エスケープが難しくなっている。

目的

* エスケープされたJavaScript文字列から抜け出して呼び出す `alert()`.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b20849c7386445f502bcda99a59c69db13fefbc1%2F%7BB4BF6BF3-E865-4CA6-93C3-77F303A56C58%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

現在の観察

* もし `テスト` が送信されると、値は `searchTerm` スクリプトの変数に保存される。
* 新しい変数を導入しようとする:/ `テスト中'; var=test='thisIsATest`/ → 引用符とバックスラッシュ（\）が注入／存在しており、直接の注入を妨げることが観察される。

```bash
テスト中'; var=test='thisIsATest
```

* 単にスクリプトの終了タグを挿入するだけで、スクリプトのコンテキストを閉じられる: `</script>`

```javascript
</script>
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8178c1763e714af16e1c99e1f1e64532d3c7287f%2F%7B4896DDCD-7438-4CDB-8BCD-A2182B9B0377%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* 閉じた後は、単純なHTMLテキストをレンダリングできる: `</script><h1>HACK</h1>`

```javascript
</script><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-01e8b24c7ccb11208295c9e8aef660a44a4ce3e2%2F%7B48AD1C5D-80B0-4D32-97C0-65A58F29B55B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* そして最後に、実行することが可能である `alert` 新しいものを追加することで `<script>` 閉じた後に: `</script><script>alert(0)</script>`

```javascript
</script><script>alert(0)</script>
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e61bc34ce9d843b0e2a120f26623d2a3c09900d8%2F%7BC137BE47-B233-47C6-9F68-398E189107DF%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/xss-in-a-javascript-string-with-apostrophe-and-backslash-escaped.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.
