(Ubuntu) setuid bash doesn't work
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.
Try exec ./sbash with -p.
sh:~# cp /bin/bash /bin/ape
sh:~# chmod +s /bin/ape
sh:~**$** /bin/ape -p
ape-3.2#
You cannot make scripts SUID. Fortunately.
You may be interested in the SUID-wrapper program here, though: http://isptools.sourceforge.net/suid-wrap.html
I should also add, please please please make sure that you really need to do this before you do it. SUID binaries can be a great big gaping hole in your system.
I could repost what's been done to death already, but this is a great read.
Basically setuid shell scripts don't work by default
http://www.faqs.org/faqs/unix-faq/faq/part4/section-7.html