SUID SGID

SUID 

  1.只作用在可执行二进制文件上,普通用户需要对该文件有x权限,

  2.在执行该文件时,用户身份切换为文件owner;

  3.执行完毕,切换回普通用户。

一、查找具有SUID权限的系统文件(-4000 表示至少有SUID权限)

[zheng@localhost ~]$ sudo find / -perm -4000  2>/dev/null 
/usr/bin/chfn
/usr/bin/chage
/usr/bin/gpasswd
/usr/bin/newgrp
/usr/bin/chsh
/usr/bin/sudo
/usr/bin/mount
/usr/bin/su
/usr/bin/umount
/usr/bin/crontab
/usr/bin/pkexec
/usr/bin/passwd
/usr/sbin/pam_timestamp_check
/usr/sbin/unix_chkpwd
/usr/sbin/usernetctl
/usr/lib/polkit-1/polkit-agent-helper-1
/usr/lib64/dbus-1/dbus-daemon-launch-helper

二、比较系统SUID文件变化

1.将系统现有的SUID文件存入 /root/suid.list

2.创建比较脚本

#!/bin/bash

find / -perm -4000 -o -perm -2000 > /tmp/setuid.check 2>/dev/null

cat /dev/null >/root/suid_log_$(date +%F)

for i in $( cat /tmp/setuid.check )

do
        grep $i /root/suid.list > /dev/null
        if [ $? -ne 0 ] ;
                then
                echo "$i don't exist in listfile!" | tee -a  /root/suid_log_$(date +%F)
        fi

done

 SGID

即可作用在文件的所属组,也可作用在目录的所属组。

root 创建一个具有SGID权限的文件夹;普通用户进去,创建一个文件,查看文件所属组

[root@localhost tmp]# mkdir gDIR
[root@localhost tmp]# chmod g+s gDIR
[root@localhost tmp]# ll -d gDIR
drwxr-sr-x. 2 root root 6 Jun 17 00:39 gDIR
[root@localhost tmp]# chmod 777 gDIR
[root@localhost tmp]# exit
exit
[zheng@localhost ~]$ cd /tmp/gDIR
[zheng@localhost gDIR]$ touch a.file
[zheng@localhost gDIR]$ ll
total 0
-rw-rw-r--. 1 zheng root 0 Jun 17 00:42 a.file

原文地址:https://www.cnblogs.com/zhengwenqiang/p/7039911.html