SUID/SGID binary exploitation

Understanding SUID/SGID Binaries

What Makes SUID/SGID Dangerous

SUID (Set User ID) and SGID (Set Group ID) binaries are programs that execute with the privileges of their owner or group, rather than the user who runs them. This mechanism allows regular users to perform administrative tasks through trusted programs, but misconfigurations or vulnerable binaries create direct privilege escalation paths.

The Attack Principle: Find SUID/SGID binaries that either:

  • Have built-in functionality to spawn shells or execute commands

  • Can be abused to read/write files as the binary owner

  • Have vulnerabilities that allow arbitrary code execution

  • Can be exploited through command injection or path manipulation

Why This Works: When a SUID binary runs, it inherits the privileges of the file owner (usually root), giving attackers a direct escalation path if the binary can be manipulated to execute arbitrary commands.

SUID/SGID Binary Discovery

Finding Elevated Binaries

Basic SUID/SGID Discovery:

# Find all SUID binaries
find / -type f -perm -4000 2>/dev/null

# Find all SGID binaries  
find / -type f -perm -2000 2>/dev/null

# Find both SUID and SGID binaries
find / -type f \( -perm -4000 -o -perm -2000 \) 2>/dev/null

# More detailed search with file information
find / -type f \( -perm -4000 -o -perm -2000 \) -exec ls -la {} \; 2>/dev/null

Advanced Discovery Techniques:

Quick Common Location Check:

GTFOBins Integration

Understanding GTFOBins

GTFOBins (https://gtfobins.github.io/) is the definitive resource for exploiting UNIX binaries for privilege escalation. When you find a SUID binary, immediately check GTFOBins for exploitation techniques.

GTFOBins Categories for SUID Exploitation:

  • SUID: Direct privilege escalation through SUID binaries

  • Shell: Binaries that can spawn interactive shells

  • Command: Binaries that can execute arbitrary commands

  • File Read: Binaries that can read files as the owner

  • File Write: Binaries that can write files as the owner

Common GTFOBins SUID Exploits

Text Editors and Pagers:

vim/vi (if SUID):

nano (if SUID):

less/more (if SUID):

Programming Languages and Interpreters:

python (if SUID):

perl (if SUID):

ruby (if SUID):

Network and System Tools:

tcpdump (if SUID):

wget (if SUID):

File Management Tools:

cp (if SUID):

tar (if SUID):

find (if SUID):

Advanced SUID Exploitation Techniques

Binary Analysis and Vulnerability Research

Checking Binary Properties:

Identifying Custom SUID Binaries:

Environment Variable Exploitation

PATH Manipulation for SUID Binaries:

Library Path Exploitation:

Race Condition Exploitation

TOCTOU (Time of Check Time of Use) Attacks:

Specific Binary Exploitation Examples

Real-World SUID Binary Exploits

systemctl (if SUID - rare but possible):

docker (if SUID - very dangerous):

env (if SUID):

awk (if SUID):

File Read/Write Exploitation

Reading Sensitive Files via SUID Binaries:

Writing Files via SUID Binaries:

SGID Binary Exploitation

Understanding SGID Group Privileges

Common Dangerous SGID Groups:

  • shadow: Can read /etc/shadow file

  • disk: Can read raw disk devices

  • video: Can access framebuffer devices

  • audio: Can access audio devices

  • docker: Can control Docker daemon

SGID Binary Discovery:

Exploiting SGID shadow Group:

Key Operational Considerations

Success Indicators

  • SUID binary executes with elevated privileges

  • Effective UID changes to binary owner (check with id)

  • File access to previously restricted files

  • Command execution with elevated privileges

Common Failure Points

  • No SUID binaries present or all are standard system binaries

  • Binaries are hardened against command injection

  • Restricted environments prevent execution of found binaries

  • Modern protections (grsecurity, AppArmor) prevent exploitation

Cleanup Considerations

  • Remove created files in /tmp or other writable directories

  • Reset PATH variable if modified

  • Clear command history if shell access was gained

  • Remove temporary scripts used for exploitation

SUID/SGID binary exploitation remains one of the most reliable Linux privilege escalation methods, with GTFOBins providing a comprehensive reference for exploiting nearly any SUID binary encountered in real-world environments.

Last updated

Was this helpful?