bash – (Ubuntu) setuid Bash Doesn’t Work

bashsetuid

Here is the code:

(root:)

# mkdir /test
# cp /bin/bash /test/sbash
# chmod a+s /test/sbash

(user1:)

$ cd /test
$ ./sbash
$ mkdir trycreate
mkdir: cannot create directory `trycreate': Permission denied

And bash scripts with setuid bit set not work, either.

By the way, my setuid perl script works:

test.pl: (with setuid bit set, owner=root)

#!/usr/bin/perl
mkdir('/test/tryperlcreate') or die 'failed'; 

execute test.pl by user1 will create the directory owned by root.

Best Answer

Try exec ./sbash with -p.

sh:~# cp /bin/bash /bin/ape
sh:~# chmod +s /bin/ape
sh:~**$** /bin/ape -p
ape-3.2#