After using sudo and entering a password to do so, sudo remembers that we have entered a password and we do not have to enter a password the next time we use it.

I am concerned about the possibility of using this fact to trick a user (admin/sudoer) to execute a script that contains a sudo command, so that the script can use administrator privileges.

A test using a directory and ls

I figured I could probably show that a script would ask for a password so that this trick could not work. I did the following test.

I created a directory testDir owned by root and using chmod I deleted all the access priviliges of both the group (g) and others (o). I used sudo to do so, so from now on assume we are in the "remember that the user does not need to enter a password to use sudo" state.

In testDir I created a testFile using sudo (after this we don't need to enter a password to use sudo anymore).

Because I am not root, ls testDir now tells me that permission is denied.

However, echo sudo ls testDir| bash prints testFile to the terminal.

The behavior appears to be the same if instead of piping "sudo ls testDir" to bash, we execute a shell script containing the line sudo ls testDir.

Questions: Should you use caution when executing programs when you have just used sudo?

  • 1
    I think it really depends on what script you are talking about. If one has sudo access, I don't think one would execute a script without knowing what it does, especially when normally it would require sudo access. – ryekayo Apr 23 '15 at 15:02
  • @ryekayo yeah, for simple script that seems reasonable. But I do not see how things are any different for larger applications that are not so easy to oversee. For example I might download some application that I do not completely trust, thinking it would not be too bad if the application can potentially use the privileges of that specific user. But if I then accidentally start it up from a terminal where "sudo is active", then it can suddenly do anything. I guess this is surprising to me, hence my effort to disprove that this was the design. – Matheor Apr 23 '15 at 15:10
  • i understand where you are coming from. You should look into this O'Reilly book that can go into the specifics of Linux Security.. It's called Linux Security Cookbook.. – ryekayo Apr 23 '15 at 15:13
  • 6
    If it concerns you, you can always revoke the password manually, and/or change the timestamp_timeout parameter – steeldriver Apr 23 '15 at 15:15
  • @ryekayo thank you for that reference, that sounds interesting. I would prefer to have a good "intermediate level unix book" where the author warns me of cases like though. I feel this is something everybody who uses sudo should know about. I will start using the -k option a lot I think. – Matheor Apr 23 '15 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.