赞
踩
Auditd是Linux审计系统的用户空间组件。Auditd是Linux审计守护进程的缩写。在Linux中,daemon被称为后台运行服务,当它在后台运行时,应用程序服务的末尾附加了一个“d”。auditd的工作是作为后台服务收集审计日志文件并将其写入磁盘。
审计系统由两个主要部分组成:用户空间应用程序和实用程序,以及内核端系统调用处理。内核组件接收来自用户空间应用程序的系统调用,并通过以下过滤器之一对其进行过滤:user、task、fstype或exit。
一旦系统调用通过了exclude过滤器,它就会通过前面提到的过滤器之一发送事件消息。该过滤器根据审核规则配置将其发送到审核守护进程进行进一步处理。
用户空间审计守护进程从内核收集信息,并在日志文件中创建条目。用户可以通过用户空间的审计实用程序与审计守护程序、内核审计组件或审计日志文件交互:
这个Linux服务为用户提供了一个Linux环境的安全审计解决方案。auditd收集和保存的日志是用户在Linux环境中执行的不同活动,如果有任何用户想询问其他用户在公司或多用户环境中做了什么,该用户可以以简化和最小化的形式访问此类信息,也就是安全审计日志。此外,如果用户的系统出现异常活动,比如说他的系统被破坏了,那么用户可以追踪并查看其系统是如何被破坏的,这在许多情况下也有助于事件响应。
常见使用场景有:
注意,审核规则不是越多越好,当audit需要收集大量的事件消息时,就会对系统性能产生一些负面的影响。
debian-based Linux distributions:
sudo apt-get install auditd audispd-plugins
service auditd start
centos:
yum install audit
systemctl start auditd
systemctl enable auditd
service auditd restart
用户可以使用ausearch和aureport实用程序搜索auditd保存的日志。审计规则位于/etc/audit/audit.rules中。使用auditctl可以读取,也可以修改这些规则。/etc/audit/auditd.conf文件中是auditd的服务参数配置。
auditctl:配置审核规则
aureport:生成审计报告
ausearch:查询审计日志
autrace:进程审计,参考下面的方法。
# auditctl -D
No rules
# autrace /bin/ls /tmp
Waiting to execute: /bin/ls
hsperfdata_bjxtb systemd-private-5e979fd32cfa4f68a1caf461c8af9796-chronyd.service-ZWAp4d zabbix
Cleaning up...
Trace complete. You can locate the records with 'ausearch -i -p 18037'
# ausearch -i -p 18037
使用aureport查看当天的统计数据:
# aureport --start today --event --summary -i Event Summary Report ====================== total type ====================== 25505 SYSCALL 1003 USER_ACCT 1002 CRED_ACQ 995 LOGIN 976 USER_START 960 CRED_REFR 959 CRED_DISP 959 USER_END 199 CONFIG_CHANGE 14 USER_AUTH
audit审核规则包括以下3类:
设置审核规则的方式:
auditctl -w /etc/passwd -p wa -k user-modify
做个测试,查看审计日志效果:
sudo useradd testuser
cat /var/log/audit/audit.log | grep user-modify
ausearch -i -k user-modify
auditctl -w /bin/rm -p x -k removefile #-w指定所要监控的文件或命令
#-p指定监控属性,如x执行、w修改
#-k是设置一个关键词用于查询
auditctl -a exit,always -F arch=b64 -S clock_settime -k changetime
auditctl -a always,exit -F exe=/bin/id -F arch=b64 -S execve -k execution_bin_id
auditctl -a exit,always -F arch=x86_64 -S open -F auid=80
# pwd
/usr/share/doc/audit-2.8.5/rules
# ls
10-base-config.rules 12-cont-fail.rules 21-no32bit.rules 30-nispom.rules 30-stig.rules 40-local.rules 43-module-load.rules 99-finalize.rules
10-no-audit.rules 12-ignore-error.rules 22-ignore-chrony.rules 30-ospp-v42.rules 31-privileged.rules 41-containers.rules 70-einval.rules README-rules
11-loginuid.rules 20-dont-audit.rules 23-ignore-filesystems.rules 30-pci-dss-v31.rules 32-power-abuse.rules 42-injection.rules 71-networking.rules
auditctl -s
auditctl -l
审计日志的还会输出到/var/log/message文件中,如果需要禁止输出到/var/log/message文件,可以修改rsyslog.conf配置项并重启即可:
*.info;mail.none;authpriv.none;cron.none.local2.none /var/log/messages
在audit.log文件中保存的时间格式是自1970年以来的秒数,可以用下面方法转成容易理解的日期时间:
date --date=@1648198201
auditctl -l #查看定义的规则
auditctl -D #清空定义的规则
将审核规则写入到配置文件中,以持续生效:/etc/audit/rules.d/audit.rules
-a always,exclude -F msgtype=USER_START
-a always,exclude -F msgtype=CRED_REFR
-a always,exclude -F msgtype=CRED_ACQ
-a always,exclude -F msgtype=USER_ACCT
-a always,exclude -F msgtype=USER_END
-a always,exclude -F msgtype=CRED_DISP
参考了很多配置模板后,整理出的一份配置文件,仅供参考。
/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 -c # log messages rate limit,100 messages per second at most. -r 100 ## Make the loginuid immutable. This prevents tampering with the auid. --loginuid-immutable # This prevents chrony from overwhelming the logs -a never,exit -F arch=x86_64 -S adjtimex -F auid=unset -F uid=chrony -F subj_type=chronyd_t ## If you are on a 64 bit platform, everything _should_ be running ## in 64 bit mode. This rule will detect any use of the 32 bit syscalls ## because this might be a sign of someone exploiting a hole in the 32 ## bit API. -a always,exit -F arch=b32 -S all -F key=32bit-abi ## This rule suppresses the time-change event when chrony does time updates -a never,exit -F arch=b64 -S adjtimex -F auid=unset -Fuid=chrony -F subj_type=chronyd_t # This rule supresses events that originate on the below file systems. # Typically you would use this in conjunction with rules to monitor # kernel modules. The filesystem listed are known to cause hundreds of # path records during kernel module load. As an aside, if you do see the # tracefs or debugfs module load and this is a production system, you really # should look into why its getting loaded and prevent it if possible. -a never,filesystem -F fstype=tracefs -a never,filesystem -F fstype=debugfs ## Things that could affect time -w /etc/localtime -p wa -k time-change ## Things that could affect system locale -a always,exit -F arch=b64 -S sethostname,setdomainname -F key=system-locale -w /etc/issue -p wa -k system-locale -w /etc/issue.net -p wa -k system-locale -w /etc/hosts -p wa -k system-locale -w /etc/hostname -p wa -k system-locale -w /etc/sysconfig/network -p wa -k system-locale -a always,exit -F dir=/etc/NetworkManager/ -F perm=wa -F key=system-locale ## Audit 1, 1(b) Successful and unsuccessful logons and logoffs. ## This is covered by patches to login, gdm, and openssh ## Might also want to watch these files if needing extra information -w /var/log/tallylog -p wa -k logins -w /var/run/faillock/ -p wa -k logins -w /var/log/lastlog -p wa -k logins -w /var/log/btmp -p wa -k logins -w /var/run/utmp -p wa -k logins ## unsuccessful creation -a always,exit -F arch=b64 -S mkdir,creat,link,symlink,mknod,mknodat,linkat,symlinkat -F exit=-EACCES -F key=creation -a always,exit -F arch=b64 -S mkdir,link,symlink,mkdirat -F exit=-EPERM -F key=creation ## unsuccessful open -a always,exit -F arch=b64 -S open,openat,open_by_handle_at -F exit=-EACCES -F key=open -a always,exit -F arch=b64 -S open,openat,open_by_handle_at -F exit=-EPERM -F key=open ## unsuccessful close -a always,exit -F arch=b64 -S close -F exit=-EIO -F key=close ## unsuccessful modifications -a always,exit -F arch=b64 -S rename -S renameat -S truncate -S chmod -S setxattr -S lsetxattr -S removexattr -S lremovexattr -F exit=-EACCES -F key=mods -a always,exit -F arch=b64 -S rename -S renameat -S truncate -S chmod -S setxattr -S lsetxattr -S removexattr -S lremovexattr -F exit=-EPERM -F key=mods ## unsuccessful deletion -a always,exit -F arch=b64 -S rmdir,unlink,unlinkat -F exit=-EACCES -F key=delete -a always,exit -F arch=b64 -S rmdir,unlink,unlinkat -F exit=-EPERM -F key=delete ## Unsuccessful ownership change -a always,exit -F arch=b64 -S lchown,fchown,chown,fchownat -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccesful-perm-change -a always,exit -F arch=b64 -S lchown,fchown,chown,fchownat -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccesful-perm-change ## Audit 1, 1(d) Changes in user authenticators. ## Covered by patches to libpam, passwd, and shadow-utils ## Might also want to watch these files for changes -w /etc/group -p wa -k auth -w /etc/passwd -p wa -k auth -w /etc/gshadow -p wa -k auth -w /etc/shadow -p wa -k auth -w /etc/security/opasswd -p wa -k auth ## Group add delete modify. This is covered by pam. However, someone could ## open a file and directly create or modify a user, so we'll watch group and ## gshadow for writes -a always,exit -F arch=b64 -S openat,open_by_handle_at -F a2&03 -F path=/etc/group -F auid>=1000 -F auid!=unset -F key=group-modify -a always,exit -F arch=b64 -S open -F a1&03 -F path=/etc/group -F auid>=1000 -F auid!=unset -F key=group-modify -a always,exit -F arch=b64 -S openat,open_by_handle_at -F a2&03 -F path=/etc/gshadow -F auid>=1000 -F auid!=unset -F key=group-modify -a always,exit -F arch=b64 -S open -F a1&03 -F path=/etc/gshadow -F auid>=1000 -F auid!=unset -F key=group-modify ## Use of special rights for config changes. This would be use of setuid ## programs that relate to user accts. This is not all setuid apps because ## requirements are only for ones that affect system configuration. -a always,exit -F path=/usr/bin/chfn -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/bin/chage -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/bin/gpasswd -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/bin/newgrp -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/bin/chsh -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/bin/sudo -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/bin/mount -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/bin/su -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/bin/umount -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/bin/pkexec -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/bin/passwd -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/sbin/pam_timestamp_check -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/sbin/unix_chkpwd -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/sbin/usernetctl -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/sbin/mtr -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/sbin/lsof -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged -a always,exit -F path=/usr/sbin/tcpdump -F perm=x -F auid>=1000 -F auid!=unset -F key=privileged ## Things that could affect MAC policy -a always,exit -F dir=/etc/selinux/ -F perm=wa -F key=MAC-policy ## Cron configuration & scheduled jobs -w /etc/cron.allow -p wa -k cron -w /etc/cron.deny -p wa -k cron -w /etc/cron.d/ -p wa -k cron -w /etc/cron.daily/ -p wa -k cron -w /etc/cron.hourly/ -p wa -k cron -w /etc/cron.monthly/ -p wa -k cron -w /etc/cron.weekly/ -p wa -k cron -w /etc/crontab -p wa -k cron -w /var/spool/cron/ -p wa -k cron ## Look for pam_tty_audit and add it to your login entry point's pam configs. ## If that is not found, use sudo which should be patched to record its ## commands to the audit system. Do not allow unrestricted root shells or ## sudo cannot record the action. -w /etc/sudoers -p wa -k actions -w /etc/sudoers.d/ -p wa -k actions ## The purpose of this rule is to detect when an admin may be abusing power ## by looking in user's home dir. -a always,exit -F dir=/home -F uid=0 -F auid>=1000 -F auid!=unset -C auid!=obj_uid -F key=power-abuse ## These rules watch for code injection by the ptrace facility. ## This could indicate someone trying to do something bad or ## just debugging -a always,exit -F arch=b64 -S ptrace -F key=tracing -a always,exit -F arch=b64 -S ptrace -F a0=0x4 -F key=code-injection -a always,exit -F arch=b64 -S ptrace -F a0=0x5 -F key=data-injection -a always,exit -F arch=b64 -S ptrace -F a0=0x6 -F key=register-injection ## These rules watch for kernel module insertion. By monitoring ## the syscall, we do not need any watches on programs. -a always,exit -F arch=b64 -S init_module,finit_module -F key=module-load -a always,exit -F arch=b64 -S delete_module -F key=module-unload ## SSH configuration -w /etc/ssh/sshd_config -p wa -k sshd ## root ssh key tampering -w /root/.ssh -p wa -k rootkey # Systemd -w /bin/systemctl -p x -k systemd -w /etc/systemd/ -p wa -k systemd ## Shell/profile configurations -w /etc/profile.d/ -p wa -k shell_profiles -w /etc/profile -p wa -k shell_profiles -w /etc/shells -p wa -k shell_profiles -w /etc/bashrc -p wa -k shell_profiles -w /etc/csh.cshrc -p wa -k shell_profiles -w /etc/csh.login -p wa -k shell_profiles -w /etc/fish/ -p wa -k shell_profiles -w /etc/zsh/ -p wa -k shell_profiles ## 排除一些干扰性过强的消息 -a always,exclude -F msgtype=USER_START -a always,exclude -F msgtype=CRED_REFR -a always,exclude -F msgtype=CRED_ACQ -a always,exclude -F msgtype=USER_ACCT -a always,exclude -F msgtype=USER_END -a always,exclude -F msgtype=CRED_DISP -a always,exclude -F msgtype=LOGIN -a always,exclude -F msgtype=PROCTITLE ## Ignore current working directory records -a always,exclude -F msgtype=CWD ## Cron jobs fill the logs with stuff we normally don't want (works with SELinux) -a never,user -F subj_type=crond_t -a never,exit -F subj_type=crond_t ## This is not very interesting and wastes a lot of space if the server is public facing -a always,exclude -F msgtype=CRYPTO_KEY_USER ## FileBeat #-a never,exit -F arch=b64 -F path=/opt/filebeat -k filebeat ## This is to check if the system is making or recieving connections ## externally #-a always,exit -F arch=b64 -S accept,connect -F key=external-access ## Make the configuration immutable - reboot is required to change audit rules #-e 2 ## 在audit.log文件中保存的时间格式是自1970年以来的秒数,可以用下面方法转成容易理解的日期时间,audit(1364481363.243:24287) ## date --date=@1364481363.243
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。