(C) special permission linux system permissions SUID, SGID

A, SUID
1.1 Basics
SUID binary executable file against in terms of his ultimate goal is for all users in the implementation of the SUID binary executable file, the binary file permissions have permission of the owner. (To break the security context of the law).
Case understand

[root@tysonscloud ~]# ls -l /bin/passwd 
-rwsr-xr-x. 1 root root 27832 Jun 10  2014 /bin/passwd
[root@tysonscloud ~]# ls -l /etc/shadow
---------- 1 root root 948 Jan 29 15:25 /etc/shadow

Users use the passwd command to change your password is / etc / shadow file for this operation, but ordinary users this file without any permission. According to the former theory is no way to modify the password. The effect is to SUID allows ordinary users after performing this procedure passwd, passwd process rights generated by the process owner (root) instead of the initiator (a normal user) the same, so that ordinary users can / etc / passwd the program modifies the password.

1.2 security context of the law

Before starting the program: whether the user can initiate a binary executable file for the process, depending on whether the user has rights to the x binary executable file.
Program starts: the process has permission to permission of the originator, which is the owner of the process is the owner of the initiator.
1.3 Enable SUID process after the owner
prior to commencement: whether the user can initiate a binary executable file for the process, depending on whether the user has rights to the x binary executable file.
After the program starts: the process has permissions for binary executable files belong to the Lord's authority, which is the owner of the process is the owner of binary files.

1.4 Case 2
in the root user environment will be a binary executable file / bin / cat tyson copied to the user's home directory corresponding to the folder, you can see that at this time there is no set of SUID. (Note: SUID only in the case of the main display of permissions).

[root@Tyson Lee learnSuid]# cp /bin/cat  /home/tyson/learnSuid/
[root@Tyson Lee learnSuid]# ll
total 56
-rwxr-xr-x. 1 root root 54080 Jan 14 01:29 cat

Switch to tyson user, in the case of the test is not set SUID permissions:
Once you have a cat file execute permissions cat tyson user starts the process, the process has the permissions are tyson user permissions.
That has only user rights tyson cat is unable to operate (other permissions of the file is -) to / etc / shadow file.

[root@Tyson Lee learnSuid]# su - tyson
Last login: Mon Jan 14 01:27:53 CST 2019 on pts/0
[tyson@Tyson Lee ~]$ cd learnSuid/
[tyson@Tyson Lee learnSuid]$ ls -al
total 60
drwxr-xr-x.  2 root  root     17 Jan 14 01:29 .
drwx------. 10 tyson tyson  4096 Jan 14 01:29 ..
-rwxr-xr-x.  1 root  root  54080 Jan 14 01:29 cat
[tyson@Tyson Lee learnSuid]$ ~/learnSuid/cat /etc/shadow
/home/tyson/learnSuid/cat: /etc/shadow: Permission denied
[tyson@Tyson Lee ~]$ ls -l /etc/shadow
----------. 1 root root 881 Jan 10 12:17 /etc/shadow

Two, SGID
2.1 basics
generate demand SGID is: root user needs to set a particular folder, so that when other ordinary users to create files in the folder, is a set of files that are created are of the group directory (which by default belong to the group is the creator of the file is a group).
SGID may act on files and directories:
act on the file: Similar to SUID, after the user binary executable files is enabled to process, is a set of processes that belong to the group of binary executable file, permissions process is a binary executable file is a set of permissions.
Acting on the directory: belong to the same group is a group of files and directories of any user-created in the directory.

Guess you like

Origin blog.csdn.net/weixin_43803070/article/details/94758653