root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat canape.md
// writeups

Canape

14 Apr 2018 · 8 min read · root access
Canape - maquina de Hack The Box

Executive summary — Canape is a Medium Linux box (Ubuntu 18.04) serving a Flask application, a "Simpsons Fan Site", whose .git directory is exposed. The recovered source shows an endpoint that deserializes user-controlled data with cPickle, which gives code execution as www-data. From there, a local CouchDB 2.0.0 is vulnerable to CVE-2017-12635, which allows creating an administrator and reading a passwords database that holds the SSH password of homer. Finally, sudo lets that user run pip install * as root, and a malicious package's setup.py executes with those privileges.

PlatformHack The Box
OSLinux (Ubuntu 18.04, Apache 2.4.29)
DifficultyMedium
StatusRetired
Services80 (Apache, Flask app), 65535 (OpenSSH 7.6p1, non-standard port); CouchDB on localhost 5984
TechniquesExposed .git repository, insecure pickle deserialization, CouchDB CVE-2017-12635, credential store in clear text, sudo pip install

Attack map

[80/HTTP] Flask 'Simpsons Fan Site' -> /.git/ exposed
        |  git-dumper -> __init__.py (full application source)
        v
/submit writes raw bytes to /tmp/<md5>.p ; /check cPickle.loads() if it contains 'p1'
        |  protocol-0 pickle with os.system, whitelist word + 'p1' satisfied
        v
Reverse shell as www-data
        |  CouchDB 2.0.0 on localhost:5984, 'passwords' needs auth
        v
CVE-2017-12635 (duplicate 'roles' key) -> admin user -> read 'passwords'
        v
[65535/SSH] homer -> user
        |  sudo: (root) /usr/bin/pip install *
        v
malicious setup.py as root -> SUID bash -> ROOT

1. Reconnaissance

sudo nmap -p- --min-rate 2000 -Pn -n <TARGET_IP> -oN ports.txt
sudo nmap -sCV -Pn -n -p80,65535 <TARGET_IP> -oN svc.txt
PortServiceVersion
80HTTPApache httpd 2.4.29 (Ubuntu), "Simpsons Fan Site"
65535SSHOpenSSH 7.6p1 Ubuntu (non-standard port)

A full-port scan is what finds SSH on 65535. nmap's default scripts already point at the essentials:

| http-git:
|   <TARGET_IP>:80/.git/
|     Git repository found!
|     Last commit message: final ...
|_      http://git.canape.htb/simpsons.git
echo "<TARGET_IP> canape.htb git.canape.htb" | sudo tee -a /etc/hosts

A .git directory served by the web server means the application's source can be reconstructed; git-dumper downloads it:

git-dumper http://<TARGET_IP>/.git/ loot/repo

What comes back is __init__.py, the whole Flask application.

🔒 Clearance required

Root Access unlocks the content you can't see — everything else on the site is already open.

See Root Access plans

No account? Create one free then upgrade from your console.