> 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/zh/web/xss/xss-in-template-literal-with-escaped-unicode.md).

# 带转义 Unicode 字符的字面模板中的 XSS

带转义 Unicode 字符的字面模板中的 XSS 笔记，适用于 PortSwigger Web Security Academy 实验室，包括利用流程、载荷测试、Burp Suite 验证和修复 cont

### 反射型 XSS 注入模板字面量中，尖括号、单引号、双引号、反斜杠和反引号均进行了 Unicode 转义

XSS 反射在字面量模板（反引号）中，其中 `<` 和 `>` 尖括号以及单引号和双引号都被编码，而反引号则以 Unicode 方式转义。目标：触发执行 `alert()` 在字符串模板中。

search 参数被反射到一个 JavaScript 字面量模板中。必须先打破该模板字符串才能运行 `alert()` 从反射值中。

<pre class="language-javascript"><code class="lang-javascript">var message = `关于 'test' 的 2 条搜索结果`;
<strong>document.getElementById('searchMessage').innerText = message;
</strong></code></pre>

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

* 反引号字符（`` ` ``）用于界定模板字面量；页面对用户提供的反引号进行了转义（例如使用 Unicode 转义），从而阻止简单逃逸。

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

JS 插值差异示例（示意）：

```javascript
variable = "测试";
console.log("变量是：${variable}")
console.log(`变量是：${variable}`)
```

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

第一行会原样显示 `${variable}`，第二行则通过反引号解析变量。

* 尝试插入一个可运行的插值表达式 `alert()`:

```javascript
${alert(0)}
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ab6acd9b60a371feb6d804be4b5282f96fee3f97%2Fimage%20(419).png?alt=media" alt="" width="520"><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/zh/web/xss/xss-in-template-literal-with-escaped-unicode.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.
