
HTB: Chemistry
Chemistry runs a CIF Analyzer web app built on pymatgen, whose CIF parser carries an arbitrary-code-execution bug (CVE-2024-23346). A crafted file hands us a reverse shell as the app user, a SQLite database gives up rosa's MD5 hash which hashcat cracks in seconds for SSH and the user flag, and a root-owned internal app on localhost 8080 falls to a path-traversal LFI we use to read root.txt.
Kicking things off with an nmap scan, we spot something running on port 5000. Let's load it up in a browser and see what it is.

It's a Chemistry CIF Analyzer, a tool for uploading and analyzing CIF (Crystallographic Information File) data. There's a login and a register option, so let's make an account and poke around.

Once we're in, we land on a dashboard that lets us upload a CIF file for analysis. An upload feature that parses a structured file format is always a great place to go looking for trouble.

Researching CIF-parsing vulnerabilities points us straight at the Python library doing the work: pymatgen. It has a known arbitrary-code-execution bug in its CIF parser, tracked as CVE-2024-23346 (advisory GHSA-vgv8-5cpj-qj2f). A specially crafted CIF file can smuggle in a Python expression that the parser happily evaluates, which means we can run commands on the box just by uploading a file.
The advisory ships a proof-of-concept CIF we can adapt. We edit the embedded command so it calls back to a reverse shell, start an nc listener, and upload the file. My first attempt wired up a bash reverse shell and never caught. After some trial and error (and a fair bit of overthinking), the fix was almost embarrassingly simple: a plain sh reverse shell instead of bash, and the connection came straight back.

With a shell as the app user, let's stabilise it into a proper TTY and start enumerating.
python3 -c 'import pty;pty.spawn("/bin/bash")'

Poking around the application directory, there's an instance folder holding a SQLite database. Let's dump the users table.
sqlite3 /home/app/instance/database.db "SELECT username, password FROM user;"

We get back a pile of MD5 password hashes, including one for rosa, the other user on the box. Feeding it to hashcat with rockyou, it falls in seconds.

rosa reuses that password for SSH, so we log straight in, and the user.txt flag is sitting right there in her home directory.

Time to hunt for a privesc. Checking what's listening locally, we find a service bound to 127.0.0.1 on port 8080 that isn't exposed externally, some kind of site-monitoring app.

A quick probe shows this internal app is vulnerable to local file inclusion through path traversal. Since it's running as root, we can read any file on the system, the root flag included.
curl --path-as-is "http://127.0.0.1:8080/assets/../../../../root/root.txt"

This box wasn't too easy but also not too hard. I got stuck at the initial foothold for a while purely from overthinking it, the whole time I could have just used an sh reverse shell but kept forcing /bin/bash. Good reminder: when you're stuck, calm down, step back a few moves, and reassess the position you're in. Once I was on the box, the privesc was smooth and quick.
