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

TechniqueT1548 (Abuse Elevation Control Mechanism)
AlsoT1053.003 (Cron)
Usual causeMisconfiguration, not zero-days
Common areassudo, SUID files, cron, credentials, kernel
ReferenceGTFOBins (which programs can be abused)
DefenseLeast privilege + patching + auditing

Step by step

  1. 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.

  2. 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.

  3. Misconfiguration 1: sudo A tool that can do more than intended

    The admin allowed www-data to 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.

  4. Misconfiguration 2: writable cron script Root runs what anyone can edit

    Root's cron runs /opt/backup.sh every 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 with id output, then removes it.

  5. 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

More in Penetration Testing.