在设置了auditctl的规则之后,我想把这些匹配的logging发送到我的Python脚本中作进一步的分析。
这些是涉及的文件:
auditdlogging:
type=PATH msg=audit(1451011319.268:533): ... type=CWD msg=audit(1451011319.268:533): cwd=”/home/root” type=SYSCALL msg=audit(1451011319.268.230:533): ... key=(null)
/etc/audisp/audispd.conf是,如下所示,
q_depth = 80 overflow_action = ignore priority_boost = 4 max_restarts = 10 name_format = HOSTNAME #name = mydomain
/etc/audisp/plugin.d/的audispd插件configuration文件,
active = yes direction = out path = /usr/bin/python type = always # two args, one is my Python script, the other is the log file args = /var/t/h.py /var/log/audit.log format = string
我的h.py如下所示,
# -*- coding: utf-8 -*- import sys print sys.argv[1] ...
但是,我的Python脚本无法从auditd获取任何logging。
我不知道哪里错了,请帮我一把!
看来audispd正在将审计事件写入其插件stdin中。
(链接到下面的源代码是相对的从https://github.com/packetstash/auditd/tree/ba912fa614a7e73160a4eba338e55890d6e8f62f这是我在服务器故障的第一篇文章,我不能包括两个以上的链接)。
尤其是:
audisp/audispd.c#L484创build一对套接字; audisp/audispd.c#L500 ; audisp/audispd.c#L533 。 你的脚本将inheritanceaudispd开放文件描述符,包括stdout(fd#1),这个文件将被重新打开到/dev/null 。 因此,在脚本中print可能没有效果,你将不得不写入一些文件。
尝试像这样:
import sys with open('/tmp/my_audit.log', 'w') as log_file: for event_message in sys.stdin: log_file.write('%s\n' % event_message)
您可能还想使用bindings/python/auparse_python.c模块来parsing事件消息。