Page cover

Week 6. Titanic

SUMMARY

This is an Ubuntu 22.04 machine hosting a Gitea server and a web site vulnerable to path traversal. Leveraging this we get access to the Gitea SQLite database, where we find PBKDF2 hashes that we crack to get initial SSH access.

Regarding escalation, we exploit an arbitrary code execution vulnerability affecting ImageMagick 7.1.1-35.

KEYWORDS

Gitea, path traversal, PBKDF2 hashes, ImageMagick 7.1.1-35

ENUMERATION

Port scan.

> for ports in $(nmap $target -p- --min-rate=5000 -Pn --open --reason | grep open | awk -F "/" '{print $1}' | tr '\n' ',' | sed s/,$//); do nmap $target -p$ports -sV -sC -Pn -vv -n && echo "\nList of open ports: $ports";done

Starting Nmap 7.93 ( https://nmap.org )
Nmap scan report for 10.10.11.55
Host is up, received user-set (0.13s latency).
PORT   STATE SERVICE REASON  VERSION
22/tcp open  ssh     syn-ack OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 73039c76eb04f1fec9e980449c7f1346 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBGZG4yHYcDPrtn7U0l+ertBhGBgjIeH9vWnZcmqH0cvmCNvdcDY/ItR3tdB4yMJp0ZTth5itUVtlJJGHRYAZ8Wg=
|   256 d5bd1d5e9a861ceb88634d5f884b7e04 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDT1btWpkcbHWpNEEqICTtbAcQQitzOiPOmc3ZE0A69Z
80/tcp open  http    syn-ack Apache httpd 2.4.52
|_http-title: Did not follow redirect to http://titanic.htb/
|_http-server-header: Apache/2.4.52 (Ubuntu)
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
Service Info: Host: titanic.htb; OS: Linux; CPE: cpe:/o:linux:linux_kernel

Nmap done: 1 IP address (1 host up) scanned in 15.26 seconds

List of open ports: 22,80

Add to hosts file and enumerate the web site with Firefox.

If you enumerate a bit the web site you see there is a path traversal in http://titanic.htb/download?ticket, and a Gitea server running in dev.titanic.htb subdomain.

Update the hosts file and browse the Gitea stuff.

In the file flask-app/app.py you can see the API source code, and how the user input is used without sanitization, which is the explanation for the path traversal vulnerability.

Whereas in the docker-config/gitea/docker-compose.yml file we find the path of the default Gitea data directory.

USER

You can ask somewhere, or investigate, where to find Gitea config files when it is running as a Docker container.

Let's start using path traversal vulnerability with the home/developer/gitea/data/gitea/conf/app.ini file. In it we see lots of interesting stuff, for example, location of the SQLite database.

Just download it and inspect its content.

In the user table there are two hashes.

In order to crack them, first we convert its format to a Hashcat readable format.

Now you can safely crack it with Hashcat module 10900.

And use the cracked password to login as developer and collect the user flag.

ROOT

Start from the low-priv shell and take the opportunity to enumerate the user and the system.

If you enumerate a bit the file system, you find this script /opt/scripts/identify_images.sh

It seems it is related to application ImageMagick 7.1.1-35.

Which in turn is vulnerable to arbitrary code execution.

To exploit this vulnerability, just move to the /opt/app/static/assets/images directory and create a suitable C file with your favorite payload.

For example this one.

Compile it and wait n minutes till a bash binary with SUID appears in /var/tmp

Then just spawn a root shell.

You are root.

REFERENCES

https://docs.gitea.com/next/installation/install-with-docker

https://www.unix-ninja.com/p/cracking_giteas_pbkdf2_password_hashes

https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-8rxc-922v-phg8

Last updated