linux audit审计服务audit.rules策略参数

audit是linux内核的特性,可以通过内核参数audit=1来启用。


/etc/audit/audit.rules是audit的规则文件,本文主要讲述如何利用audit来监视系统重要资源。


一、监控文件系统行为(依靠文件、目录的权限属性来识别)

规则格式:-w 路径 -p 权限 -k 关键字

其中权限动作分为四种


r  读取文件

w 写入文件

x 执行文件

a 修改文件属性



示例,监控/etc/passwd文件的修改行为(写,权限修改)



  1. -w /etc/passwd -p wa


将上述内容加入到audit.rules中即可实现对该文件的监视。

同理,为了维护系统正常,下列资源也应该被监视。



  1. -w /etc/at.allow  

  2. -w /etc/at.deny  

  3. -w /etc/inittab -p wa  

  4. -w /etc/init.d/

  5. -w /etc/init.d/auditd -p wa  

  6. -w /etc/cron.d/ -p wa  

  7. -w /etc/cron.daily/ -p wa  

  8. -w /etc/cron.hourly/ -p wa  

  9. -w /etc/cron.monthly/ -p wa  

  10. -w /etc/cron.weekly/ -p wa  

  11. -w /etc/crontab -p wa

  12. -w /etc/group -p wa  

  13. -w /etc/passwd -p wa  

  14. -w /etc/shadow  

  15. -w /etc/sudoers -p wa

  16. -w /etc/hosts -p wa  

  17. -w /etc/sysconfig/

  18. -w /etc/sysctl.conf -p wa  

  19. -w /etc/modprobe.d/

  20. -w /etc/aliases -p wa

  21. -w /etc/bashrc -p wa

  22. -w /etc/profile -p wa

  23. -w /etc/profile.d/

  24. -w /var/log/lastlog

  25. -w /var/log/yum.log

  26. -w /etc/issue -p wa

  27. -w /etc/issue.net -p wa

  28. -w /usr/bin/ -p wa

  29. -w /usr/sbin/ -p wa

  30. -w /bin -p wa

  31. -w /etc/ssh/sshd_config

注:如果没有-p选项,则默认监视所有动作rwxa


二、监控系统调用行为(依靠系统调用来识别)

规则:-a 一系列动作 -S 系统调用名称 -F 字段=值 -k 关键字


系统调用的种类见:

http://www.ibm.com/developerworks/cn/linux/kernel/syscall/part1/appendix.html



列举常见应该被监视的系统调用


-a exit,always
-F 规则字段

none 不记
exit:行为完成后记录审计(一般常用)
entry:行为刚开始时记录审计(某些规则要求)
  1. 监视文件权限变化,因为改变权限必须调用umask

  2. -a entry,always -S umask -S chown                            #-a后面的规则:always总是记录审计;none不记录;exit行为完成后记录审计;entry行为刚刚开始                                                                                         时记录审计

  3. 监视主机名变化,因为修改主机名必须调用sethostname

  4. -a entry,always -S sethostname -S setdomainname

  5. 监视系统时间变化

  6. -a entry,always -S adjtimex -S settimeofday -S stime

  7. 设置系统日期和时间

  8. -a entry,always -S stime

  9. 监控用户和组ID变化

  10. -a entry,always -S setuid -S seteuid -S setreuid

  11. -a entry,always -S setgid -S setegid -S setregid

  12. 监控挂载

  13. -a entry,always -S mount -S umount


注:请查阅系统调用列表后决定监控那种行为,系统调用是底层的、全局性的,监控不合适的调用,会给系统带来巨大负担。


audit.rules 样本



  1. # This file contains the auditctl rules that are loaded

  2. # whenever the audit daemon is started via the initscripts.

  3. # The rules are simply the parameters that would be passed

  4. # to auditctl.

  5. # First rule - delete all

  6. -D

  7. # Increase the buffers to survive stress events.

  8. # Make this bigger for busy systems

  9. -b 1024

  10. # Feel free to add below this line. See auditctl man page

  11. -a exit,always -F arch=b64 -S umask -S chown -S chmod

  12. -a exit,always -F arch=b64 -S unlink -S rmdir

  13. -a exit,always -F arch=b64 -S setrlimit

  14. -a exit,always -F arch=b64 -S setuid -S setreuid

  15. -a exit,always -F arch=b64 -S setgid -S setregid

  16. -a exit,always -F arch=b64 -S sethostname -S setdomainname

  17. -a exit,always -F arch=b64 -S adjtimex -S settimeofday

  18. -a exit,always -F arch=b64 -S mount -S _sysctl

  19. -w /etc/group -p wa

  20. -w /etc/passwd -p wa

  21. -w /etc/shadow -p wa

  22. -w /etc/sudoers -p wa

  23. -w /etc/ssh/sshd_config

  24. -w /etc/bashrc -p wa

  25. -w /etc/profile -p wa

  26. -w /etc/profile.d/

  27. -w /etc/aliases -p wa

  28. -w /etc/sysctl.conf -p wa  

  29. -w /var/log/lastlog

  30. # Disable adding any additional rules - note that adding *new* rules will require a reboot

  31. #-e 2


读取audit报告


  1. aureport --start this-week

  2. aureport --user

  3. aureport --file

  4. aureport --summary


审计日志时间转换脚本

time.pl:
s/(1\d{9})/localtime($1)/e
echo 1234567890|perl -p time.pl


转自:http://purplegrape.blog.51cto.com/1330104/1010148

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章