Security operations

Linux Privilege Escalation: Techniques, Detection and Fixes

Most Linux privilege escalation is not a zero-day. It is a misconfigured sudo rule, a stray SUID binary or a writable cron script. Here are the techniques attackers use, the commands that find them, and the fixes that close them.

Cysoro Security TeamPublished · 9 min read
$ sudo -l(ALL) NOPASSWD: ALLfind / -perm -4000/usr/bin/find# root shell →$ id → uid=0(root) SECURITY OPERATIONS Linux privilege escalation From user to root — and how to stop it.
Quick answer

Linux privilege escalation is the process of gaining root or another higher privilege from a low-privilege account, usually by abusing a misconfiguration rather than a software bug. The most common paths are SUID binaries, sudo misconfigurations, writable cron jobs, PATH hijacking, Linux capabilities and kernel vulnerabilities. Defenders find them with enumeration tools such as LinPEAS and fix them by removing unneeded privileges and auditing sudo, cron and file permissions.

Key takeaways

  • Most Linux privilege escalation abuses misconfigurations — SUID, sudo, cron and capabilities — not zero-day exploits.
  • Enumeration is the attacker's first step: sudo -l, SUID scans, cron review and capability checks reveal the path to root.
  • The fixes are boring and effective: least privilege, regular sudo and SUID audits, patching, and auditd logging of elevation.

An attacker who lands on a Linux server as www-data or a service account has not won yet. What they have is a foothold. Privilege escalation is the next step: turning that low-privilege shell into root, and with it, full control of the system. Most of the time, no zero-day is needed — a misconfigured sudo rule, a stray SUID binary or a writable cron script does the job.

What is Linux privilege escalation?

Linux privilege escalation is gaining a higher level of permission than you were given, usually root, on a Linux system. MITRE ATT&CK groups these techniques under tactic TA0004, Privilege Escalation, and describes them as taking advantage of system weaknesses, misconfigurations and vulnerabilities.

There are two kinds. Vertical escalation moves up: a normal user becomes root. Horizontal escalation moves sideways: one user gains another user's access at the same level. This article covers vertical escalation to root, which is the case defenders worry about most.

Attackers escalate for a simple reason: root can read any file, install persistence, disable defenses, steal credentials and move to other systems. Without root, an attacker is limited to what one account can touch. With root, the whole host is theirs.

How does Linux privilege escalation work?

Almost every escalation follows the same pattern: enumerate, find a weak elevation path, abuse it, then clean up and persist. The enumeration step is where most attacks are won or lost.

The privilege escalation attack flow 1 Enumerate sudo -l, SUID, cron, kernel, capabilities 2 Find a path a misconfig or a known CVE 3 Abuse it spawn a root shell, overwrite a file 4 Persist new user, SSH key, cron backdoor Defenders should break the chain at step 1: find the paths before an attacker does.
Enumeration finds the path; the abuse itself is usually a single command. Illustration by Cysoro.

Automated tools speed up enumeration. LinPEAS, the Linux Privilege Escalation Awesome Script, scans for hundreds of misconfigurations and color-codes likely exploitable findings in red and yellow. It checks SUID binaries, sudo rules, cron jobs, writable directories in PATH, capabilities, environment variables and running processes. Other tools in the same role are LinEnum and linux-exploit-suggester, which matches the kernel version against known exploits.

The commands in this article are for authorized testing on systems you own or have written permission to test, and for defenders checking their own hosts. Running them against systems you do not own is illegal in most countries.

How do you enumerate a Linux host for escalation paths?

Enumeration starts with the basics: who you are, what the system is, and what you are allowed to do. These commands are the standard first pass, and they are the same commands a defender should run in an audit.

  • id and groups — your user, groups and privileges.
  • uname -a and cat /etc/os-release — kernel and distribution version, for known CVEs.
  • sudo -l — every command you may run as root through sudo.
  • find / -perm -4000 -type f 2>/dev/null — SUID binaries.
  • getcap -r / 2>/dev/null — binaries with Linux capabilities.
  • cat /etc/crontab, crontab -l and systemctl list-timers --all — scheduled jobs.
  • env and echo $PATH — environment variables and writable PATH directories.
  • ls -la /etc/passwd /etc/shadow — whether password files are writable.

Check the results against a known-good baseline. A single unexpected SUID binary or sudo rule is the kind of thing that matters — and the kind of thing that is easy to miss in a long list.

What are the main Linux privilege escalation techniques?

Six paths cover most real-world Linux escalation: SUID abuse, sudo misconfiguration, cron hijacking, PATH injection, capabilities abuse and kernel exploits. The first five are misconfigurations; only the last needs a software vulnerability.

TechniqueMITREWhat the attacker abusesTypical fix
SUID / SGID abuseT1548.001Root-owned binary that can spawn a shell or write filesRemove the SUID bit where it is not needed
Sudo misconfigurationT1548.003NOPASSWD, wildcards or shell-spawning sudo commandsLeast-privilege sudoers, no wildcards
Cron hijackingT1053.003Writable cron script or PATH used by a root cron jobRoot-owned scripts, tight permissions
PATH injectionT1574.006 / T1574Writable directory early in PATH, or a relative binary callAbsolute paths, no writable PATH dirs
Capabilities abuseT1548Binary with cap_setuid or cap_dac_overrideRemove unneeded capabilities
Kernel exploitT1068Unpatched kernel vulnerabilityPatch promptly, use live patching

SUID and SGID abuse

When the SUID bit is set on a binary, it runs with the file owner's privileges, not the caller's. A root-owned SUID binary therefore runs as root, whoever invokes it. That is legitimate for tools such as passwd and sudo themselves — and dangerous for anything that can spawn a shell or write arbitrary files.

The classic examples are find, vim and python3 with the SUID bit set. A SUID find can run find . -exec /bin/sh -p \; -quit and drop to a root shell. The -p flag preserves the effective UID. GTFOBins documents exploitation paths for hundreds of SUID binaries; if you find a non-standard SUID binary, check it there.

Fix: list SUID binaries regularly, remove the bit from anything that does not need it with chmod u-s, and alert on new SUID files. SGID works the same way for group privileges.

Sudo misconfiguration

Sudo lets specified users run commands as other users, typically root. A misconfigured sudoers file is the most commonly exploited privilege escalation vector in enterprise Linux environments, because a single careless rule hands over root.

The dangerous patterns are: NOPASSWD entries for powerful commands, wildcards in sudo rules that allow argument injection, and sudo access to programs that can spawn a shell — vim, find, less, cp and editors in general. For example, sudo vim -c ':!/bin/bash' gives a root shell if vim is sudo-allowed. Environment tricks such as LD_PRELOAD can also escalate when sudo preserves unsafe variables.

Fix: give each user only the exact commands they need, with full paths and no wildcards, require a password, keep tty_tickets enabled, and set timestamp_timeout to 0 so the password is asked each time. Edit sudoers only with visudo, which checks the syntax before saving.

Cron job hijacking

Cron runs scheduled jobs, often as root. If a root cron job runs a script that a low-privilege user can write to, the attacker simply edits the script and waits for cron to run it as root. The same applies to cron jobs that call binaries by relative name, or that use a PATH containing a writable directory.

Wildcard injection is a subtler variant: a cron job that runs tar or rsync with a wildcard over a writable directory can be tricked into running attacker-controlled options. The pspy tool watches process execution in real time without root, which attackers use to discover cron jobs — and defenders can use the same way.

Fix: make every cron script root-owned and non-writable by others, use absolute paths in cron jobs, avoid wildcards over writable directories, and review systemd timers as well as crontabs.

PATH injection and dynamic linker hijacking

When a privileged program calls another program by name rather than by absolute path, the shell searches the directories in PATH in order. If a writable directory sits early in PATH, an attacker can place a malicious binary with the same name there and have root run it.

Dynamic linker hijacking is the same idea for shared libraries: a privileged binary that loads a library from a writable location, or that honors LD_PRELOAD, can be made to load attacker code. MITRE lists this under hijack execution flow, including dynamic linker hijacking as T1574.006.

Fix: use absolute paths in scripts and services, keep writable directories out of root's PATH, and do not let sudo preserve LD_PRELOAD or other dangerous environment variables.

Linux capabilities abuse

Capabilities split root's power into smaller pieces. A binary with cap_setuid can change its user ID; one with cap_dac_override can bypass file permissions. They are meant to be a safer alternative to SUID — but a capability on the wrong binary is as good as root.

For example, a Python binary with cap_setuid lets an attacker run os.setuid(0) and become root. Check capabilities with getcap -r / 2>/dev/null and treat any unusual entry the same way you would treat an unusual SUID binary.

Fix: remove capabilities that are not needed, prefer SUID-free designs where possible, and include capability checks in your regular audits.

Kernel exploits

When no misconfiguration is exploitable, attackers target the kernel directly. Kernel exploits bypass application-layer controls — they work regardless of sudo policy, file permissions or AppArmor and SELinux configuration. They are powerful but risky: a bug in exploit code can panic the system, so they are usually a last resort.

Notable Linux kernel privilege escalation vulnerabilities include Dirty COW (CVE-2016-5195), Baron Samedit in sudo (CVE-2021-3156, sudo before 1.9.5p2), PwnKit in pkexec (CVE-2021-4034), and DirtyPipe (CVE-2022-0847, Linux 5.8 to 5.16, which allowed overwriting read-only files to gain root). Newer examples include GameOver(lay) (CVE-2023-2640 and CVE-2023-32629) affecting Ubuntu.

Fix: patch kernels promptly, use live patching where available so reboots do not delay fixes, and keep sudo, polkit and other privilege tools updated. The MITRE T1068 page on exploitation for privilege escalation documents this technique family.

How do you detect Linux privilege escalation?

Detection starts with logging the elevation paths. If you log sudo use, SUID execution and cron changes, most escalation attempts leave a clear trail.

Detection: what to log and alert on Log with auditd sudo executions, SUID runs with euid=0 by a non-root user, cron file changes. Alert in the SIEM A shell spawned with effective UID 0 by a non-root process is the core signal. Watch for new paths New SUID binaries, sudoers changes and new cron jobs need a ticket. Compare against a baseline Run LinPEAS output on a clean host, then diff it on every audit.
Log elevation, alert on root shells from non-root users, and diff against a baseline. Illustration by Cysoro.
  • auditd: flag processes that execute with effective UID 0 but were started by a non-root user — the direct signature of SUID abuse.
  • sudo logging: forward sudo logs to your SIEM and alert on sudo use outside normal patterns, especially interactive shells.
  • File integrity monitoring: alert on changes to /etc/sudoers, /etc/crontab, cron directories and SUID binaries.
  • Sigma rules: community Sigma rules exist for SUID execution by non-root users and for sudo abuse; use them as a starting point.
  • Baseline diffs: run LinPEAS on a clean host, save the output, and compare it on every audit. A new SUID binary or capability stands out immediately.

MITRE's T1548 page on abuse of elevation control mechanisms lists detection and mitigation guidance per sub-technique, including sudo, SUID and sudo caching.

How do you prevent Linux privilege escalation?

Prevention is mostly hygiene, applied consistently. No single control closes every path, but together they make escalation hard and noisy.

  1. Apply least privilege everywhere. Users, service accounts and containers get only the permissions they need, and no more.
  2. Audit sudo monthly. Review sudo -l output for every user, remove NOPASSWD and wildcards, and delete stale rules.
  3. Audit SUID, SGID and capabilities quarterly. Compare against a baseline and remove anything unneeded.
  4. Lock down cron and services. Root-owned scripts, absolute paths, and systemd units with tight permissions.
  5. Patch fast. Kernel, sudo and polkit updates close the exploit path; live patching removes the reboot excuse.
  6. Run services as non-root users with separate accounts, and use containers or SELinux and AppArmor to limit what a compromise can reach.
  7. Disable or remove unneeded software. Every installed binary with SUID or capabilities is a potential path.

For a wider starting point, our small business cybersecurity checklist covers patching, access reviews and backups alongside host hardening.

Put these checks on a schedule in your security baseline so they run every month, not just after an incident.

What about privilege escalation in containers and Docker?

Containers add a new escalation surface. A container running as root, or with the Docker socket mounted inside it, can often escape to the host. Membership in the docker group is effectively root on the host, because it allows mounting the host filesystem.

Check for containers running as root, privileged containers, mounted Docker sockets, and users in the docker group who do not need it. Run containers as non-root users, drop unneeded capabilities, and use read-only root filesystems where possible.

The bottom line

Linux privilege escalation is usually a configuration problem, not a vulnerability problem. The attacker enumerates, finds a sudo rule, SUID binary, cron script or capability that should never have existed, and uses it. The defender's job is to find those paths first.

Run the enumeration commands on your own hosts this week, fix what you find, and put SUID, sudo and cron checks on a recurring schedule. If you need a starting point for the wider hardening work, the small business cybersecurity checklist covers the controls that sit around privilege escalation.

Frequently asked questions

What is Linux privilege escalation?

It is gaining a higher privilege, usually root, from a low-privilege Linux account. Attackers abuse misconfigurations such as SUID binaries, sudo rules, cron jobs and capabilities, or exploit a kernel vulnerability.

What is the most common Linux privilege escalation technique?

Sudo misconfiguration is the most commonly exploited vector in enterprise Linux environments. A NOPASSWD rule, a wildcard, or sudo access to a shell-spawning program such as vim or find can give an attacker root.

What is a SUID binary?

A SUID (set user ID) binary runs with the privileges of its owner, not the user who runs it. A root-owned SUID binary that can spawn a shell, write files or run commands gives whoever runs it a path to root.

How do I check for privilege escalation risks on Linux?

Run sudo -l, list SUID binaries with find, review cron jobs and systemd timers, check capabilities with getcap, and run an enumeration tool such as LinPEAS on a test system. Review the output for anything non-standard.

What is LinPEAS?

LinPEAS is an open-source enumeration script that scans a Linux host for hundreds of privilege escalation misconfigurations, including SUID binaries, sudo rules, cron jobs, capabilities and writable paths. It color-codes likely exploitable findings.

How do you detect Linux privilege escalation?

Log sudo use, SUID execution by non-root users and cron changes with auditd or Sysmon for Linux, forward the logs to a SIEM, and alert on shells spawned with effective UID 0 by a non-root user.

Is privilege escalation illegal?

Yes, when done without authorization. Testing these techniques is only lawful on systems you own or have written permission to test, such as in a penetration test or a lab.

What is the difference between vertical and horizontal privilege escalation?

Vertical escalation gains a higher privilege, such as a normal user becoming root. Horizontal escalation gains the same level of privilege as another user, such as one user reading another user's files.

Sources

  1. Hive Security — Linux Privilege Escalation: Attack Techniques and How to Detect Them
  2. MITRE ATT&CK — Technique T1548: Abuse Elevation Control Mechanism
  3. MITRE ATT&CK — Technique T1068: Exploitation for Privilege Escalation
  4. ManageEngine Log360 — Detecting Abuse Elevation Control Mechanism (T1548)
  5. GrayCode — Performing Privilege Escalation on Linux
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against MITRE ATT&CK TA0004, T1548 and T1068, and 2026 Linux privilege escalation guides from Hive Security and ManageEngine.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free