> 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-message-manipulation.md).

# Манипуляция сообщениями WebSocket

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

В этом интернет-магазине есть работающая в реальном времени **функция чата** реализованная с помощью **WebSocket**. / Сообщения, отправленные пользователем, мгновенно отображаются в браузере **оператора поддержки**. / Цель лабораторной работы — **запустить `alert()`** всплывающее окно в браузере оператора, манипулируя сообщением WebSocket.

В приложении доступно поле чата.

<figure><img src="/files/423e1649752af60a1841a639825c2ed3df40fc51" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/70d7c8f39a5d28e6d953e05e7fadc157ac710a5c" alt=""><figcaption></figcaption></figure>

При анализе трафика видно, что сообщения отправляются через WebSocket следующим образом:

```json
{
    "user":"Вы",
    "content":"привет"
}
```

**Тест фильтрации**

Попробуйте отправить следующий полезный payload через чат:

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

Наблюдаемый результат:/ Содержимое \*\* экранируется на стороне сервера\*\* и интерпретируется как текст:

```javascript
&lt;script&gt;alert(0)&lt;/script&gt;
```

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

Это указывает на наличие базовой фильтрации против `<script>` тегов.

**Обход фильтрации**

Затем вручную отправляется сообщение WebSocket со следующим полезным payload:

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

Сообщение **пересылается напрямую** через запрос WebSocket, минуя обычные элементы управления интерфейса.

<figure><img src="/files/3a1bd566bc12629082bea213cce58407b9e9063f" alt=""><figcaption></figcaption></figure>

Когда оператор поддержки получает сообщение, браузер интерпретирует `атрибут onerror` атрибут, что вызывает:

* выполнение `alert(0)`
* Появление **всплывающего окна** в браузере оператора

<figure><img src="/files/1210958b86a1b1f43173196d300a03c63a256ee5" 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-message-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.
