Skip to content
Advertisement

bash does not get root permissions with setuid program

I have the following home-grown implementation of su:

JavaScript

To allow for proper execution, the permissions and ownership information are set accordingly:

JavaScript

When I invoke a shell, such as /bin/sh, I am able to modify root-owned files and directories:

JavaScript

However, /bin/bash doesn’t seem to get root permissions:

JavaScript

Advertisement

Answer

Shells reset the euid to the uid for security reasons. So if you really want to have a rooted shell, you need to enforce uid and euid to 0. Set-uid bit only change the effective user id.

You need to set the user id to 0 for bash to be run as root:

JavaScript
Advertisement