为防止audit在不同系统上的不同,还是介绍下环境 centos 6.3 x64

直奔主题,审计系统是什么、重要性略!

 

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.  
  4. -w /etc/inittab -p wa  
  5. -w /etc/init.d/ 
  6. -w /etc/init.d/auditd -p wa  
  7.  
  8. -w /etc/cron.d/ -p wa  
  9. -w /etc/cron.daily/ -p wa  
  10. -w /etc/cron.hourly/ -p wa  
  11. -w /etc/cron.monthly/ -p wa  
  12. -w /etc/cron.weekly/ -p wa  
  13. -w /etc/crontab -p wa 
  14.  
  15. -w /etc/group -p wa  
  16. -w /etc/passwd -p wa  
  17. -w /etc/shadow  
  18. -w /etc/sudoers -p wa 
  19.  
  20. -w /etc/hosts -p wa  
  21. -w /etc/sysconfig/ 
  22. -w /etc/sysctl.conf -p wa  
  23.  
  24. -w /etc/modprobe.d/ 
  25.  
  26. -w /etc/aliases -p wa 
  27.  
  28. -w /etc/bashrc -p wa 
  29. -w /etc/profile -p wa 
  30. -w /etc/profile.d/ 
  31. -w /var/log/lastlog 
  32. -w /var/log/yum.log 
  33.  
  34. -w /etc/issue -p wa 
  35. -w /etc/issue.net -p wa 
  36.  
  37. -w /usr/bin/ -p wa 
  38. -w /usr/sbin/ -p wa 
  39. -w /bin -p wa 
  40. -w /etc/ssh/sshd_config 

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

 

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

 

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

 

系统调用的种类见:

 

 

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

 

  1. 监视文件权限变化,因为改变权限必须调用umask 
  2. -a entry,always -S umask -S chown  
  3.  
  4. 监视主机名变化,因为修改主机名必须调用sethostname 
  5. -a entry,always -S sethostname -S setdomainname 
  6.  
  7. 监视系统时间变化 
  8. -a entry,always -S adjtimex -S settimeofday -S stime 
  9.  
  10. 设置系统日期和时间 
  11. -a entry,always -S stime 
  12.  
  13. 监控用户和组ID变化 
  14. -a entry,always -S setuid -S seteuid -S setreuid 
  15. -a entry,always -S setgid -S setegid -S setregid 
  16.  
  17. 监控挂载 
  18. -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.  
  6. # First rule - delete all 
  7. -D 
  8.  
  9. # Increase the buffers to survive stress events. 
  10. # Make this bigger for busy systems 
  11. -b 1024 
  12.  
  13. # Feel free to add below this line. See auditctl man page 
  14.  
  15. -a exit,always -F arch=b64 -S umask -S chown -S chmod 
  16. -a exit,always -F arch=b64 -S unlink -S rmdir 
  17. -a exit,always -F arch=b64 -S setrlimit 
  18.  
  19. -a exit,always -F arch=b64 -S setuid -S setreuid 
  20. -a exit,always -F arch=b64 -S setgid -S setregid 
  21.  
  22. -a exit,always -F arch=b64 -S sethostname -S setdomainname 
  23. -a exit,always -F arch=b64 -S adjtimex -S settimeofday 
  24.  
  25. -a exit,always -F arch=b64 -S mount -S _sysctl 
  26.  
  27. -w /etc/group -p wa 
  28. -w /etc/passwd -p wa 
  29. -w /etc/shadow -p wa 
  30. -w /etc/sudoers -p wa 
  31.  
  32. -w /etc/ssh/sshd_config 
  33.  
  34. -w /etc/bashrc -p wa 
  35. -w /etc/profile -p wa 
  36. -w /etc/profile.d/ 
  37. -w /etc/aliases -p wa 
  38. -w /etc/sysctl.conf -p wa  
  39.  
  40. -w /var/log/lastlog 
  41.  
  42. # Disable adding any additional rules - note that adding *new* rules will require a reboot 
  43. #-e 2 

 

读取audit报告

  1. aureport --start this-week 
  2.  
  3. aureport --user 
  4.  
  5. aureport --file 
  6.  
  7. aureport --summary 
  8.  
  9.  
  10. 详见man aureport