HTB - Artificial

Description


The machine simulates a real-world misconfiguration scenario involving an application that manages and executes .h5 modules. It starts with access to a web interface deployed in a Docker environment. By crafting and uploading a malicious module, remote code execution was achieved. Further enumeration revealed an exposed SQLite database containing hashed credentials, which were cracked to gain access as a local user on the host system. This user, being a member of the sysadm group, had access to an archived Backrest repository. Unpacking the archive exposed sensitive configuration files, including credentials for an administrative user of a host-level application. By abusing the application's backup feature, it was possible to exfiltrate the root user's private SSH key, leading to full system compromise.

Enumeration


Nmap Scan

Summary

I always update /etc/hosts

Foothold


http://artificial.htb/

There were a few endpoints on the sites: /register, /login

http://artificial.htb/register

http://artificial.htb/login

After logging in, I accessed the user's dashboard at http://artificial.htb/dashboard, which featured upload functionality for managing and running AI modules. Also, the site provided requirements and dockerfile to build the needed environment.

I downloaded both files, and here are their contents:

requirements.txt

Dockerfile

My strategy was to prepare the environment first and then create malicious AI module to be executed by the server and gain shell access.

When I tried to install the package in the requirements file, I failed because no matching version. However, I used the docker file to create docker instance.

If Docker is not installed in your VM, run

In the same directory where Dockerfile is located, run

After installation finished, Access the docker image

With this blog, I can create malicious .h5 module and get RCE:

My test exploit script

Upload the module, run it, and I got a reply.

After confirming command execution, I sought shell access. Here are the steps I followed:

  1. In my Docker shell, I started python3 terminal and pasted my exploit

And I could confirm the exploit was created

I could download the exploit to my Kali with this command:

Upload the .h5 file

After uploading the module, A section appeared with the module ID and a link to run your module:

I got the shell with penelope or any other listener (Ex: nc)

Lateral Movement


Under /app/instance directory, there was the site database:

Download the file:

The database wasSQLite, so I used sqlitebrowser to open it

There was User table and inside it several records (users & hashes):

One of the hashes was cracked:

There was another user in the box called gaelUsing the cracked password, I managed to compromise him and get the user flag

User Flag: 149c8c8a3296529c41xxxxxxxxxxxxx

Privilege Escalation


The user is on sysadm group. When I searched for files/directories created or owned by that group, I found one archive file:

Under /optThere was a directory with the same name: backrest. After downloading the file with the same nc trick, I unpicked the archived file and noticed the difference:

A hidden config directory:

The directory contained a JSON file that stored the username and password hash.

The password seemed to be base64 and not Bcrypt, so I tried to decode it and got the actual hash

Then, I cracked the hash with hashcat

The baskret application was running locally on port 9898

Forward the port with SSH to access the application. Then, log in as the user in config.json

The application is used for backup operation and it was running as root, so I could abuse it to backup the private key for root user or get the root flag

  1. Add repo

  1. Add plan

  1. Click on plan1 and then Run Command

  1. Backup /root directory

  1. Then dump the root private key

  1. Access the box as root

  1. Get root flag

Root Flag: 8be64cf645053b4cc23xxxxxxxxxxxxx

Last updated