> 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/ru/web/xss/dom-xss-document-write-with-location-search.md).

# DOM XSS document.write с location.search

Заметки по DOM XSS document.write с location.search для лабораторных работ PortSwigger Web Security Academy, включая процесс эксплуатации, тестирование полезной нагрузки, проверку в Burp Suite и контекст исправления.

### DOM XSS в приемнике document.write с использованием источника location.search

В этой лабораторной работе есть DOM-уязвимость XSS в функции отслеживания поискового запроса. Страница использует `document.write` для записи данных из `location.search` в DOM, который можно контролировать через URL.

**Описание уязвимости**/ `document.write` вызывается с `location.search` строкой без очистки. Поскольку ввод поступает напрямую из URL, злоумышленник может внедрить HTML/JS на страницу, изменив `location.search`.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-285c95883d25e18b3fd57703bb9cbfd4fadf1dfb%2F%7B71C2914B-1181-4283-97D9-BE369005ECA2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Цель для решения** Выполните DOM XSS-атаку, которая вызывает `alert()` функцию при загрузке страницы.

**Комментарии/подсказки**/ Код генерирует что-то вроде `<img>` тега, содержащего `searchTerms` параметр в кавычках, например:

```html
<img src="/resources/images/tracker.gif?searchTerms=Jordan">
```

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7015f343e74f8f00a9f988ac5d97d58733c3fbff%2F%7BD88B1544-A14A-483D-843A-87C3D304FE97%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Если вы закроете `<img>` тег и кавычки, вы сможете вставить произвольное содержимое HTML/JS.

**Примеры протестированных полезных нагрузок (предоставлены)**/ Закройте тег и внедрите HTML:

```html
"><h1>hack</h1>
```

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e990723f01026088e065e95c8ed8315f4f9d9273%2F%7B69F16E73-C94E-482E-B6AE-BAC849952B9E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Закройте тег и внедрите скрипт, чтобы вызвать `alert`:

```javascript
"><script>alert("xss")</script>
```

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c1cb6a560a846ee995ffcdfa9f704d0c2e4fc1c2%2F%7B6656AD8C-DF1B-4935-AE99-1203574875DC%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/ru/web/xss/dom-xss-document-write-with-location-search.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.
