Skip to content

Artifact Analysis: Sudo Rights & Privilege Escalation (sudoers)

1. Artifact Locations (The Configuration Puzzle)

Section titled “1. Artifact Locations (The Configuration Puzzle)”

The sudo configuration is rarely confined to a single file. System administrators and automated provisioning tools (like Ansible or Terraform) heavily utilize modular drop-in directories.

Assuming the compromised forensic image is mounted at /mnt/analysis/, analysts must inspect two primary locations:

  1. The Main Configuration File: /mnt/analysis/etc/sudoers
  2. The Drop-in Directory: /mnt/analysis/etc/sudoers.d/

The sudoers syntax dictates exactly what actions are permitted. It follows a strict paradigm: WHO WHERE=(AS_WHO) WHAT

To hunt for malicious modifications, analysts must understand how to read these rules:

  • The “Open Bar” Rule (Dangerous): nico ALL=(ALL:ALL) ALL

    • Who: user nico
    • Where: on all hosts (ALL)
    • As Who: as any user or any group (ALL:ALL)
    • What: can run any command (ALL).
  • The “NOPASSWD” Directive (The Attacker’s Dream): www-data ALL=(ALL) NOPASSWD: ALL

    • This rule allows the www-data web service account to become root without ever typing a password. If threat actors deploy a webshell on a server with this configuration, they immediately achieve root dominance without needing a secondary exploit.

3. The GTFOBins Trap (Subtle Privilege Escalation)

Section titled “3. The GTFOBins Trap (Subtle Privilege Escalation)”

Administrators often attempt to apply the Principle of Least Privilege by restricting a user to a single, specific administrative command. However, this often creates a severe vulnerability.

  • The Intent: backup ALL=(root) /usr/bin/find (The backup user is only allowed to use the find command to locate files).
  • The Flaw: Many native Unix binaries possess interactive features or the ability to spawn subshells. The find command, for instance, has an -exec flag.
  • The Attack: sudo find . -exec /bin/sh \;

By executing this command, the attacker instantly bypasses the restriction and spawns an interactive root shell.

This concept is known as GTFOBins (Get The F*** Out Binaries). Hundreds of legitimate binaries (vim, less, awk, tar, python, nmap) can be abused in this manner. If you observe a highly specific binary authorized in the sudoers file, cross-reference it with the GTFOBins repository to determine if it allows shell escapes.

When conducting offline analysis, you must examine the files’ metadata before analyzing their content.

  1. MAC Times Analysis: Check the modification time (mtime) of /etc/sudoers and all files within /etc/sudoers.d/. A recent modification timestamp that aligns with the suspected intrusion window is definitive proof of an LPE or persistence attempt.
  2. File Permissions: By design, sudoers files must be read-only (0440 or -r--r-----). If a file within /etc/sudoers.d/ possesses writable permissions (0640 or higher), it is a severe anomaly indicating tampering or gross misconfiguration.
audit_sudoers_offline.sh
#!/bin/bash
TARGET_DIR="/mnt/analysis"
echo "[+] Auditing main sudoers file for NOPASSWD..."
grep -E -i "nopasswd" $TARGET_DIR/etc/sudoers | grep -v "^#"
echo "[+] Auditing sudoers.d drop-in directory..."
grep -rE -i "nopasswd" $TARGET_DIR/etc/sudoers.d/ | grep -v "^#"
echo "[+] Checking for dangerous file permissions (Should be 440)..."
stat -c "%a %n" $TARGET_DIR/etc/sudoers $TARGET_DIR/etc/sudoers.d/* | grep -v "440"

If you identify a malicious rule, pivot immediately to the Linux Authentication Logs (auth.log or secure). Query the logs for COMMAND= to identify exactly when the attacker utilized their newly minted sudo privileges and which post-exploitation commands they executed. Furthermore, review the Account Analysis to check if the attacker added themselves directly to the sudo or wheel groups in /etc/group.