首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何审核特定用户对给定路径内的任何文件或文件夹的访问

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

Unix & Linux用户
提问于 2015-02-24 09:41:16
回答 1查看 11.7K关注 0票数 9

我一直在读一些关于auditd配置的信息,我就是搞不懂,我知道怎么做

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

然而,我无法理解的是:如何设置审计守护进程,以便它只记录对给定用户id的文件夹结构(例如/home和所有子文件夹和文件)中的所有文件的访问(读/写)。

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

额外的问题:是否有可能为整个文件系统层次结构设置这种审计?由于某些原因,AFAIK审计不允许这样做

EN

回答 1

Unix & Linux用户

发布于 2015-03-05 11:11:41

我会从这样的开始:

代码语言:javascript
复制
# auditctl -a exit,always -F arch=x86_64 -S open -F auid=1000 -k track-guido

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

代码语言:javascript
复制
# 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 

要细化规则并对目录树进行这种控制,这将转到:

代码语言:javascript
复制
# auditctl -w /home/guido/Development/git/ -F auid=1000 -p rwxa -k track-guido-development

其中:

代码语言:javascript
复制
-F auid=     filter on actual uid
-p rwxa      track Read, Write, eXecute, Attributes

(您可以将所需的-F组合起来)。

给予产出,如:

代码语言:javascript
复制
# 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 
----

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

代码语言:javascript
复制
# auditctl -R /etc/audit/audit.rules

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

票数 5
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/186539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档