Using auditd to capture "permission denied" notices

the*_*ien 2 linux-audit

I'm trying to figure out how to log/track when a user gets a Permission denied notice after attempting to access a file. I've read that adding a rule to /etc/audit/audit.rules can accomplish this.

The only suggestion that I've seen mentioned appears to not work as intended. Or, at least, it does not do what I would like. It very well may work the way it is written. The rule is

-a always,exit -F arch=b64 -S open -F success!=0
Run Code Online (Sandbox Code Playgroud)

Actually, the suggestion at the link above does not include the arch option. I had to add that.

当尾随时/var/log/audit/audit.log,我看到了所说的一切success=yes。这包括当我单击窗口并更改焦点或输入组合键以在窗口功能之间进行更改时。我没有看到与Permission denied包含条目相关的任何success=no内容或与我尝试打开的特定文件有关的任何内容,但我知道我没有该文件的权限。

我只能明确地说,当我 grep for success=noin时/var/log/audit/audit.log,什么也没有返回。

规则应该是什么?或者更好的是,这实际上可能吗?上面的解决方案不正确吗?

the*_*ien 7

我一直在使用工具,发现如果我使用success!=1thenaudit.log将显示指示success=no. 这对我来说似乎违反直觉,因为非零退出代码通常表示某种失败,但也!=1可以是任何内容,包括其他失败退出代码以及成功 ( 0)。但有趣的是,这些并没有出现。

另一个问题是它没有指示哪个文件访问失败。相反,它仅列出返回失败退出代码时运行的命令。就我而言,我正在跑步cat /etc/shadow。所以,与其看到

type=SYSCALL msg=audit(1438754257.463:11451): arch=c000003e syscall=2 success=no exit=-13 a0=7ffea511f35f a1=0 a2=1ffffffffffe0000 a3=0 items=1 ppid=1650 pid=5489 auid=1000 uid=1000 gid=100 euid=1000 suid=1000 fsuid=1000 egid=100 sgid=100 fsgid=100 tty=pts0 ses=1 comm="cat" exe="/usr/bin/cat" key="access"
type=CWD msg=audit(1438754257.463:11451):  cwd="/home/msnyder"
type=PATH msg=audit(1438754257.463:11451): item=0 name="/etc/shadow" inode=1131047 dev=00:20 mode=0100640 ouid=0 ogid=15 rdev=00:00 nametype=NORMAL
Run Code Online (Sandbox Code Playgroud)

我只会看到

type=SYSCALL msg=audit(1438752096.223:4952): arch=c000003e syscall=2 success=yes exit=3 a0=7f77d575c057 a1=80000 a2=1 a3=22 items=1 ppid=1650 pid=4873 auid=1000 uid=1000 gid=100 euid=1000 suid=1000 fsuid=1000 egid=100 sgid=100 fsgid=100 tty=pts0 ses=1 comm="cat" exe="/usr/bin/cat" key=(null)
type=CWD msg=audit(1438752096.223:4952):  cwd="/home/msnyder"
Run Code Online (Sandbox Code Playgroud)

然后我查看了audit.rules联机帮助页。尤里卡!答案一直就在那里:

-a always,exit -F arch=b64 -S open,openat -F exit=-EACCES -F key=access
-a always,exit -F arch=b64 -S open,openat -F exit=-EPERM -F key=access
Run Code Online (Sandbox Code Playgroud)

这两个规则结合起来解决了问题。它不仅会记录失败的文件访问,还会记录尝试访问的文件。这会产生上面的前三个日志条目,其中包括文件名。