Linux系统中有大量的日志文件可以用于查看应用程序的各种信息,但是对于用户的操作行为(如某用户修改删除了某文件)却无法通过这些日志文件来查看,如果想实现监管企业员工的操作行为就需要开启审计功能,也就是audit。
1 auditd服务相关命令(root 用户执行)启动 service auditd start (stop为停止)
[root@localhost rules.d]# service auditd start重启service auditd restart
[root@localhost rules.d]# service auditd restartStopping logging: [ 确定 ]Redirecting start to /bin/systemctl start auditd.service已配置规则查看 auditctl -l
[root@localhost rules.d]# auditctl -l-w /home/cw74/tess.txt -p w -k mytesschange清空定义的规则 auditctl -D
2 相关文件规则配置文件/etc/audit/rules.d/audit.rules,文件内容一般如下(二次安防检查缺少规则配置就是在这里配置):
## First rule - delete all-D## Increase the buffers to survive stress events.## Make this bigger for busy systems-b 8192## Set failure mode to syslog-f 1## 自己增加的规则-w /home/cw74/tess.txt -p w -k mytesschange日志记录文件/var/log/audit/audit.log,可以使用ausearch或者tail -f /var/log/audit/audit.log查看,例:
[root@localhost cw74]# ausearch -k mytesschange----time->Thu Apr 1 15:14:51 2023type=CONFIG_CHANGE msg=audit(1617261291.703:1190): auid=1000 ses=9 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 op=add_rule key="mytesschange" list=4 res=1----time->Thu Apr 1 15:15:23 2023type=PROCTITLE msg=audit(1617261323.322:1192): proctitle=76696D00746573732E747874type=PATH msg=audit(1617261323.322:1192): item=3 name="tess.txt~" inode=295491 dev=fd:02 mode=0100664 ouid=1000 ogid=1000 rdev=00:00 obj=unconfined_u:object_r:user_home_t:s0 objtype=CREATEtype=PATH msg=audit(1617261323.322:1192): item=2 name="tess.txt" inode=295491 dev=fd:02 mode=0100664 ouid=1000 ogid=1000 rdev=00:00 obj=unconfined_u:object_r:user_home_t:s0 objtype=DELETEtype=PATH msg=audit(1617261323.322:1192): item=1 name="/home/cw74" inode=67 dev=fd:02 mode=040700 ouid=1000 ogid=1000 rdev=00:00 obj=unconfined_u:object_r:user_home_dir_t:s0 objtype=PARENTtype=PATH msg=audit(1617261323.322:1192): item=0 name="/home/cw74" inode=67 dev=fd:02 mode=040700 ouid=1000 ogid=1000 rdev=00:00 obj=unconfined_u:object_r:user_home_dir_t:s0 objtype=PARENTtype=CWD msg=audit(1617261323.322:1192): cwd="/home/cw74"type=SYSCALL msg=audit(1617261323.322:1192): arch=c000003e syscall=82 success=yes exit=0 a0=194e390 a1=1b49630 a2=fffffffffffffe90 a3=7ffdd2deecf0 items=4 ppid=66658 pid=66818 auid=1000 uid=1000 gid=1000 euid=1000 suid=1000 fsuid=1000 egid=1000 sgid=1000 fsgid=1000 tty=pts1 ses=9 comm="vim" exe="/usr/bin/vim" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key="mytesschange"---- 3 审计规则默认情况下auditd会读取所审计的内容配置文件,该配置文件在/etc/audit/目录下,配置文件名为audit.rules,在该文件中详细描述了,要对一个操作系统可以做哪些审计,应该怎么做审计等内容。如下表所示为Linux系统常用审计配置,具体详细的微调还需具体到各业务系统需要。
规则格式:-w 路径 -p 权限 -k 关键字
-w 文件或文件夹路径
-p 文件或文件夹权限,动作分为四种
r 读取文件
w 写入文件
x 执行文件
a 修改文件属性
注:如果没有-p选项,则默认监视所有动作rwxa
-k 审计日志里的记录关键字,查看日志的时候可以使用,例:ausearch -k mytesschange,mytesschange即为关键字
示例,监控/etc/passwd文件的修改行为(写,权限修改) -w /etc/passwd -p wa将上述内容加入到audit.rules中即可实现对该文件的监视。
推荐的配置规则(供参考,具体监控系统如OPEN3000、NS3000等,可监视系统的配置文件的修改) Linux、Unix 系统审计重点位置-w /var/log/audit/ -k LOG_audit-w /etc/audit/ -p wa -k CFG_audit-w /etc/sysconfig/auditd -p wa -k CFG_auditd.conf-w /etc/libaudit.conf -p wa -k CFG_libaudit.conf-w /etc/audisp/ -p wa -k CFG_audisp-a entry,always -F arch=b32 -S setxattr -S lsetxattr -S fsetxattr -S removexattr -S lremovexattr -S fremovexattr-a entry,always -F arch=b32 -S mknod -S mknodat-a entry,always -F arch=b32 -S mount -S umount -S umount2-w /etc/cups/ -p wa -k CFG_cups-w /etc/init.d/cups -p wa -k CFG_initd_cups-w /etc/netlabel.rules -p wa -k CFG_netlabel.rules-w /etc/racoon/racoon.conf -p wa -k CFG_racoon.conf-w /etc/racoon/psk.txt -p wa -k CFG_racoon_keys-w /etc/racoon/certs/ -p wa -k CFG_racoon_certs-w /etc/selinux/config -p wa -k CFG_selinux_config-w /etc/selinux/mls/ -p wa -k CFG_MAC_policy-w /usr/share/selinux/mls/ -p wa -k CFG_MAC_policy-w /etc/selinux/semanage.conf -p wa -k CFG_MAC_policy-a entry,always -F arch=b32 -S adjtimex -S settimeofday -S clock_settime-w /usr/sbin/stunnel -p x-w /etc/security/rbac-self-test.conf -p wa -k CFG_RBAC_self_test-w /etc/aide.conf -p wa -k CFG_aide.conf-w /etc/cron.allow -p wa -k CFG_cron.allow-w /etc/cron.deny -p wa -k CFG_cron.deny-w /etc/cron.d/ -p wa -k CFG_cron.d-w /etc/cron.daily/ -p wa -k CFG_cron.daily-w /etc/cron.hourly/ -p wa -k CFG_cron.hourly-w /etc/cron.monthly/ -p wa -k CFG_cron.monthly-w /etc/cron.weekly/ -p wa -k CFG_cron.weekly-w /etc/crontab -p wa -k CFG_crontab-w /var/spool/cron/root -k CFG_crontab_root-w /etc/group -p wa -k CFG_group-w /etc/passwd -p wa -k CFG_passwd-w /etc/gshadow -k CFG_gshadow-w /etc/shadow -k CFG_shadow-w /etc/security/opasswd -k CFG_opasswd-w /etc/login.defs -p wa -k CFG_login.defs-w /etc/securetty -p wa -k CFG_securetty-w /var/log/faillog -p wa -k LOG_faillog-w /var/log/lastlog -p wa -k LOG_lastlog-w /var/log/tallylog -p wa -k LOG_tallylog-w /etc/hosts -p wa -k CFG_hosts-w /etc/sysconfig/network-scripts/ -p wa -k CFG_network-w /etc/inittab -p wa -k CFG_inittab-w /etc/rc.d/init.d/ -p wa -k CFG_initscripts-w /etc/ld.so.conf -p wa -k CFG_ld.so.conf-w /etc/localtime -p wa -k CFG_localtime-w /etc/sysctl.conf -p wa -k CFG_sysctl.conf-w /etc/modprobe.conf -p wa -k CFG_modprobe.conf-w /etc/pam.d/ -p wa -k CFG_pam-w /etc/security/limits.conf -p wa -k CFG_pam-w /etc/security/pam_env.conf -p wa -k CFG_pam-w /etc/security/namespace.conf -p wa -k CFG_pam-w /etc/security/namespace.init -p wa -k CFG_pam-w /etc/aliases -p wa -k CFG_aliases-w /etc/postfix/ -p wa -k CFG_postfix-w /etc/ssh/sshd_config -k CFG_sshd_config-w /etc/stunnel/stunnel.conf -k CFG_stunnel.conf-w /etc/stunnel/stunnel.pem -k CFG_stunnel.pem-w /etc/vsftpd.ftpusers -k CFG_vsftpd.ftpusers-a exit,always -F arch=b32 -S sethostname-w /etc/issue -p wa -k CFG_issue-w /etc/issue.net -p wa -k CFG_issue.net自己应用系统本身中文件的监视,如下:
-w /home/xxxx/sys -k XXXX_sys参照规则要求配置即可。
4 设置开机自启 # 查看开机自启的状态 disabled 为非开机自启;enabled 为开机自启[root@localhost cw74]# systemctl list-unit-files | grep auditauditd.service disabled[root@localhost cw74]# chkconfig auditd on注意:正在将请求转发到“systemctl enable auditd.service”。Created symlink from /etc/systemd/system/multi-user.target.wants/auditd.service to /usr/lib/systemd/system/auditd.service.[root@localhost cw74]# systemctl list-unit-files | grep auditauditd.service enabled