You've found sudo permissions - now let's exploit them. This lesson covers comprehensive exploitation techniques for various sudo configurations, from simple shell escapes to advanced bypass methods.Related
Each binary that sudo allows has potential escape vectors. Some are obvious (vim → :!bash), others are creative (apache2 → config include). GTFOBins is your reference, but understanding WHY these work helps you find new ones.
Categories of Exploitation
Sudo exploitation falls into categories: shell escapes, file read/write, command execution, and environment abuse. Know which category each binary falls into.
Shell Escape Binaries
Text Editors
Pagers
System Utilities
-p Flag for Shells
When spawning bash from sudo context, use bash -p if you get a non-root shell. The -p preserves effective UID. Usually not needed with sudo but good habit.
Language Interpreters
File Read/Write Binaries
Reading Sensitive Files
Writing Files (Overwrite passwd)
Network Tool Exploitation
Package Manager Exploitation
Service-Related Binaries
Compression Tools
Wildcard Abuse
Wildcard Injection
When sudo paths contain wildcards (*), check if you can create files that become malicious arguments. This is especially powerful with tar, rsync, and find.
Environment Variable Exploitation
Sudo Exploitation Methodology
Advanced Sudo Attack Flow
1
ParseUnderstand exact sudo -l output
2
GTFOBinsCheck each binary for known escapes
3
CategoryIdentify: shell escape, file r/w, command exec
4
WildcardsCheck for path traversal or argument injection
5
EnvironmentCheck for env_keep or SETENV
6
ChainCombine techniques if single doesn't work
Knowledge Check
Challenges
Key Takeaways
- Most binaries have shell escape vectors - check GTFOBins
- Pagers (less, more) allow !command for shell access
- Editors (vim, nano) have built-in shell execution
- Wildcards in sudo paths enable argument injection
- tar --checkpoint-action is a common exploitation vector
- Even read-only binaries can read /etc/shadow