Contents
What is a SUID shell?
SUID, Set User-ID, is one of the most beautiful concepts in UNIX. The above example shows a simple shell script which writes the username and date-time to a log file and echoes a confirmation statement .
How do I find my SUID?
Use the following procedure to find files with setuid permissions.
- Become superuser or assume an equivalent role.
- Find files with setuid permissions by using the find command. # find directory -user root -perm -4000 -exec ls -ldb {} \; >/tmp/ filename.
- Display the results in /tmp/ filename . # more /tmp/ filename.
How do I enable SUID?
Configuring SUID on your required files/script is a single CHMOD command away. Replace “/path/to/file/or/executable”, in the above command, with the absolute path of the script that you need SUID bit on. This can be achieved by using the numerical method of chmod as well. The first “4” in “4755” indicates SUID.
Why does calling setuid on an executable not work?
If a user does not have permissions to do a certain action (like kill the process of another user), then calling setuid on the program you want to kill (or on kill itself) will have no effect because the user does not have permission to another users ‘space’ without super user rights.
What to do if Linux setuid doesn’t work?
Without calling setuid () or setreuid (), the script will still run as the user who invoked the script. Avoid system and exec as they drop privileges for security reason. You can use kill () to kill the processes. Check These out. You should replace your system call with exec call.
What to do if the script doesn’t run in the UID?
The script still needs to call setuid () or setreuid () to run in the the real uid or effective uid respectively. Without calling setuid () or setreuid (), the script will still run as the user who invoked the script. Avoid system and exec as they drop privileges for security reason. You can use kill () to kill the processes. Check These out.
When to use the nosuid attribute in Linux?
Most filesystems designed for Unix/Linux can be mounted with a nosuid attribute, which will prevent setuid or setgid binaries located on those filesystems from altering the effective uid or gid of a process. It’s often used when mounting “untrusted” filesystems, those that are under the control of a non-administrator.