Skip to main content

Overview

After a user runs sudo and enters their password, a token is cached (default 5 minutes). If you have access to that user’s session, you can reuse the token without knowing the password.

Requirements

  • User is in sudo group
  • User has recently used sudo (token not expired)
  • You have code execution as that user
  • ptrace_scope allows process injection OR /proc/sys/kernel/yama/ptrace_scope = 0

Check ptrace_scope

Check Token Existence


sudo_inject

exploit.sh — Process Injection

Injects into a process owned by target user to activate sudo token:
Creates /tmp/sh — SUID shell:

exploit_v2.sh — No ptrace Required

Uses /proc/pid/mem instead of ptrace:

exploit_v3.sh — Via Shared Library

Loads shared library into user process:

Manual Token Abuse

Write sudo_inject Token

If you can write to /var/run/sudo/ts/<username>:
If writable, create a valid token entry. The token format is binary — use write_sudo_token:

Timestamp Directory Permissions

Default: /var/run/sudo/ts/ owned by root with 0700. If misconfigured (writable):

Sudo Timestamp Timeout

Check timeout:
Default: 5 minutes. Any value < 0 (e.g. -1) = never expires (always exploitable if token exists).

Sudo Hijacking (PATH)

Create fake sudo in writable PATH directory:
Next time user types sudo — either reuses token or captures password.

Persistent via .bashrc


Quick Reference