Safeguard
Application Security•

Sudo Caching and Sudoers Abuse: Detection and Hardening (T1548.003)

Sudo remembers your password for a while and the sudoers file can skip it entirely. MITRE T1548.003 explained, with the settings that close the gap and signals to log.

Safeguard Security Team
3 min read

Sudo lets an administrator delegate the ability to run commands as root or another user, with an audit trail. MITRE tracks the abuse of its convenience features as T1548.003, Sudo and Sudo Caching, a privilege escalation technique on Linux and macOS.

How attackers use it

Two pieces of sudo configuration matter.

The first is credential caching. The timestamp_timeout setting is the number of minutes between sudo runs before it asks for a password again. Sudo creates or touches a file under /var/db/sudo to record when it last ran. MITRE explains that malware can watch that timestamp, and if it falls inside the timeout, run sudo commands without supplying a password.

The second is tty_tickets, which treats each terminal session separately. If it is disabled, the same trick works from any tty belonging to that user. MITRE notes that in the wild, malware has disabled it by appending Defaults !tty_tickets to the sudoers file, then restarting Terminal for the change to take effect. As of macOS Sierra, tty_tickets is enabled by default.

The sudoers file, /etc/sudoers, can also state when not to prompt, with a line such as user1 ALL=(ALL) NOPASSWD: ALL. Editing it needs elevated privileges, so a NOPASSWD line is usually a sign that something already went wrong, or a convenience that outlived its need.

How to detect it

MITRE's detection strategy has two parts.

  • Correlate sudo command executions with an effective user ID of 0, especially when tty_tickets is disabled or the timestamp timeout is being used.
  • Detect NOPASSWD entries in /etc/sudoers or the disabling of tty_tickets, followed right away by privileged commands.

File integrity monitoring on /etc/sudoers and /etc/sudoers.d gives you the edit itself.

How to reduce the risk

MITRE lists three mitigations.

  • Operating System Configuration: keep tty_tickets enabled so the cache does not leak across sessions.
  • Privileged Account Management: require a password, so terminal access alone is not enough. Setting timestamp_timeout to 0 requires the password on every sudo.
  • Restrict File and Directory Permissions: edit sudoers strictly so passwords are always required and users cannot start risky processes as more privileged users.

Check your own environment

Read-only commands for Linux or macOS.

sudo -l
sudo grep -rn "NOPASSWD" /etc/sudoers /etc/sudoers.d
sudo grep -rn "tty_tickets\|timestamp_timeout" /etc/sudoers /etc/sudoers.d
  • Which accounts have NOPASSWD, and is each one still needed?
  • Is tty_tickets ever negated?
  • Is the timeout set to something you chose on purpose?

Quick check

What does setting timestamp_timeout to 0 do?

Sudo asks for the password every time it runs, so there is no cached window to abuse.

Sources

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.