歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

檢查系統中新增加的帶有suid或者sgid位權限的程序文件

一些特殊的執行程序若被設置了set_uid位等權限,將會給系統帶來很大的風險,

通過以下方法可以很快的找出系統中,

    首先需要,在系統處於“干淨”狀態(沒有設置不當set位權限的文件)時,建立合法

suid/sgid文件列表,作為是否有新增可以suid文件的比較依據。

  1. [root@server253 ~]# find /  -type f -perm +6000 > /etc/sfilelist 
  2. [root@server253 ~]# chmod 600 /etc/sfilelist  

 然後,在編寫一個chksfile腳本文件,與sfilelist比較,輸出新增的帶suid/sgid屬性的文件

  1. [root@server253 ~]# find /  -type f -perm +6000 > /etc/sfilelist 
  2. [root@server253 ~]# chmod 600 /etc/sfilelist  
  3. #!/bin/bash 
  4. OLD_LIST=/etc/sfilelist 
  5. for i in `find / -type f -perm +6000` 
  6. do 
  7.         grep -F "$i" $OLD_LIST >/dev/null 
  8.         [ $? -ne 0 ] && ls -lh $i 
  9. done 
  10. [root@server253 ~]# chmod 700 /usr/sbin/chksfile  

其中,grep命令的“-F”選項表示在查找時將一整行內容作為字符串進行匹配;find

命令添加的“-perm +6000” 選項,表示查找設置了set-uid(權限數為4)或者set-gid(權限數為2)位的文件。

測試:

 執行chksfile腳本,檢查是否有新增suid/sgid文件。

  1. [root@server253 ~]# chmod 700 /usr/sbin/chksfile   ##腳本文件授權
  2. [root@server253 ~]# cp /bin/touch  /bin/mytouch  ##建立測試的程序文件
  3. [root@server253 ~]# chmod 4755 /bin/mytouch   ##添加suid權限
  4. [root@server253 ~]# chksfile   ##執行腳本程序,輸出測試結果
  5. -rwsr-xr-x 1 root root 39K 07-22 12:22 /bin/mytouch 
Copyright © Linux教程網 All Rights Reserved