This document contains the process for recreating SETUID and SETGID permission bits.
The information in this document applies to AIX Version 3 and 4.
************************************************************ SECURITY RISK WARNING: Current UNIX(r) security manuals warn SUID/SGID shell scripts are a major security risk and are to be avoided. This document reintroduces a POTENTIAL SECURITY RISK to your system! ************************************************************
A fix for a potential security risk dealing with the use of the SETUID and SETGID permission bits on shell scripts was included in AIX 3.1.7 (which corresponds to update level 2007). Prior to 3.1.7, when a shell script was executed whose permissions included the SETUID bit (set user-id), the shell script ran with the permissions of the shell script's owner. Similarly, if the SETGID bit (set group-id) was set, the shell script ran with the permissions of the shell script's group. Beginning with AIX 3.1.7, the SETUID and SETGID permission bits is no longer supported for shell scripts. This change does NOT affect compiled programs.
Here is an example.
#!/bin/ksh id
chown root shell.sh chmod 4755 shell.sh
Prior to AIX 3.1.7, if an ordinary user named 'joeuser' ran shell.sh, the output would be:
uid=200(joeuser) gid=200(staff) euid=0(root)
The 'euid=0(root)' indicates that the user was 'effectively' root while the shell script executed.
For AIX 3.1.7 and later, the output is:
uid=200(joeuser) gid=200(staff)
The SETUID bit no longer has any meaning for shell scripts.
If your application requires the previous SETUID behavior, you can call the shell script from a small compiled program that has the SETUID bit set in its permissions.
main(int argc, char *argv[]) { execvp("/path/shell.sh", argv); /* execute the shell script */ exit(1); }
cc -o execsh execsh.c
chown root execsh chmod 4755 execsh
The SETUID behavior has not changed for compiled programs, so execsh will 'effectively' become root when it is executed, and will pass these credentials to shell.sh.
To have a non-root user execute a program with root permissions, use the following:
Put the following text in the file you just created.
main () { setuid(0); setgid(0); system("/bin/mksysb -i /dev/rmt0"); }
cc umksysb.c -o umksysb
chmod 4755 umksysb
ACL (access control lists) can be used to specify particular users that can access these files. This can be used with other commands as well.
Another example of a non-root user executing a program with root permissions is shown in the following steps.
myshutdown.c
Put the following text in the file myshutdown.c:
main() { setuid(0); setgid(0); system("/usr/sbin/shutdown -Fr"); }
cc myshutdown.c -o myshutdown
chmod 4755 myshutdown
NOTE: Making a program suid root only assigns uid 0 to the program. Additional code may be required to acquire root's environment using the setpcred and setpenv subroutines.