Analytics - HackTheBox

Máquina: Analytics — Dificultad: Easy

AnalyticsMachine

WriteUp Machine Analytics/HackTheBox

Scan

scan{: width=“600”}

Nmap Command Parameters Explained

ParameterDescription
-p-Scans all ports (1-65535).
--openDisplays only open ports.
-sSPerforms a SYN scan (half-open), faster and stealthier.
--min-rate 5000Forces Nmap to send at least 5000 packets per second.
-vvvIncreases verbosity level, showing more details in the output.
-nSkips DNS resolution for faster scanning.
-PnDisables host discovery; assumes the host is up.
IPTarget IP address to scan.
-oG portsSaves the output in Grepable format to a file named ports.

We add the ip to the /etc/hosts file so we can see it on our machine

hosts

Now we will see if we find hidden directories through the gobuster tool, doing different tests, but it didn’t come to anything, so we decided to try a DNS search. I did a wfuzz on it and found data.

wfuzz

We see a subdirectory with the name data. We add it to etc/hosts -> data.analytical.htb

data

We enter the url and see that an interface with the name metabase does not appear

metabase

We proceeded to look for an exploit with metabase, with the wappalyzer I couldn’t even see what the version was in the source code, but searching the internet I found an exploit that turned out to work

exploit

a pre-auth exploit, the exploit details that we can get the setup token in this directory /api/session/properties

token

We filter by token and in fact it gives us the token so it is a very serious error, now with the token the exploit details that we have remote command execution so I will try to connect to the victim machine through a reverse shell

rev

We listen on port 443 and we are done but we still cannot access the user’s flag

rev

We are the metabase user and in the same directory we find a file called .dockerenv so we are going to look at its environment variables to see if we find information that is interesting to us

docker env

We see that it gives us a META_USER and META_PASS. Since in the nmap scan port 22 (ssh) is open, we will see if with those credentials we can connect via ssh

user

Ready we have access as the metalytics user and we see the user flag, now we must raise our privilege to be able to have the root flag. After trying different methods, both for capabilities, suid permissions, whether cron tasks are executed, etc. When we see the version of the machine we search the internet to see if we find an exploit in that version and we find one.

uname esc

The exploit.sh file executed a line, what I did was first read it and interpret it and then modify it in the part where you passed the command to execute. So what I did was give suid permissions to /bin/bash to be able to connect as root through SUID permissions

The command I executed was the following:

unshare -rm sh -c "mkdir l u w m && cp /u*/b*/p*3 l/;setcap cap_setuid+eip l/python3;mount -t overlay overlay -o rw,lowerdir=l,upperdir=u,workdir=w m && touch m/*;" && u/python3 -c 'import os;os.setuid(0);os.system("chmod u+s /bin/bash")'

root