Box link
https://www.hackthebox.eu/home/machines/profile/314
Summary
This box had a CVE for foothold which exploited msfvenom apk generation. Once we are able to get a shell, we already have user. We have to do horizontal privesc into antoher user by command injection, then basic enumeration to get root.
Exploring the target
First things first, after deploying the box and getting an IP, I started with an nmap scan. In fact, I usually run 2 nmap scans, one to quickly grab the open ports, then one to enumerate the running services in more details, so I’ve ran the following two commands:
|
|
To grab the open ports, then:
|
|
To enumerate service headers and versions.
This gave us the following result:
Nmap result
Foothold
Port 22 didn’t seem interesting, so I moved on to port 5000. This is a python webserver, which isn’t vulnerable, but the application hosted on it is. Looks like we are greeted by a page containing some 1337 h4x0r tools. After poking around for basic command injection and a bit of googling, I came across this exploit. The main “hint” which gave this away was that I could generate apk payloads, which is kinda unusual so I looked into it and suprise suprise it was the right path. This exploit works by injecting arbitary system code into the apk generation of msfvenom, so we have code execution!
I’ll say it now, straight up reverse shell didn’t work for me, rather I had to save the bash reverse shell code to a file, then upload it to the target and run it that way.
We need to modify the payload in line 15.
User
First I made a rev.sh file with the content:
|
|
Next we modify the exploit code to wget
this revshell from our attack box:
|
|
Let’s start a python http server:
|
|
Now we have to run the exploit with python3, which will generate a malicious msfvenom template for us, which we can import on the website during payload generation and the command we gave on line 15 will run hopefully (we can confirm this by looking at the python http server logs).
If successful, the exploit script will generate a malicious apk in the /tmp
folder, which we can use.
After this is done, let’s import the apk on the website.
Once we click generate, we can see the GET request to our python server.
Okay, we have our reverse shell code in the /tmp
folder. Next step is to generate another apk with our exploit, which will run the reverse shell which we saved on the target.
Let’s put the command into the exploit generator first:
|
|
And let’s not forget to open a listener for the shell which will connect back to us:
|
|
We generate another evil.apk
with our exploit python script, import it on the website and send the request. Shortly after this, we get back a shell as kid
.
Let’s stabilize our shell a bit:
|
|
If we go to our home directory, we can find user.txt
there.
Root
After checking out the folders on the target we can see another user’s home directory, called pwn
. We have read privs for some of the files in this directory. We can see, that there’s a file called scanlosers.sh
in this directory, which we can read. This file uses another file as input found at /home/kid/logs/hackers
. We can modify this, so there is confirmed command injection and we should be able to get a shell as pwn
. I already suspected that this shell script runs automatically from time to time, but to confirm this, I’ve moved pspy
onto the target and ran it to monitor results. This indeed confirmed my theory.
Have to take note that the box has some weird anomalies. The method I used for command injection when the box came out didn’t work when I did my wirteup and retried the box. The 2nd method also didn’t work when my friend did the box the 3rd time, so I found another working method. All three methods are listed below.
The first time, I used:
|
|
The one I used the second time I did the box:
|
|
Initially these methods gave me a reverse shell immediately as pwn
, but staff or the box creator probably modified the box several times, or atleast stuff that used to work fine didn’t work anymore. My third method was to copy bash and make it a SUID:
|
|
Then do:
|
|
Had to do this, because being in a SUID bash in another user doesn’t allow us to run sudo
. So had to go through the long steps of getting an actual shell back as the given user.
I’ve ran sudo -l
to see that we can run msfconsole as root. Well you can execute OS commands inside msfconsole, so let’s start it and we can get a root shell.
|
|
Then run
|
|
We are root!