Concepts / Exploitation and privilege escalation

Exploitation and privilege escalation

Setuid and setgid

Also called suid, set-user-id bit, perm 4000, chmod u+s

A permission bit that makes a program run as its owner, not as whoever started it — safe on a few tools, dangerous on one that runs other commands.

The s bit runs the program as its owner
The s bit runs the program as its owner

The same user starts both programs. Only the one with the setuid bit runs as its owner, root, whoever started it.

The setuid bit makes a program run as its owner, not as whoever started it. Set with chmod u+s, it shows as -rwsr-xr-x, and find / -perm -4000 finds them. passwd needs it to edit the root-only password file. The danger is a setuid-root program that can run other commands (find -exec, vim): any user gets a root shell. [[gtfobins|GTFObins]] lists them. Setgid does the same with the file's group.

See it on real machines

Read next

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab