Linux SUID Privilege Escalation: Complete Guide with Examples

Linux SUID Privilege Escalation: Complete Guide with Examples

Picture this: You’re a locksmith trying to break into a vault. You could spend hours cracking the combination, drilling through steel, or bypassing security systems. Or… you could just check if someone accidentally left a spare key under the doormat. That spare key? In the Linux world, it’s called a misconfigured SUID binary, and it’s shockingly common.

Uploading: 192390 of 192390 bytes uploaded.

Here’s the wild part: Getting root access — the holy grail of system control — can sometimes be as simple as running two commands. No fancy exploits, no complex code injection, no waiting for zero-day vulnerabilities. Just a misconfigured binary sitting right there, waiting to be discovered. It’s like finding out the bank vault’s back door was left wide open because someone checked the wrong permission box during setup.

Why Should You Care?

Whether you’re a penetration tester, security enthusiast, system administrator, or just curious about Linux security, understanding SUID privilege escalation is absolutely critical.

Here’s what you gain:

  • Find privilege escalation in minutes instead of hours of complex exploitation
  • Understand common security misconfigurations that attackers check first
  • Learn practical commands for CTF challenges and penetration tests
  • Protect your systems by knowing what to look for
  • Save time during assessments by checking low-hanging fruit first

The reality? Privilege escalation can be tedious, frustrating work — searching for that tiny misconfiguration in an entire system. But SUID binaries? They’re often the easiest win and yet one of the most commonly overlooked security issues.

What Are SUID Binaries?

In Linux, every file has permissions controlling who can read, write, or execute it. But there’s a special permission called SUID (Set User ID), and it’s basically a superpower for programs.

Here’s the key: When a program has the SUID bit set, it runs with the permissions of the file owner, not the person executing it.

Think of it like this: You work at a company where only the CEO can approve expense reports. Normally, you’d need to find the CEO every time. But what if the CEO gave you a special stamp that says “Approved by CEO,” and you could use it anytime? That stamp is the SUID bit — temporary CEO powers for a specific task.

A legitimate example: The passwd command lets you change your password, which requires modifying /etc/shadow—a file only root can edit. But you're not root! The passwd binary has SUID root, so it temporarily gets root privileges to modify that protected file.

ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 68208 May 28 2024 /usr/bin/passwd

See that s in -rwsr-xr-x? That's the SUID bit!

When SUID Goes Wrong

SUID is perfectly safe when used correctly. The problem happens when powerful binaries that shouldn’t have SUID… do. If a binary with SUID root can spawn a shell or execute commands, you’ve just given anyone on the system a fast-pass to root access.

Finding Misconfigured SUID Binaries

You’ve gained access to a Linux system (legally, in a CTF or authorized pentest), but you’re just a low-privileged user. Now what?

Step 1: Find all SUID binaries

find / -perm -4000 2> /dev/null

Breaking it down:

  • find / - Search from the root directory (entire filesystem)
  • -perm -4000 - Look for files with the SUID bit (4000 in octal)
  • 2> /dev/null - Hide "Permission denied" errors by sending them to the void

What you’ll see:

/usr/bin/sudo
/usr/bin/passwd
/usr/bin/vim.basic # ← This shouldn't be here!
/usr/bin/mount

Most are normal binaries that need SUID to function. But sometimes you’ll spot something suspicious — a text editor, programming language interpreter, or utility with no business running as root.

In our example: We found /usr/bin/vim.basic. Vim is a text editor, and if it has SUID root, we can abuse it to get a root shell. Why? Because vim can execute system commands and spawn shells. When vim runs with root privileges, any shell it spawns will also be root.

GTFOBins: Your Exploitation Cookbook

Found a suspicious SUID binary? Now you need GTFOBins — a curated list of Unix binaries that can bypass security restrictions.

Visit: https://gtfobins.github.io/

Think of GTFOBins as your exploitation cookbook. It shows exactly how to abuse specific binaries to escalate privileges, spawn shells, or bypass restricted environments.

How to use it:

  1. Go to https://gtfobins.github.io/
  2. Search for your binary (e.g., “vim”)
  3. Look for the “SUID” section
  4. Copy and adapt the command

For vim with SUID:

/usr/bin/vim.basic -c ':py3 import os; os.setuid(0); os.execl("/bin/bash", "/bin/bash")'

Understanding the command:

  • /usr/bin/vim.basic - Runs vim with SUID root privileges
  • -c - Execute a command immediately on vim startup
  • :py3 import os; - Vim has built-in Python support; we import the OS module
  • os.setuid(0); - Set our user ID to 0 (root's user ID)
  • os.execl("/bin/bash", "/bin/bash") - Replace the current process with a bash shell

What happens: Vim starts with root privileges, executes our Python code that maintains those root privileges, then launches bash. Since bash inherits vim’s permissions, we get a root shell.

Verify you’re root:

whoami

Output: root

Congratulations! You just escalated from a regular user to root in two simple commands. No kernel exploits, no brute forcing, no complex payloads — just a misconfigured binary.

Why This Works (And Why It’s Scary)

The administrator probably thought, “I’ll just give vim SUID so users can edit system files easily.” What they didn’t realize is that vim isn’t just a text editor — it’s a Swiss Army knife that can:

  • Execute shell commands with :!command
  • Run Python/Perl/Ruby scripts internally
  • Read and write any file on the system
  • Spawn interactive shells

Giving vim SUID root is like giving someone a key to the vault and saying “only use it to look at the money, don’t take any.” The key doesn’t enforce restrictions — the person holding it does.

Your First Step in Privilege Escalation

Here’s pro advice: Always check SUID binaries first during privilege escalation. Why?

  1. Quick to check — One command lists them all
  2. High success rate — Misconfigurations are common
  3. Easy to exploit — GTFOBins gives you ready-made commands
  4. No complexity — No need for kernel exploits or custom code

Think of it as the “low-hanging fruit” of privilege escalation. Why climb the tree when the apples are on the ground?

Practice Makes Perfect: Try It Yourself

Want hands-on experience? Head to OffSec’s Proving Grounds and try the Shakabrah lab:

Lab URL: https://portal.offsec.com/machine/shakabrah-369/overview

This lab specifically features SUID misconfiguration vulnerabilities, making it perfect for practicing what you’ve learned. You’ll get real experience finding misconfigured binaries, using GTFOBins, and escalating privileges in a safe, legal environment.

The learning path:

  1. Gain initial access to the system
  2. Run your SUID discovery command
  3. Identify suspicious binaries
  4. Consult GTFOBins for exploitation methods
  5. Execute your privilege escalation
  6. Capture the root flag!

It’s one thing to read about privilege escalation; it’s another to actually do it. The Shakabrah lab lets you experience that “aha!” moment when you see root@shakabrah in your terminal.

Wrapping Up: The Easiest Root You’ll Ever Get

Obtaining root privileges can be a tedious process involving extensive research into system configurations, kernel versions, and obscure vulnerabilities. But sometimes — more often than you’d think — it’s as simple as finding a binary with the wrong permissions and running a single command from GTFOBins.

Key takeaways:

  • SUID binaries run with the file owner’s permissions, not yours
  • Misconfigured SUID binaries are common privilege escalation vectors
  • The find / -perm -4000 2> /dev/null command finds them all
  • GTFOBins is your go-to resource for exploitation techniques
  • Always check SUID binaries first — it’s the fastest win
  • Practice on legal platforms like OffSec’s Shakabrah lab

For defenders: Audit your SUID binaries regularly. Ask yourself: “Does this binary really need root privileges to function?” If not, remove the SUID bit. It’s that simple.

For pentesters: Make SUID enumeration your first move after gaining initial access. You’d be surprised how often this “basic” check leads straight to root.

Remember: In cybersecurity, the most dangerous vulnerabilities aren’t always the most complex. Sometimes it’s just someone leaving the keys under the mat.


TLDR Cheat Sheet

Find SUID Binaries:

find / -perm -4000 2> /dev/null

What to look for:

  • Text editors: vim, nano, emacs
  • Programming languages: python, perl, ruby, php
  • File utilities: find, cp, mv
  • Anything unusual that shouldn’t have root privileges

Exploitation steps:

  1. Find suspicious SUID binary
  2. Search it on GTFOBins (https://gtfobins.github.io/)
  3. Use the SUID exploitation method
  4. Get root shell
  5. Run whoami to verify

Example (vim):

/usr/bin/vim.basic -c ':py3 import os; os.setuid(0); os.execl("/bin/bash", "/bin/bash")'

Practice lab: OffSec Shakabrah — https://portal.offsec.com/machine/shakabrah-369/overview

Pro tip: Always check SUID binaries first during privilege escalation — it’s the fastest, easiest win. 

Post a Comment

Previous Post Next Post