如何审核特定用户对给定路径内任何文件或文件夹的访问

如何审核特定用户对给定路径内任何文件或文件夹的访问

我一直在阅读一些有关配置的信息auditd,但我无法弄清楚我知道该怎么做

  • 记录用户的特定系统调用
  • 记录所有用户对特定文件的访问

然而,我无法弄清楚的是:如何设置审核守护程序,以便它/home仅记录给定用户 ID 对文件夹结构中的所有文件(例如,以及其中的所有子文件夹和文件)的访问(读/写)。

因此,如果我有一个用户 ID 为 2053 的用户“bob”,我就会知道他们尝试在文件系统上打开或读取的每个文件。我对系统服务或任何其他用户访问这些文件不感兴趣。

额外的问题:是否可以以某种方式为整个文件系统层次结构设置这种审核?由于某些原因,据我所知审计不允许这样做

答案1

我会从这样的事情开始:

# auditctl -a exit,always -F arch=x86_64 -S open -F auid=1000 -k track-guido

这将跟踪所有文件系统上 uid=1000 用户的所有文件打开操作;请注意,如果您在具有图形会话的用户上运行它,这将生成日志,例如以下内容(我猜是不需要的):

# ausearch -i -k track-guido
---- (chrome opening /etc/hosts )
type=PROCTITLE msg=audit(03/05/2015 19:49:14.990:257528) : proctitle=/opt/google/chrome/chrome  
type=PATH msg=audit(03/05/2015 19:49:14.990:257528) : item=0 name=/etc/hosts inode=917951 dev=08:02 mode=file,644 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:net_conf_t:s0 nametype=NORMAL 
type=CWD msg=audit(03/05/2015 19:49:14.990:257528) :  cwd=/home/guido 
type=SYSCALL msg=audit(03/05/2015 19:49:14.990:257528) : arch=x86_64 syscall=open success=yes exit=164 a0=0x7f843c7682fe a1=O_RDONLY|O_CLOEXEC a2=0x1b6 a3=0x7f84411c070c items=1 ppid=1665 pid=3224 auid=guido uid=guido gid=guido euid=guido suid=guido fsuid=guido egid=guido sgid=guido fsgid=guido tty=(none) ses=1 comm=WorkerPool/3224 exe=/opt/google/chrome/chrome subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=track-guido 
---- (gnome-shell opening /proc/self/stat)
type=PROCTITLE msg=audit(03/05/2015 19:49:15.041:257529) : proctitle=/usr/bin/gnome-shell 
type=PATH msg=audit(03/05/2015 19:49:15.041:257529) : item=0 name=/proc/self/stat inode=21375 dev=00:03 mode=file,444 ouid=guido ogid=guido rdev=00:00 obj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 nametype=NORMAL 
type=CWD msg=audit(03/05/2015 19:49:15.041:257529) :  cwd=/home/guido 
type=SYSCALL msg=audit(03/05/2015 19:49:15.041:257529) : arch=x86_64 syscall=open success=yes exit=42 a0=0x7f7b7b7a5f4a a1=O_RDONLY a2=0x7fff4ce2aaa0 a3=0x1 items=1 ppid=1371 pid=1665 auid=guido uid=guido gid=guido euid=guido suid=guido fsuid=guido egid=guido sgid=guido fsgid=guido tty=(none) ses=1 comm=gnome-shell exe=/usr/bin/gnome-shell subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=track-guido 

为了完善规则并对目录树进行这样的控制,这将变成:

# auditctl -w /home/guido/Development/git/ -F auid=1000 -p rwxa -k track-guido-development

在哪里:

-F auid=     filter on actual uid
-p rwxa      track Read, Write, eXecute, Attributes

(你可以组合你想要的 -F 数量)。

给出如下输出:

# ausearch -i -k track-guido-development
----
type=PROCTITLE msg=audit(03/05/2015 22:04:40.893:365951) : proctitle=vim /home/guido/Development/git/eduFXserver.git/pom.xml 
type=PATH msg=audit(03/05/2015 22:04:40.893:365951) : item=0 name=/home/guido/Development/git/eduFXserver.git/.pom.xml.swp inode=11146444 dev=08:05 mode=file,600 ouid=guido ogid=guido rdev=00:00 obj=unconfined_u:object_r:user_home_t:s0 nametype=NORMAL 
type=CWD msg=audit(03/05/2015 22:04:40.893:365951) :  cwd=/home/guido 
type=SYSCALL msg=audit(03/05/2015 22:04:40.893:365951) : arch=x86_64 syscall=getxattr success=yes exit=37 a0=0x241e6d0 a1=0x7fc8479afcee a2=0x241e720 a3=0xff items=1 ppid=784 pid=9231 auid=guido uid=guido gid=guido euid=guido suid=guido fsuid=guido egid=guido sgid=guido fsgid=guido tty=pts3 ses=1 comm=vim exe=/usr/bin/vim subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=track-guido-development 
----
type=PROCTITLE msg=audit(03/05/2015 22:04:40.893:365953) : proctitle=vim /home/guido/Development/git/eduFXserver.git/pom.xml 
type=PATH msg=audit(03/05/2015 22:04:40.893:365953) : item=0 name=/home/guido/Development/git/eduFXserver.git/.pom.xml.swp inode=11146444 dev=08:05 mode=file,600 ouid=guido ogid=guido rdev=00:00 obj=unconfined_u:object_r:user_home_t:s0 nametype=NORMAL 
type=CWD msg=audit(03/05/2015 22:04:40.893:365953) :  cwd=/home/guido 
type=SYSCALL msg=audit(03/05/2015 22:04:40.893:365953) : arch=x86_64 syscall=getxattr success=yes exit=37 a0=0x241e6d0 a1=0x7fc8479afcee a2=0x241e720 a3=0xff items=1 ppid=784 pid=9231 auid=guido uid=guido gid=guido euid=guido suid=guido fsuid=guido egid=guido sgid=guido fsgid=guido tty=pts3 ses=1 comm=vim exe=/usr/bin/vim subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=track-guido-development 
----

它仍然会包含很多不需要的东西,但好多了。如果系统由于您的规则之一接管而变得无响应,您可以执行:

# auditctl -R /etc/audit/audit.rules

作为重置为默认(空)规则的恐慌模式。

相关内容