Canape

Gaining Access

Nmap scan:

$ nmap -p- --min-rate 4000 10.129.107.118          
Starting Nmap 7.93 ( https://nmap.org ) at 2023-08-17 17:06 +08
Nmap scan report for 10.129.107.118
Host is up (0.011s latency).
Not shown: 65533 filtered tcp ports (no-response)
PORT      STATE SERVICE
80/tcp    open  http
65535/tcp open  unknown

Did a detailed scan as well:

$ nmap -p 80,65535 -sC -sV --min-rate 4000 10.129.107.118                              
Starting Nmap 7.93 ( https://nmap.org ) at 2023-08-17 17:07 +08
Nmap scan report for 10.129.107.118
Host is up (0.0073s latency).

PORT      STATE SERVICE VERSION
80/tcp    open  http    Apache httpd 2.4.18 ((Ubuntu))
| http-git: 
|   10.129.107.118:80/.git/
|     Git repository found!
|     Repository description: Unnamed repository; edit this file 'description' to name the...
|     Last commit message: final # Please enter the commit message for your changes. Li...
|     Remotes:
|_      http://git.canape.htb/simpsons.git
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-trane-info: Problem with XML parsing of /evox/about
|_http-title: Simpsons Fan Site
65535/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 8d820b3190e4c885b2538ba17c3b65e1 (RSA)
|   256 22fc6ec35500850f24bff5796c928b68 (ECDSA)
|_  256 0d912751805e2ba3810de9d85c9b7735 (ED25519)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

There's a .git repository present on the website. There is also a domain we have to add to our /etc/hosts file.

Web + Git Enumeration

The website was a Flask based website:

We can submit quotes to be viewed on the website through the using specific Simpsons characters:

Since we have a .git repository, we can dump that out first.

Then, we can view the files present.

cPickle RCE

There was an __init__.py file that contained the source code for the website. There were a few interesting routes:

Pickling is used here, and it might be exploitable later. If p1 is in data, then it passes it to the cPickle.loads() function. The cPickle function used actually allows for RCE.

Based on online scripts, we have to create a Python class using the __reduce__ with our command, and then pickle the content using the cPickle library. Afterwards, we need to send a POST request to /check with the id parameter set to the MD5 hash of our character and payload combined.

To bypass the character check, we just need to include a Simpsons character as a substring of the actual thing.

The website code uses python2, so I also used python2 to match:

Running it gives me this string:

The reason we split the string by * is because of the weird string it generates. Running this gives us a shell:

Privilege Escalation

We cannot read the user's flag yet.

CouchDB -> User Creds

The user was called homer, and they were running some processes:

CouchDB was being run on the machine, and it is running a vulnerable version.

However, this exploit does not seem to work on the machine. Since this is a DB and can interact with it, perhaps it has passwords within it. The references within the exploit have a link to this:

The above uses curl to create a new administrator user on the machine.

Afterwards, we can read the passwords:

The one on the last row contains a hint about the user's password:

With this, we can ssh in as homer using the password from the other fields:

Sudo Pip -> Root

When checking sudo privileges, we see that we can run pip install as root:

Using this, we can spawn a root shell using the PoC on GTFOBins:

Rooted!

Last updated