> 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/websockets/websocket-handshake-manipulation.md).

# Манипулирование рукопожатием WebSocket

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

### Манипулирование рукопожатием WebSocket для эксплуатации уязвимостей

Этот интернет-магазин имеет функцию чата в реальном времени на основе **WebSocket**. / Присутствует XSS-фильтр: он агрессивный, но имеет эксплуатируемые недостатки.

Поле чата позволяет отправлять сообщения, которые отображаются в реальном времени на стороне агента поддержки.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7e167899ebc6f6893c92a84b8deca11ad45207f5%2F%7BBD656235-BB53-498B-9FDC-C64F9A2A7784%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Первоначальный тест XSS-фильтра

При отправке следующей полезной нагрузки в чат:

```javascript
<img src=0 onerror=alert(0)>
```

Сервер отвечает сообщением:

* **Атака обнаружена: обработчик события**
* Соединение WebSocket немедленно **закрыто**.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-be096d21e9bfaabb72aa5560a09d24d9cec94b57%2F%7B880823DF-F5A4-4802-9978-933D5A8B289D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

После простого обновления страницы появляется следующее сообщение:

* **Этот адрес занесён в чёрный список**

Поэтому IP-адрес временно заблокирован.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2e33bd956aec874d584e04f7ace1a80422569d98%2F%7B2816FFE2-3D7D-4A5E-B5D4-067DBDF33F7A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Обход чёрного списка

Добавление следующего HTTP-заголовка при установлении рукопожатия WebSocket:

```http
X-Forwarded-For: 0.0.0.0
```

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2fb005e0471d574c87fc426d0dee90538d45a100%2F%7B945882E2-E46A-4509-9A6D-D108717481CB%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Сервер снова принимает соединение. / Чтобы не приходилось добавлять его вручную каждый раз, этот заголовок настроен **постоянно в прокси**.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-952feb57fb13e416a58916a89b9fa5fa47a45a64%2F%7BF1745B76-CF31-4A2D-A7F3-676136BE4FD5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Обход XSS-фильтра

После восстановления соединения полезная нагрузка немного изменяется, чтобы обойти фильтр:

```javascript
<img src=0 OnErrOR=alert`0`>
```

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fc0cb7c6ea20369b6bb250a51f13b799dc90ba1f%2F%7B0C6DB5F8-6777-4263-AAFA-086A9424FF9B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Это изменение разрывов и синтаксиса позволяет обойти обнаружение.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-516c9a384c0d6a8043d8bc11a7c924d6e6e825de%2F%7B46B6F48D-4B77-4AAC-A4B4-F12D6FD070A6%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/websockets/websocket-handshake-manipulation.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.
