一.audit簡介
請參閱redhat說明文檔: https://people.redhat.com/sgrubb/audit/
二.使用audit
1.確認系統安裝了audit服務,ubuntu執行以下命令安裝
~# sudo apt-get install auditd
2.啟動audit服務
systemctl restart auditd
實驗
監控/mnt目錄
auditctl -w /mnt -p rwxa -k MNT //-w 制定監控的文件,-p制定屬性rwxa ,-k 指定標識符,隨意
當我們操作/mnt是會產生審計日志
ls /mnt; touch /mnt/file
ausearch -i -k MNT //查看監控日志
結果如下
root@localhost:~# ausearch -i -k MNT ---- type=CONFIG_CHANGE msg=audit(2019年08月21日 21:45:48.049:42) : auid=xiao ses=1 op="add_rule" key=MNT list=exit res=yes ---- type=PROCTITLE msg=audit(2019年08月21日 21:45:57.445:43) : proctitle=ls --color=auto /mnt/ type=PATH msg=audit(2019年08月21日 21:45:57.445:43) : item=0 name=/mnt/ inode=1569793 dev=fc:00 mode=dir,755 ouid=root ogid=root rdev=00:00 nametype=NORMAL type=CWD msg=audit(2019年08月21日 21:45:57.445:43) : cwd=/root type=SYSCALL msg=audit(2019年08月21日 21:45:57.445:43) : arch=x86_64 syscall=open success=yes exit=3 a0=0xcbf5e0 a1=O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC a2=0x0 a3=0x502 items=1 ppid=3544 pid=4611 auid=xiao uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=pts4 ses=1 comm=ls exe=/bin/ls key=MNT ---- type=PROCTITLE msg=audit(2019年08月21日 21:47:29.402:47) : proctitle=touch /mnt/file type=PATH msg=audit(2019年08月21日 21:47:29.402:47) : item=1 name=/mnt/file inode=1577707 dev=fc:00 mode=file,644 ouid=root ogid=root rdev=00:00 nametype=CREATE type=PATH msg=audit(2019年08月21日 21:47:29.402:47) : item=0 name=/mnt/ inode=1569793 dev=fc:00 mode=dir,755 ouid=root ogid=root rdev=00:00 nametype=PARENT type=CWD msg=audit(2019年08月21日 21:47:29.402:47) : cwd=/root type=SYSCALL msg=audit(2019年08月21日 21:47:29.402:47) : arch=x86_64 syscall=open success=yes exit=3 a0=0x7ffcfb32c8fa a1=O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK a2=0666 a3=0x69d items=2 ppid=3544 pid=4631 auid=xiao uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=pts4 ses=1 comm=touch exe=/bin/touch key=MNT root@localhost:~#
日志保存在
/var/log/audit/audit.log
注意點:
(1)這是臨時添加的,永久設置修改配置文件
/etc/audit/rules.d/audit.rules 子配置目錄
/etc/audit/audit.rules 主配置目錄
完成后重啟audit服務
(2)bash后臨時添加失敗或者寫到配置文件后,重啟audit服務失敗
需要解固,刪除修改配置文件中的-e 選項