Skip to content
Advertisement

Why does SetSUID not work for shell script?

I am trying to create a executor program for regular users on linux with SUID bit set so whatever commands, passed to the program as parameters, get executed with root permission. However when I try to implement this as a bash script, this does not work, where it works when implemented in C. I want to know what I am doing wrong for the shell script. The codes are below

Shell Script:

JavaScript

Execution:

JavaScript

C Program:

JavaScript

Execution:

JavaScript

Both files have identical permissions

JavaScript

Advertisement

Answer

It is documented in execve(2) :

Linux ignores the set-user-ID and set-group-ID bits on scripts.

IIRC, setuid scripts would be a significant security hole

See this question

You could configure sudo to avoid asking a password – see sudoers(5) (or use super)

You could also write a simple C program wrapping your shell script, and make it setuid.

Advertisement