Given that it is a frequent requirement to allow unprivileged users restricted access to privileged functions: Jobbing sysadmins sometimes provide this in the form of shellscripts, which are then invoked via a setuid
wrapper, like so:
int main()
{
setuid( 0 );
system( "/path/to/script.sh" );
return 0;
}
(The evidence for this assertion can be found by searching for setuid script not working on your favourite search engine, or on stack overflow. No, they shouldn't be doing this, but they are. When security advice is too hard, or too obscure, for sysadmins to follow, another solution is needed.)
Note that this may not merely be ignorance. Who would expect that a script containing only this would be dangerous?
#!/bin/bash
kill -HUP $(< /var/run/demonname.pid)
Obviously the intent is to ask demonname to re-read his configuration file. It calls nothing but bash built-ins (so shouldn't use the path), and doesn't consult the environment once. In my opinion, even an experienced sysadmin could be forgiven for thinking that a suidwrapper was OK in this case.
As previously discovered, Shellshock, and (even without it) the Function Import from Environment (FIE) feature of bash, pose privilege escalation vulnerabilities.
Assuming that:
- such things exist in your installation, and you don't know they do, and
- you can reliably assume new ones will be created...
Would it be advisable to:
- dump bash and use something else forever and ever amen?
- patch bash to rip out FIE altogether (the "nuke from orbit" option)?
- patch bash to whitelist the full paths of scripts which are allowed to use this feature?
- patch
system
andpopen
to clear the environment by default if running as root? (People shouldn't be using these functions). - Mail the admin every time someone calls
system
as root? Or starts a shellscript as root? - or what?
In other words, is FIE used in production for anything other than exploiting systems? If so can we whitelist those uses and forbid it everywhere else? If not can't we just rip the feature out?