CTF Arsenal
Boot2Root/Linux Privilege Escalation

Sudo Misconfigurations

Concept

sudo -l shows what commands the current user may run as another user (often root), sometimes without a password. If any allowed command can be abused to spawn a shell, read files, or write files (per GTFOBins), that's a direct path to root.

When to Use

  • Always run sudo -l right after SUID enumeration — it's equally high-yield and low-cost.

Workflow

  1. 1
    List sudo permissions

    sudo -l (may prompt for current user's own password).

  2. 2
    Check each allowed binary on GTFOBins

    Specifically its 'sudo' section.

  3. 3
    Watch for wildcard/path issues

    e.g. sudo allows a script path you can edit.

  4. 4
    Execute the escalation

    Spawn a root shell via the allowed command.

Commands

sudo -l
sudo -l

Lists the commands the current user is permitted to run via sudo, and under which conditions.

When to use: Always, immediately after gaining any shell.

Expected output:

User ctf may run the following commands on target:
    (ALL) NOPASSWD: /usr/bin/vim

Look for: NOPASSWD entries, and whether the allowed path includes a wildcard or is interpretable (scripting language, editor, pager).

Next step: Look up the exact binary on GTFOBins under 'Sudo'.

sudo BINARY -c 'COMMAND'
sudo vim -c ':!/bin/sh'

GTFOBins example: vim run via sudo can shell out, inheriting root privileges.

When to use: When sudo -l shows vim (or another interactive program with a shell-escape feature) as NOPASSWD-allowed.

Expected output:

# (root shell)

Look for: Successful shell spawn with uid=0.

Next step: Confirm with id and proceed.

sudo -u ROOT_OR_OTHER_USER COMMAND
sudo -u#0 /bin/bash

If sudoers allows running as a specific UID via (ALL) or a wildcard user spec, this runs a command directly as that UID.

  • -u#0 — Run as UID 0 (root) by numeric ID, useful if username matching is restricted but UID isn't.

When to use: When sudoers entries use user wildcards or numeric UID patterns.

Expected output:

# (root shell)

Look for: Successful privilege change.

Next step: Confirm and continue.

Tools

GTFOBins

Lookup table of sudo-abuse techniques per binary.

When to use: For every binary sudo -l allows.

Search the binary name, read its 'Sudo' section specifically (different from the SUID section).

Example workflow: sudo -l shows /usr/bin/less -> GTFOBins: sudo less /etc/profile then !/bin/sh inside the pager.

Findings & Interpretation

Interesting

  • Any NOPASSWD entry
  • A sudo-allowed script you have write access to (edit it to run anything as root)

Suspicious

  • Wildcards in the sudoers command path (e.g. /usr/bin/* or a path with * for arguments) — often exploitable via argument injection

False Positives

  • sudo -l requiring a password you don't have is not automatically a dead end — if you have the user's password from elsewhere, this still applies

How to Validate

  • Actually run the GTFOBins technique rather than assuming the binary name alone guarantees success — version/compile flags can differ

Next Step

  • If the allowed command is a custom script, read and look for ways to influence its behavior (writable, calls other writable binaries, uses a manipulable PATH).

Troubleshooting

sudo -l prompts for a password you don't have.

Likely cause: sudoers requires authentication for this user, unlike NOPASSWD entries.

Verify: Check /etc/sudoers or /etc/sudoers.d (if readable) directly for NOPASSWD lines matching your user.

Fix: Try any password you've recovered from other enumeration (configs, cracked hashes) — sudo -l will then reveal the full rule set.

Recovery: Fall back to SUID/cron/capabilities enumeration if no password is available.

Avoid repeating: Don't assume a password prompt means sudo is a dead end — it only means NOPASSWD isn't set for every rule.