如果程序设置为 SUID root,则普通用户将能够以 root 身份运行该程序。您计算机上所有程序和文件的s模式中显示的位,都启用了 SUID-rwsr-xr-x或 SGID-r-xr-sr-x位已启用。因为这些程序授予执行它们的用户特殊权限,所以务必删除sroot 权限程序中那些绝对不需要这种特权的位。这可以通过执行 chmod 命令来完成a-s并将 SUID/SGID 文件的名称作为其参数。此类程序包括但不限于
您从不使用的程序。
您不希望任何非 root 用户运行的程序。
您偶尔使用,并且不介意必须 su 到 root 才能运行的程序。
我们已在我们个人可能禁用并认为对于服务器正常运行并非绝对必要的每个程序旁边放置了一个星号 *。请记住,您的系统需要一些 suid root 程序才能正常工作,因此请务必小心。根据您的需求做出选择。要查找所有带有sroot 权限程序中的位的程序,请使用以下命令
[root@deep]#find / -type f \( -perm -04000 -o -perm -02000 \) \-exec ls 'lg {} \; |
*-rwsr-xr-x 1 root root 35168 Sep 22 23:35 /usr/bin/chage *-rwsr-xr-x 1 root root 36756 Sep 22 23:35 /usr/bin/gpasswd *-r-xr-sr-x 1 root tty 6788 Sep 6 18:17 /usr/bin/wall -rwsr-xr-x 1 root root 33152 Aug 16 16:35 /usr/bin/at -rwxr-sr-x 1 root man 34656 Sep 13 20:26 /usr/bin/man -r-s--x--x 1 root root 22312 Sep 25 11:52 /usr/bin/passwd -rws--x--x 2 root root 518140 Aug 30 23:12 /usr/bin/suidperl -rws--x--x 2 root root 518140 Aug 30 23:12 /usr/bin/sperl5.00503 -rwxr-sr-x 1 root slocate 24744 Sep 20 10:29 /usr/bin/slocate *-rws--x--x 1 root root 14024 Sep 9 01:01 /usr/bin/chfn *-rws--x--x 1 root root 13768 Sep 9 01:01 /usr/bin/chsh *-rws--x--x 1 root root 5576 Sep 9 01:01 /usr/bin/newgrp *-rwxr-sr-x 1 root tty 8328 Sep 9 01:01 /usr/bin/write -rwsr-xr-x 1 root root 21816 Sep 10 16:03 /usr/bin/crontab *-rwsr-xr-x 1 root root 5896 Nov 23 21:59 /usr/sbin/usernetctl *-rwsr-xr-x 1 root bin 16488 Jul 2 10:21 /usr/sbin/traceroute -rwxr-sr-x 1 root utmp 6096 Sep 13 20:11 /usr/sbin/utempter -rwsr-xr-x 1 root root 14124 Aug 17 22:31 /bin/su *-rwsr-xr-x 1 root root 53620 Sep 13 20:26 /bin/mount *-rwsr-xr-x 1 root root 26700 Sep 13 20:26 /bin/umount *-rwsr-xr-x 1 root root 18228 Sep 10 16:04 /bin/ping *-rwxr-sr-x 1 root root 3860 Nov 23 21:59 /sbin/netreport -r-sr-xr-x 1 root root 26309 Oct 11 20:48 /sbin/pwdb_chkpwd |
要禁用上面选定程序中的 suid 位,请键入以下命令
[root@deep] /# chmod a-s /usr/bin/chage [root@deep] /# chmod a-s /usr/bin/gpasswd [root@deep] /# chmod a-s /usr/bin/wall [root@deep] /# chmod a-s /usr/bin/chfn [root@deep] /# chmod a-s /usr/bin/chsh [root@deep] /# chmod a-s /usr/bin/newgrp [root@deep] /# chmod a-s /usr/bin/write [root@deep] /# chmod a-s /usr/sbin/usernetctl [root@deep] /# chmod a-s /usr/sbin/traceroute [root@deep] /# chmod a-s /bin/mount [root@deep] /# chmod a-s /bin/umount [root@deep] /# chmod a-s /bin/ping [root@deep] /# chmod a-s /sbin/netreport |