Linux Privilege Escalation
From a low-privilege shell to root, and how to prevent it
Getting a foothold as an ordinary user is rarely the end of an attack. Privilege escalation turns limited access into full control, almost always through misconfiguration rather than clever exploits: overly broad sudo rules, scripts that root runs but anyone can edit, leftover passwords, and unpatched software.
Intermediate · 5 steps
| Technique | T1548 (Abuse Elevation Control Mechanism) |
|---|---|
| Also | T1053.003 (Cron) |
| Usual cause | Misconfiguration, not zero-days |
| Common areas | sudo, SUID files, cron, credentials, kernel |
| Reference | GTFOBins (which programs can be abused) |
| Defense | Least privilege + patching + auditing |
Step by step
The foothold An ordinary user on a test server
During an authorised test, a web application flaw gives the tester a shell as
www-data, the low-privilege account the web server runs as. It can read the website's files but not much else. The question now is whether this server's configuration lets that user become root.Enumerate Look before you leap
The tester gathers facts: user and groups, OS and kernel version, sudo rules, files with the SUID bit, scheduled jobs, running services, and readable configuration files. Scripts such as LinPEAS automate this checklist, but it's the same questions either way.
Misconfiguration 1: sudo A tool that can do more than intended
The admin allowed
www-datato run a file-viewing tool as root without a password, meaning to let it read logs. But many programs, including pagers and editors, can open a shell or read any file. Public references like GTFOBins list which ones. This sudo rule effectively grants full root access.Misconfiguration 2: writable cron script Root runs what anyone can edit
Root's cron runs
/opt/backup.shevery five minutes, but the file is writable by every user. Anything added to it would run as root at the next run. The tester proves it harmlessly by adding a line that writes a marker file withidoutput, then removes it.Fix and detect Close the gaps, watch for misuse
The fixes are simple: replace the sudo rule with a specific log-reading command, make the backup script owned and writable only by root, and audit SUID files. Audit rules send an alert to the SIEM whenever sudo is used unexpectedly or a file run by root is modified.
Best practices
- Give sudo only for specific commands, and never for tools that can run other programs or edit files
- Make sure scripts run by root are writable only by root
- Remove unnecessary SUID permissions and audit them regularly
- Keep passwords and keys out of world-readable files and shell history
- Patch the kernel and packages, and alert on unexpected root processes
More in Penetration Testing.
Packets
| No. | Time | Source | Destination | Protocol | Info | Size |
|---|