2.9 KiB
T1206 - Sudo Caching
Description from ATT&CK
Thesudocommand "allows a system administrator to delegate authority to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while providing an audit trail of the commands and their arguments." (Citation: sudo man page 2018) Since sudo was made for the system administrator, it has some useful configuration features such as atimestamp_timeoutthat is the amount of time in minutes between instances ofsudobefore it will re-prompt for a password. This is becausesudohas the ability to cache credentials for a period of time. Sudo creates (or touches) a file at/var/db/sudowith a timestamp of when sudo was last run to determine this timeout. Additionally, there is atty_ticketsvariable that treats each new tty (terminal session) in isolation. This means that, for example, the sudo timeout of one tty will not affect another tty (you will have to type the password again).Adversaries can abuse poor configurations of this to escalate privileges without needing the user's password.
/var/db/sudo's timestamp can be monitored to see if it falls within thetimestamp_timeoutrange. If it does, then malware can execute sudo commands without needing to supply the user's password. Whentty_ticketsis disabled, adversaries can do this from any tty for that user.The OSX Proton Malware has disabled
tty_ticketsto potentially make scripting easier by issuingecho 'Defaults !tty_tickets' >> /etc/sudoers(Citation: cybereason osx proton). In order for this change to be reflected, the Proton malware also must issuekillall Terminal. As of macOS Sierra, the sudoers file hastty_ticketsenabled by default.
Atomic Tests
Atomic Test #1 - Unlimited sudo cache timeout
Sets sudo caching timestamp_timeout to a value for unlimited. This is dangerous to modify without using 'visudo', do not do this on a production system.
Supported Platforms: macOS, Linux
Run it with sh!
sudo sed -i 's/env_reset.*$/env_reset,timestamp_timeout=-1/' /etc/sudoers
sudo visudo -c -f /etc/sudoers
Atomic Test #2 - Disable tty_tickets for sudo caching
Sets sudo caching tty_tickets value to disabled. This is dangerous to modify without using 'visudo', do not do this on a production system.
Supported Platforms: macOS, Linux
Run it with sh!
sudo sh -c "echo Defaults "'!'"tty_tickets >> /etc/sudoers"
sudo visudo -c -f /etc/sudoers