Samhain 可以监视不存在的文件,但将来可能吗?

Ric*_*ner 8 security linux intrusion-detection

我希望 Samhain 监视一个文件,例如,/root/somefile. 此文件当前不存在,但我希望在任何时候创建它时收到通知。

我将此添加到samhainrc

[ReadOnly]
file = /root/somefile
Run Code Online (Sandbox Code Playgroud)

这会导致 Samhain 发出这些日志条目:

Oct 18 22:54:04 ip-172-31-24-115 Samhain[17123]: CRIT   :  [2018-10-18T22:54:04+0000] interface=<lstat>, msg=<No such file or directory>, userid=<0>, path=</root/somefile>
Oct 18 22:54:04 ip-172-31-24-115 Samhain[17123]: CRIT   :  [2018-10-18T22:54:04+0000] msg=<POLICY MISSING>, path=</root/somefile>
Oct 18 22:54:19 ip-172-31-24-115 Samhain[17157]: INFO   :  [2018-10-18T22:54:19+0000] msg=<Checking       [ReadOnly]>, path=</root/somefile>
Oct 18 22:54:19 ip-172-31-24-115 Samhain[17157]: NOTICE :  [2018-10-18T22:54:19+0000] msg=<Check failed>, path=</root/somefile>
Run Code Online (Sandbox Code Playgroud)

如果我用 来创建这个文件echo test > /root/somefile,那么我不会记录任何违反政策的行为——这个文件的添加没有被注意到。

如果创建了以前不存在的感兴趣文件,我如何配置 Samhain 以通知我?


IgnoreMissing配置选项会出现在乍看之下是有用的,但事实并非如此。使用IgnoreMissing = /root/somefilein samhainrc,行为没有变化。似乎此选项适用于预计稍后会丢失的文件 - 如果文件曾经存在,它会抑制警报,但现在不会,例如,如果自动化进程删除过时的文件。


虽然/root/somefile在这种情况下显然是编造的,但不存在的文件突然开始存在的一个例子是,如果该文件/home/someuser/.ssh/authorized_keys以前不存在但突然确实存在——这可能是恶意用户利用某些东西放下后门,允许他们以 shell 用户身份登录。这是我想要提醒的事情。

可以使用dir = /home/someuser/.ssh来监视用户文件夹中的所有更改.ssh,但这无济于事:如果用户在其帐户中使用 SSH 是正常的,则他们的.ssh/known_hosts文件可能会更改,他们可能会更改他们的ssh_config. 等,而我不希望被那些人警告。因此,除了某些列入白名单的文件之外,我不想监视整个目录;除了特定的关键文件之外,我想让目录不受监视。

小智 0

如果我正确理解,您需要监视 dir 中的所有文件,除了某些文件或子目录:

您可以尝试下一步:

[ReadOnly] 
    #
    dir=/home/someuser/.ssh 
    # 
    [Attributes] 
    # 
    # less restrictive policy for the directory file itself 
    # 
    file=/home/someuser/.ssh 
    # 
    [IgnoreAll] 
    # 
    # exclude these file and directories 
    #
    file=/home/someuser/.ssh/known_hosts
    #dir=-1/etc/calendar
    #
Run Code Online (Sandbox Code Playgroud)

更多信息https://www.la-samhna.de/samhain/manual/all-except.html