This post is focused on the walkthrough of Easy Linux Machine Trick from HackTheBox.
Summary
Trick from HackTheBox is an Easy Linux Machine. We get a subdomain by performing a DNS zone transfer which in turn reveals another subdomain by brute-forcing on the same pattern. The newly discovered website was vulnerable to LFI through which we can read the private ssh key of the user and login to get the user.txt. The current user being able to restart the fail2ban service as root and being part of security group leads to Privilege Escalation by abusing the fail2ban configuration.
Logging with these credentials we get the following page.
I couldn’t find anything further here so moved on to brute-forcing vhosts.
Brute-forcing vhosts we couldn’t find any so we can try brute-forcing with a pattern preprod-<subdomain>.trick.htb
We can first use sed command to add a prefix to our wordlist then use wfuzz to brute-force subdomains based on their character count.
1
2
┌──(kali㉿kali)-[~/…/hackthebox/hackthebox/machines/Trick]└─$ sed -e 's/^/preprod-/' /home/kali/Documents/wordlists/SecLists/Discovery/DNS/subdomains-top1million-110000.txt > newWordlist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
┌──(kali㉿kali)-[~/…/hackthebox/hackthebox/machines/Trick]└─$ wfuzz -c -f sub-fighter -w newWordlist -u 'http://trick.htb' -H "Host: FUZZ.trick.htb" --hh 5480 /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://trick.htb/
Total requests: 114441=====================================================================ID Response Lines Word Chars Payload=====================================================================000000254: 200178 L 631 W 9660 Ch "preprod-marketing"
Adding this subdomain to our /etc/hosts then visiting.
Foothold
Looking around we have a page parameter which looks interesting for a LFI.
Bypassing some basic filtering we get the LFI
From the /etc/passwd we know there’s a user michael, so we can check for ssh keys in it’s home directory.
Try logging in with the id_rsa.
1
2
3
4
5
6
7
┌──(kali㉿kali)-[~/…/hackthebox/hackthebox/machines/Trick]└─$ ssh -i id_rsa michael@trick.htb
michael@trick:~$ whoami
michael
michael@trick:~$
michael@trick:~$ ls -al
total 84drwxr-xr-x 15 michael michael 4096 Oct 29 08:34 .
drwxr-xr-x 3 root root 4096 May 25 13:28 ..
lrwxrwxrwx 1 root root 9 Apr 222022 .bash_history -> /dev/null
-rw-r--r-- 1 michael michael 220 Apr 182019 .bash_logout
-rw-r--r-- 1 michael michael 3526 Apr 182019 .bashrc
drwx------ 9 michael michael 4096 May 11 21:09 .cache
drwx------ 10 michael michael 4096 May 11 21:08 .config
drwxr-xr-x 2 michael michael 4096 May 11 21:07 Desktop
drwxr-xr-x 2 michael michael 4096 May 11 21:07 Documents
drwxr-xr-x 2 michael michael 4096 May 11 21:07 Downloads
drwx------ 3 michael michael 4096 May 11 21:08 .gnupg
-rw------- 1 michael michael 1256 May 25 13:09 .ICEauthority
drwx------ 3 michael michael 4096 May 11 21:07 .local
drwxr-xr-x 2 michael michael 4096 May 11 21:07 Music
drwxr-xr-x 2 michael michael 4096 May 11 21:07 Pictures
-rw-r--r-- 1 michael michael 807 Apr 182019 .profile
drwxr-xr-x 2 michael michael 4096 May 11 21:07 Public
-rw------- 1 michael michael 86 Oct 29 08:34 .python_history
drwx------ 2 michael michael 4096 May 24 17:25 .ssh
drwxr-xr-x 2 michael michael 4096 May 11 21:07 Templates
-rw-r----- 1 root michael 33 Oct 29 07:52 user.txt
drwxr-xr-x 2 michael michael 4096 May 11 21:07 Videos
michael@trick:~$ cat user.txt
1a****************************ef
michael@trick:~$
Privilege Escalation
sudo -l shows we can run /etc/init.d/fail2ban restart as root.
1
2
3
4
5
6
7
8
michael@trick:~$ sudo -l
Matching Defaults entries for michael on trick:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User michael may run the following commands on trick:
(root) NOPASSWD: /etc/init.d/fail2ban restart
michael@trick:~$
fail2ban
Fail2ban is an intrusion prevention software framework. Written in the Python programming language, it is designed to prevent against brute-force attacks. It is able to run on POSIX systems that have an interface to a packet-control system or firewall installed locally, such as iptables or TCP Wrapper.
Looking up for PrivEsc using fail2ban I came accross this article.
We have almost the same scenario as the above article.
We also have ssh service enabled in the /etc/fail2ban/jail.conf file.
Now since we can restart fail2ban as root what we have to do now is to inject our custom command as actionban in /etc/fail2ban/action.d/iptables-multiport.conf file.
Sadly we don’t have write permissions on the file.
But luckily we are part of a group security and this group has write permissions on the /etc/fail2ban/action.d folder.
Now the attack scenario is as follows.
We will delete the original iptables-multiport.conf file and replace it with our custom made file. Then we will restart the fail2ban service and finally attempt to login via ssh 5 times via brute-forcing or manually. And this will execute our command as actionban.
Now changing the iptables-multiport.conf file as follows
Then deleting the previous one and fetching the new one.
Restarting the fail2ban service.
Now brute-force the ssh login via hydra.
Now looking at the bash binary, it has the SUID bit set.