This is a suggestion for a bash security hardening patch which
prevents xtrace from being initialized to the SHELLOPTS environment
variable when a new shell starts.
xtrace can be used to exploit bogus system()/popen() calls on setuid
binaries via a specially crafted PS4 environment variable leading to
privilege escalation, like so:
This means, that setuid programs which call system(3)/popen(3) (a
horrendously bad practice in any case) are vulnerable, since it's safe
to assume that most of these do not ignore such environment variables.
CVE-2005-2959 reported by Tavis Ormandy would be an example against sudo
from bash-4.2.53/shell.c:
1722 /* Initialize the shell options. Don't import the shell options
1723 from the environment variables $SHELLOPTS or $BASHOPTS if we are
1724 running in privileged or restricted mode or if the shell
is running
1725 setuid. */
1726 #if defined (RESTRICTED_SHELL)
+ /* xtrace can be used to exploit bogus system()/popen() calls
on setuid binaries
+ via a specially crafted PS4 environment variable leading to
privilege escalation. */
+ if(!strcmp(vname, "xtrace"))
+ break;
set_minus_o_option (FLAG_ON, vname);
free (vname);
}
After compilation:
# rm /bin/bash
# cp bash-4.2.53/bash /bin/bash
# ls -l /bin/sh
lrwxrwxrwx. 1 root root 9 Oct 4 18:18 /bin/sh -> /bin/bash
# exit
$ env -i SHELLOPTS=xtrace PS4='$(id)' ./test
Thu Dec 10 18:30:41 WET 2015
Thanks,
Federico Bento.
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.