Special permissions suid, sgid, sbit

1. SUID---->SetUID [ invalid for directories, only valid for files ]

The function of SUID?----->Let the ordinary user who has execution authority to the command temporarily have all the authority of the owner of the command when executing the command (equivalent to the owner of the command to execute the command)

Limitations of suid:

  1. The program to be executed by the executor must have x permission (executable). If there is no x, set suid to S

  2. This permission is only valid during the execution of the program (temporary)

  3. The suid permission is only valid for binary programs

  4 The executor has all the permissions of the program owner

 

Take the rm command as an example to get familiar with suid:

[root@learning test]# ls -ld /tmp/test
drwx--xr-x. 2 root test2 4096 Apr 22 04:11 /tmp/test
[root@learning test]# ll /tmp/test
total 0
-rw-r--r--. 1 root root 0 Apr 18 06:33 test1.txt
-rw-r--r--. 1 root root 0 Apr 18 06:33 test2.txt
-rw-r--r--. 1 root root 0 Apr 18 06:33 test3.txt
-rw-r--r--. 1 root root 0 Apr 18 06:33 test4.txt

 

[root@learning test]# su - oldboy
[oldboy@learning ~]$ rm -f /tmp/test/test1.txt
rm: cannot delete "/tmp/test/test1.txt": insufficient permissions

Above, user oldboy cannot delete files in test. After adding suid... he has the authority of the owner of rm (--->root), and root has the authority to delete test1.txt

[root@learning test]# chmod u+s /bin/rm
[root@learning test]# ls -ld !$
ls -ld /bin/rm
-rwsr-xr-x. 1 root root 53592 May 11  2016 /bin/rm
[root@learning test]# su - oldboy
[oldboy@learning ~]$ rm -f /tmp/test/test1.txt
[oldboy@learning ~]$ ls -l /tmp/test
Total usage 0 
-rw-r--r--. 1 root root 0 Apr   18  06:33 test2.txt
 -rw-r -- r-- . 1 root
 root 0 Apr   18 06:33 test3.txt - rw-r--r-- . 1 root root 0 Apr   18 06:33 test4.txt  

 

2. SGID--->SetGID [ valid for both files and directories ]

For files:

  1. sgid is only valid for binary files

  2. The executor must have x permission to the binary program. If there is no x, set the sgid to S.

  3. Any user who executes the program can obtain all permissions of the user group to which the command belongs during the execution of the command

as follows:

[root@learning test]# ll -d /tmp/test
drwxr-x--x. 2 root root 4096 Apr 22 22:29 /tmp/test
[root@learning ~]# su - oldboy
[oldboy@learning ~]$ ls /tmp/test
ls: cannot open directory /tmp/ test: insufficient permissions
                            |
                           |
                           V

[root@learning test]# chmod g+s /bin/ls
[root@learning test]# ll /bin/ls
-rwxr-sr-x. 1 root root 109208 May 11  2016 /bin/ls
[root@learning ~]# su - oldboy
[oldboy@learning ~]$ ls /tmp/test
test2.txt  test3.txt  test4.txt

 

For directories: After setting sgid, the files and directories created by users in this directory have the same user group settings as this directory

前:
[root@learning test]# groupadd adminuser [root@learning test]# chown .adminuser
/tmp/test [root@learning test]# ll -d /tmp/test drwxrwxrwx. 2 root adminuser 4096 Apr 23 00:25 /tmp/test [root@learning test]# touch lala [root@learning test]# ll lala -rw-r--r--. 1 root root 0 Apr 23 00:26 lala back: [root@learning test]# chmod g+s /tmp/test [root@learning test]# ll -d /tmp/test drwxrwsrwx. 2 root adminuser 4096 Apr 23 00:26 /tmp/test [root@learning test]# touch la [root@learning test]# ll /tmp/test/la -rw-r--r--. 1 root adminuser 0 Apr 23 00:27 la

Notice:  

    1. SUID has higher priority than SGID

    2. For suid and sgid, try not to use it at work, use sudo for management, and remove the useless suid bit commands in the system if possible.

 

3. Sticky bit sbit--->Sticky Bit (only valid for directory): t

Function: A directory with a sticky bit set, only the owner and root have permission to modify/delete files/directories in the directory (/tmp is a typical sticky bit directory)

Features: When the permission set by the directory to other users is rwx, everyone has the permission to write, although they manage themselves, but there are security issues, it is the first springboard for Trojans

 

*** In addition to character type settings, there are also numeric types: suid=4, sgid=2, sbit=1, such as chmod 4755 /tmp/test.txt, etc.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324642747&siteId=291194637