Linux中SetUID(下)

来源:互联网 发布:网络热词2016及解释 编辑:程序博客网 时间:2024/06/05 10:51
一 取消SetUID的方法
chmod 0755 文件名
chmod u-s 文件名
 
二 危险的SetUID
1、关键目录应该严格控制写权限,比如“/”、“/usr”等
2、用户密码设置要严格遵守密码三原则
3、对系统中默认应该具有SetUID权限的文件作一列表,定时检查有没有这之外的文件被设置了SetUID权限。
 
三 查找系统中所有具有SUID和GUID的文件
[root@localhost ~]# find / -perm -4000 -o -perm -2000 > suid.log
find: ?.proc/14734/task/14734/fd/6?. No such file or directory
find: ?.proc/14734/task/14734/fdinfo/6?. No such file or directory
find: ?.proc/14734/fd/6?. No such file or directory
find: ?.proc/14734/fdinfo/6?. No such file or directory
[root@localhost ~]# cat suid.log
/run/log/journal
/run/log/journal/e6a9c2dcbddf4e08b4d1b4bff091b978
/usr/bin/wall
/usr/bin/passwd
/usr/bin/chage
/usr/bin/fusermount
/usr/bin/chfn
/usr/bin/chsh
/usr/bin/mount
/usr/bin/su
/usr/bin/umount
/usr/bin/write
/usr/bin/gpasswd
/usr/bin/newgrp
/usr/bin/pkexec
/usr/bin/crontab
/usr/bin/ssh-agent
/usr/bin/staprun
/usr/bin/Xorg
/usr/bin/locate
/usr/bin/at
/usr/bin/sudo
/usr/sbin/pam_timestamp_check
/usr/sbin/unix_chkpwd
/usr/sbin/lockdev
/usr/sbin/userhelper
/usr/sbin/netreport
/usr/sbin/usernetctl
/usr/sbin/postdrop
/usr/sbin/mount.nfs
/usr/sbin/postqueue
/usr/lib/polkit-1/polkit-agent-helper-1
/usr/lib64/dbus-1/dbus-daemon-launch-helper
/usr/lib64/vte-2.91/gnome-pty-helper
/usr/libexec/utempter/utempter
/usr/libexec/qemu-bridge-helper
/usr/libexec/openssh/ssh-keysign
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
/usr/libexec/spice-gtk-x86_64/spice-client-glib-usb-acl-helper
 
四 定时检查有没有这之外的文件被设置了SetUID权限
#!/bin/bash
find / -perm -4000 -o -perm -2000 > /tmp/setuid.check
for i in $(cat /tmp/setuid.check)
do
grep $i /root/suid.log > /dev/null
if [ "$?" != 0 ]
then
echo "$i is not in listfile!" >> /root/suid_log_$(date +%F)
fi
done
rm -rf /tmp/setuid.check
 
[root@localhost ~]# touch bcd
[root@localhost ~]# chmod u+s bcd
[root@localhost ~]# ./suid_check.sh
[root@localhost ~]# cat suid_log_2017-08-05
/root/bcd is not in listfile!