AlphaMack
February 3rd, 2007, 02:44 PM
A sample exercise in getting your sudo hijacked via ~/.bash_profile and /Users/Shared is documented here (although the code has been cleaned up):
http://rixstep.com/2/20070201,00.shtml
I tried this on a fully patched 10.4.8 system (build 8L127) and was able to get a fake sudo embedded in /Users/Shared and my ~/.bash_profile altered to include the malevolent $PATH.
My method of poisoning my system involved saving the script as an .app, setting the executable bits (chmod a+x), executing it from the Terminal (since the Finder tried to launch Classic), and opened a new terminal window with the now poisoned path to sudo.
To demonstrate that sudo was indeed poisoned, I tried to run something like "sudo ls." I was prompted for my password, which was rejected (maybe a typo? hmmm) and was asked to enter it again. Game over. The script harvested the password and saved it to /Users/Shared/.keylog while at the same time destroying the fake sudo, leaving only the altered ~/.bash_profile behind along with the .keylog.
This is very dangerous, especially if this script can be wrapped inside Cocoa apps.
Knowing that /Users/Shared is wide-open, the question is: Can this be done in Ubuntu, or any Linux distro, or any UNIX system? If so, how can one best protect their box from such interlopers (besides the advice given in the article re: full paths)?
Note:
The sample script provided by Rixstep assumes the following:
- The default setup has not been changed
- You're running as an admin (by default in OS X)
- Your default shell for Terminal.app is /bin/bash
- /Users/Shared is world-writeable
http://rixstep.com/2/20070201,00.shtml
I tried this on a fully patched 10.4.8 system (build 8L127) and was able to get a fake sudo embedded in /Users/Shared and my ~/.bash_profile altered to include the malevolent $PATH.
My method of poisoning my system involved saving the script as an .app, setting the executable bits (chmod a+x), executing it from the Terminal (since the Finder tried to launch Classic), and opened a new terminal window with the now poisoned path to sudo.
To demonstrate that sudo was indeed poisoned, I tried to run something like "sudo ls." I was prompted for my password, which was rejected (maybe a typo? hmmm) and was asked to enter it again. Game over. The script harvested the password and saved it to /Users/Shared/.keylog while at the same time destroying the fake sudo, leaving only the altered ~/.bash_profile behind along with the .keylog.
This is very dangerous, especially if this script can be wrapped inside Cocoa apps.
Knowing that /Users/Shared is wide-open, the question is: Can this be done in Ubuntu, or any Linux distro, or any UNIX system? If so, how can one best protect their box from such interlopers (besides the advice given in the article re: full paths)?
Note:
The sample script provided by Rixstep assumes the following:
- The default setup has not been changed
- You're running as an admin (by default in OS X)
- Your default shell for Terminal.app is /bin/bash
- /Users/Shared is world-writeable