Meta is a medium rated machine on HackTheBox created by Nauten. For the user part we will abuse a CVE in exiftool to obtain a reverse shell on the machine. This will be followed up by another CVE inside ImageMagick which will give us a shell as another user. To escalate to root we will modify a config file for neofetch which we are able to run using sudo.
User
As usual we start our enumeration with a nmap scan against all ports followed by a script and version detection scan against the open ones to get an initial overview of the attack surface.
Nmap
All ports
1 |
|
Script and version
1 |
|
Exfitool
The nmap scan leaks the hostname artcorp.htb
so we add it to our /etc/hosts
. Opening the page up in our browser it looks like a completly static webpage without much functionality.
Checking for additional vhosts using ffuf we are able to find dev01.artcorp.htb
which we also add to our /etc/hosts
.
1 |
|
Going there we see a development page with only one application available.
Clicking on MetaView
there is a file upload form which tells us to upload an image to display metadata.
Uploading a test jpg
the output looks like straight from exiftool.
There has been a recent CVE(CVE-2021-22204)with remote code execution in exiftool. Using this PoC where we only have to adjust our ip address to tun0 and the port to where we want to catch the reverse shell we can generate an image that sends a python reverse shell back to our machine.
exploit.py
1 |
|
Running the script the image is getting updated with the payload.
1 |
|
Now we just have to set up a listener on the port we specified and upload the generated image to the website.
1 |
|
After we click the upload button the page hangs and we get a connection back on our ncat listener as www-data which we upgrade using python and fix the terminal size.
1 |
|
ImageMagick
Taking a look around on the system and monitoring for running processes there seems to be a cronjob being run by the user thomas who has the uid of 1000.
1 |
|
Checking the script it cd’s into the directory /var/www/dev01.artcorp.htb/convert_images
and then calls /usr/local/bin/mogrify
on all files machting *.*
with an output format of png.
/usr/local/bin/convert_images.sh
1 |
|
Taking a closer look at the mogrify it is actually a symlink to magick
which is part of ImageMagick.
1 |
|
To check for possible CVE’s in ImageMagick we need the version number first.
1 |
|
Looking the version up on google we are able to find a PoC which should work with the installed version of ImageMagick. The PoC abuses the the authentication mechanism for password protected PDF’s to pass additional shell commands. To abuse this we first we generate a base64 encoded reverse shell payload.
1 |
|
We then take the poc.svg
from the blogpost and exchange the payload with our reverse shell.
poc.svg
1 |
|
All we have to do now is to set up a ncat listener and to drop the file in the /var/www/dev01.artcorp.htb/convert_images
on the target machine.
1 |
|
1 |
|
After some time we get a connection back as thomas and are able to read the user flag.
1 |
|
Root
Checking for sudo permission thomas is able to run /usr/bin/neofetch
as the root user. An interesting point here is the env_keep+=XDG_CONFIG_HOME
flag for the sudoers entry.
env_keep
means that this environment variable will not be reset when calling sudo even though env_reset
is present aswell.
1 |
|
To see what we can do with this we can look for the variable in the source code of neofetch. The variable is used to declare the configuration directory of neovim. The interesting thing here is that the configuration file for neoftech get’s sourced. This means that anything we put into the configuration file will be eventually executed setting the XDG_CONFIG_HOME
.
/usr/bin/neofetch
1 |
|
To abuse this we can simply append a command setting the suid bit on bash to the config file, export the XDG_CONFIG_HOME
variable and run neofetch with sudo. Finally we can use the -p
flag on bash to keep the suid permissions on our modified bash and add the root flag to our collection.
1 |
|