Linux: Privilege Escalation Basics
From a low-privilege shell to root: sudo rules, SUID binaries, and cron jobs.
Getting a shell is rarely the end. Attackers (and penetration testers) then look for misconfigurations that let them become root. Defenders need to know the same list.
1
sudo and SUID
sudo rules.
sudo -llists what your user may run as root. A rule like this is dangerous:(root) NOPASSWD: /usr/bin/findbecause
findcan run other commands:sudo find . -exec /bin/sh \;gives a root shell. The site GTFOBins catalogs which binaries can be abused this way.SUID binaries run with the file owner's privileges, whoever starts them. In
ls -lthe owner'sxbecomes ans:-rwsr-xr-x 1 root root 54096 /usr/bin/passwdFind all SUID files:
find / -perm -4000 -type f 2>/dev/nullpasswdlegitimately needs SUID. A SUID copy ofbashorpythonis a gift to attackers.2
Cron jobs and root
cron runs scheduled jobs. The system-wide schedule lives in
/etc/crontab:*/5 * * * * root /opt/backup/backup.shThis runs
backup.shas root every 5 minutes. If your user can write tobackup.sh, you can put any command in it and it will run as root.Whatever the route, the goal is the same account: root, which always has user ID (UID) 0. You can check with
id.
โ Report a problem with this room
Log in to report a problem.