Written by cdenley the 30 Jan 09 at 13:39.
Category: Security.
Related project:
Nothing/Others.
Status: New
Rationale
By default, a sudo timestamp is valid for 15 minutes, so any process running as your user within 15 minutes after you use sudo can easily gain root privileges, killing shells and creating new shells if necessary to use the same TTY as the sudo timestamp.
It doesn't matter how soon the timestamp is killed. If timestamps can be used at all, they can be used by a malicious process immediately after sudo is run.
If the shell uses the same TTY, it does not require a password. A malicious process can easily create a shell to match the TTY you use for sudo after killing the shell you used to run it. I have proof-of-concept code if you want more details.
Without cdenley's code in hand you can still confirm this happens - ssh to an ubuntu system then do something via sudo. (obviously the user must be permitted) Check your TTY ('w' for instance) then exit the ssh session. Now ssh to the system again as the same user and check TTY again - probably the same, and if so try sudo again and it will not ask for password if you're within 15 minutes of providing the password in the previous ssh session. It only cares that the userID and TTY are the same, it seems.
Various measures can ameliorate this, but the end effect is that if timestamps are used at all, it is possible to hijack the timestamp by killing off the shell that just authenticated to sudo and then gaining its TTY by spawning shells.
It doesn't matter if the timestamp is killed one minute after you use sudo or when you log out. A malicious process can wait for you to run sudo, then re-use the timestamp immediately.