
Week 12. Chemistry
TL;DR
This is an Ubuntu 20.04 machine hosting an application used to upload CIF files. This is a format used by scientific programs for storing crystallographic structural data. The applications used to read the data contained in the files are based on Python but, unfortunately, one of the parsing libraries is vulnerable since it calls eval() function without proper sanitization (CVE-2024-23346). We exploit this to get an initial shell in the system, then move laterally to another user after finding an MD5 hash in a local SQLite database file. Regarding escalation, we exploit a web application based on library aiohttp/3.9.1, a version vulnerable to path traversal (CVE-2024-23334).
KEYWORDS
Crystallographic Information Files (CIF), pymatgen, CVE-2024-23346, SQLite, aiohttp/3.9.1, CVE-2024-23334.
REFERENCES
https://www.ccdc.cam.ac.uk/media/MoreInformationAboutCIFsyntax.pdf
https://www.cvedetails.com/cve/CVE-2024-23346
https://github.com/materialsproject/pymatgen/security/advisories/GHSA-vgv8-5cpj-qj2f
https://www.cvedetails.com/cve/CVE-2024-23334
ENUMERATION
Port scan.
> nmap $target -p- --min-rate=5000 -Pn --open --reason
Starting Nmap 7.93 ( https://nmap.org ) at 2024-11-27 11:15 EST
Nmap scan report for chemistry.htb (10.10.11.38)
Host is up, received user-set (0.039s latency).
Not shown: 64413 closed tcp ports (conn-refused), 1120 filtered tcp ports (no-response)
Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
PORT STATE SERVICE REASON
22/tcp open ssh syn-ack
5000/tcp open upnp syn-ack
Nmap done: 1 IP address (1 host up) scanned in 13.90 secondsEnumerate the open ports.
There is a web server listening on port 5000, enumerate the site with Firefox.

Sign up a new account and login. A web site to upload CIF files comes into view, the page offers the possibility to download an example of these kind of files.
It seems these are text files for storing crystallographic structural data and it is used by programs to process the data. More info here: https://www.ccdc.cam.ac.uk/media/MoreInformationAboutCIFsyntax.pdf
There is a vulnerability in one of the in the parsing libraries,pymatgen, that insecurely calls eval() function without proper input sanitization. More info here: https://www.cvedetails.com/cve/CVE-2024-23346
A PoC is available here: https://github.com/materialsproject/pymatgen/security/advisories/GHSA-vgv8-5cpj-qj2f
USER
Prepare a payload for instant reverse shell. I just took the example CIF file provided in the site and added a payload based on the PoC.
Upload the file exploit.cif and click on "View".

A reverse shell for user app is received on port 1919.

This user does not have permissions to retrieve the user flag, so we will have to enumerate the rest of the host's users with a defined shell.
It seems we have to move laterally to user rosa
Let's start enumerating the app.py source code in the /home/app directory.
This looks like source code for several API endpoints, and an SQLite database is mentioned also. The database file is in the location /home/app/instance/database.db
Inside the database there are several MD5 hashes, including rosa's.
This can be cracked with john
Use the password to SSH in as rosa and collect the user flag.

ROOT
Start from rosa's low-priv shell and take the opportunity to enumerate the user and the system.
Enumerate local connections, there is something listening on port 8080.
Forward the port to your machine and enumerate the site with Firefox. I used local port 9000 to avoid conflicts with Burpsuite, which I'll use later and is running also on port 8080.
Some kind of monitoring web site appears.

I couldn't find any info related to the site by inspecting it so I captured the traffic with Burpsuite and analyzed the requests
First, it seems the application uses Python 3.9 aiohttp/3.9.1.

And also take note of the application folder structure.

Looking for vulnerabilities affecting the aiohttp library, I found there is a path traversal: https://www.cvedetails.com/cve/CVE-2024-23334
It can be exploited with curl to retrieve root's private key.

The only thing that's left is to use the private key to log in and gather the root flag.

You are root.
Last updated