I created a simple script on Ubuntu Server 18.04:
#!/bin/bash
apt update
apt upgrade
then I changed the owner to root
# chown root update.sh
then I added SUID bit and execution bits for user and group
# chmod u+xs,g+x update.sh
and this is what I have:
-rwsrwxr-- 1 root me 35 Mar 21 09:48 update.sh*
So I was expecting that by running this script which I have permission to run (it belongs to my group), it gets the root UID and it will execute as root, but I get permission denied.
./
in the answer rather than an absolute path but it's really secondary. Then it's easy to follow the dupe of the dupe – A.B Mar 22 '20 at 23:03/bin/sh
is actually bash, the caller can execute any code by exporting a function with the same name as some command from the script (eg.echo(){ reboot; }; export -f echo; ./run_the_wrapper
. – Mar 23 '20 at 03:53