為防止audit在不同系統上的不同,還是介紹下環境 centos 6.3 x64
直奔主題,審計系統是什麼、重要性略!
audit是linux核心的特性,可以通過核心參數audit=1來啟用。
/etc/audit/audit.rules是audit的規則檔案,本文主要講述如何利用audit來監視系統重要資源。
一、監控檔案系統行為(依靠檔案、目錄的權限屬性來識别)
規則格式:-w 路徑 -p 權限 -k 關鍵字
其中權限動作分為四種
r 讀取檔案
w 寫入檔案
x 執行檔案
a 修改檔案屬性
示例,監控/etc/passwd檔案的修改行為(寫,權限修改)
-w /etc/passwd -p wa
将上述内容加入到audit.rules中即可實作對該檔案的監視。
同理,為了維護系統正常,下列資源也應該被監視。
-w /etc/at.allow
-w /etc/at.deny
-w /etc/inittab -p wa
-w /etc/init.d/
-w /etc/init.d/auditd -p wa
-w /etc/cron.d/ -p wa
-w /etc/cron.daily/ -p wa
-w /etc/cron.hourly/ -p wa
-w /etc/cron.monthly/ -p wa
-w /etc/cron.weekly/ -p wa
-w /etc/crontab -p wa
-w /etc/group -p wa
-w /etc/passwd -p wa
-w /etc/shadow
-w /etc/sudoers -p wa
-w /etc/hosts -p wa
-w /etc/sysconfig/
-w /etc/sysctl.conf -p wa
-w /etc/modprobe.d/
-w /etc/aliases -p wa
-w /etc/bashrc -p wa
-w /etc/profile -p wa
-w /etc/profile.d/
-w /var/log/lastlog
-w /var/log/yum.log
-w /etc/issue -p wa
-w /etc/issue.net -p wa
-w /usr/bin/ -p wa
-w /usr/sbin/ -p wa
-w /bin -p wa
-w /etc/ssh/sshd_config
注:如果沒有-p選項,則預設監視所有動作rwxa
二、監控系統調用行為(依靠系統調用來識别)
規則:-a 一系列動作 -S 系統調用名稱 -F 字段=值 -k 關鍵字
<b></b>
<b>系統調用的種類見:</b>
<b> </b>
列舉常見應該被監視的系統調用
監視檔案權限變化,因為改變權限必須調用umask
-a entry,always -S umask -S chown
監視主機名變化,因為修改主機名必須調用sethostname
-a entry,always -S sethostname -S setdomainname
監視系統時間變化
-a entry,always -S adjtimex -S settimeofday -S stime
設定系統日期和時間
-a entry,always -S stime
監控使用者群組ID變化
-a entry,always -S setuid -S seteuid -S setreuid
-a entry,always -S setgid -S setegid -S setregid
監控挂載
-a entry,always -S mount -S umount
注:請查閱系統調用清單後決定監控那種行為,系統調用是底層的、全局性的,監控不合适的調用,會給系統帶來巨大負擔。
audit.rules 樣本
# This file contains the auditctl rules that are loaded
# whenever the audit daemon is started via the initscripts.
# The rules are simply the parameters that would be passed
# to auditctl.
# First rule - delete all
-D
# Increase the buffers to survive stress events.
# Make this bigger for busy systems
-b 1024
# Feel free to add below this line. See auditctl man page
-a exit,always -F arch=b64 -S umask -S chown -S chmod
-a exit,always -F arch=b64 -S unlink -S rmdir
-a exit,always -F arch=b64 -S setrlimit
-a exit,always -F arch=b64 -S setuid -S setreuid
-a exit,always -F arch=b64 -S setgid -S setregid
-a exit,always -F arch=b64 -S sethostname -S setdomainname
-a exit,always -F arch=b64 -S adjtimex -S settimeofday
-a exit,always -F arch=b64 -S mount -S _sysctl
-w /etc/group -p wa
-w /etc/shadow -p wa
# Disable adding any additional rules - note that adding *new* rules will require a reboot
#-e 2
讀取audit報告
aureport --start this-week
aureport --user
aureport --file
aureport --summary
詳見man aureport
本文轉自 紫色葡萄 51CTO部落格,原文連結:http://blog.51cto.com/purplegrape/1010148,如需轉載請自行聯系原作者