> 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

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

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

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

<figure><img src="/files/e56b8658c76407b57416331f776ff89957b115de" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

<figure><img src="/files/51507a80d13ed6d700864d43f1dc4f0317318d3b" alt=""><figcaption></figcaption></figure>

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

* **Этот адрес находится в чёрном списке**

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

<figure><img src="/files/fde45945ee82bbe5fdbc1468a203d1abe1d8b9fe" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="/files/46db9df40c06381f55ae30c0b26d8dd08fa9c545" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/85f927dd79048fd393ce3a093d496aba3f8041b9" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="/files/7e7aa1ba909e2260c5803a4c42a70cd37ac82226" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/d262b6ef2244f38155ae1e8fa74c7604a25c05d4" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/ru/web/websockets/websocket-handshake-manipulation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
