Course contentsShow
← Security
Lesson 2141 of 3,05242. Penetration Testing and Red TeamingFree lesson

SUID/SGID Binary Exploitation

Finding and exploiting SUID/SGID binaries with misconfigurations or vulnerabilities to escalate privileges.

SUID/SGID Binary Exploitation

What you'll learn: How to find and exploit misconfigured SUID/SGID binaries to gain elevated privileges on Linux systems.

The Core Concept

In Linux, certain executables can be marked with special permissions (SUID/SGID) that allow them to run with the permissions of the file owner (often root) rather than the user executing them. This is like a valet key for your car—it gives temporary, specific elevated access for a particular purpose.

When a binary with the SUID bit set is executed, it runs as the owner of that file. If that owner is root and the binary has vulnerabilities or misconfigurations, an attacker can leverage this to escalate privileges.

Finding SUID/SGID Binaries

Search for these special binaries system-wide:

find / -perm -4000 -type f 2>/dev/null  # SUID binaries
find / -perm -2000 -type f 2>/dev/null  # SGID binaries

Common Exploitation Vectors

Misconfigured custom scripts: A SUID shell script or binary that calls other programs without absolute paths—you can manipulate PATH to inject malicious executables.

Vulnerable legitimate binaries: Tools like old versions of nmap, vim, or find with SUID set can escape to a shell with elevated privileges.

File operations with predictable behavior: Binaries that read/write files as root can be tricked into modifying sensitive files like /etc/passwd or /etc/shadow.

Example Pattern

If you find a SUID binary that uses relative paths:

# Binary calls 'ls' without /bin/ls
export PATH=/tmp:$PATH
echo '/bin/bash' > /tmp/ls
chmod +x /tmp/ls
./vulnerable_suid_binary  # Now spawns root shell

Key Takeaway: SUID/SGID binaries are powerful privilege escalation vectors—always enumerate them during post-exploitation, and look for misconfigurations, vulnerable versions, or insecure operations that can be abused to gain root access.