Canape
Executive summary — Canape is a Medium Linux box (Ubuntu 18.04) serving a Flask application, a "Simpsons Fan Site", whose
.gitdirectory is exposed. The recovered source shows an endpoint that deserializes user-controlled data withcPickle, which gives code execution aswww-data. From there, a local CouchDB 2.0.0 is vulnerable to CVE-2017-12635, which allows creating an administrator and reading apasswordsdatabase that holds the SSH password ofhomer. Finally,sudolets that user runpip install *as root, and a malicious package'ssetup.pyexecutes with those privileges.
| Platform | Hack The Box |
| OS | Linux (Ubuntu 18.04, Apache 2.4.29) |
| Difficulty | Medium |
| Status | Retired |
| Services | 80 (Apache, Flask app), 65535 (OpenSSH 7.6p1, non-standard port); CouchDB on localhost 5984 |
| Techniques | Exposed .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
| Port | Service | Version |
|---|---|---|
| 80 | HTTP | Apache httpd 2.4.29 (Ubuntu), "Simpsons Fan Site" |
| 65535 | SSH | OpenSSH 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.
Root Access unlocks the content you can't see — everything else on the site is already open.
See Root Access plansNo account? Create one free then upgrade from your console.