如何設定 SELinux 在審核日誌的每個條目中列印日期和時間?

如何設定 SELinux 在審核日誌的每個條目中列印日期和時間?

我使用的是 CentOS 5.5,預設情況下我的/var/log/audit/audit.log外觀如下:

type=USER_AUTH msg=audit(1331897657.359:8435): user pid=15610 uid=0 auid=4294967295 subj=system_u:system_r:unconfined_t:s0-s0:c0.c1023 msg='PAM: authentication acct="?" : exe="/usr/sbin/sshd" (hostname=c165-130.i02-2.onvol.net, addr=213.165.165.130, terminal=ssh res=failed)'
type=USER_LOGIN msg=audit(1331897657.360:8436): user pid=15610 uid=0 auid=4294967295 subj=system_u:system_r:unconfined_t:s0-s0:c0.c1023 msg='acct="oracle": exe="/usr/sbin/sshd" (hostname=?, addr=213.165.165.130, terminal=sshd res=failed)'

確切地說,日誌條目是在沒有時間戳的情況下寫入的,這使得故障排除變得更加困難。有一個可用的手冊頁

 man auditd.conf 

但在這個主題中它只說了:

log_format
     The log format describes how the information should be stored on
     disk.  There  are  2 options: raw and nolog.  If set to RAW, the
     audit records will be stored in a format exactly as  the  kernel
     sends it. If this option is set to NOLOG then all audit informa-
     tion is discarded instead of writing to disk. This mode does not
     affect data sent to the audit event dispatcher.

如何將其配置為在每個條目的開頭列印日期/時間?

答案1

雖然您無法設定任何選項來使auditd日誌具有人類可解析的日期格式,但如果您使用“ausearch”命令來搜尋您的審計日誌,則有一個-i選項可以產生人類可讀的(嗯,也許稍微更具人類可讀性)輸出。

例如,如果我ausearch -ts today在新啟動的系統上運行,我會看到:

# ausearch -ts today
----
time->Mon Mar 19 23:07:00 2012
type=DAEMON_START msg=audit(1332212820.421:3834): auditd start, ver=2.1.3 format=raw kernel=3.2.10-3.fc16.x86_64 auid=4294967295 pid=6438 subj=system_u:system_r:auditd_t:s0 res=success

但如果我運行ausearch -ts today -i,我會看到:

# ausearch -ts today -i
----
type=DAEMON_START msg=audit(03/19/2012 23:07:00.421:3834) : auditd start, ver=2.1.3 format=raw kernel=3.2.10-3.fc16.x86_64 auid=unset pid=6438 subj=system_u:system_r:auditd_t:s0 res=success 

那對你有用嗎? ausearch無論如何,您可能會用它來查看審計記錄。 -i也可以執行 uid->使用者名稱查找和其他解析等操作。 編輯:從上面可以看出我跑的是Fedora 16,但同樣ausearch -i適用於RHEL5。

答案2

開頭的長數字是時間戳記:自紀元以來的秒數。幾分鐘前,我得到:

[0 1128 18:09:57] ~ % date +%s; date
1331917801
Fri Mar 16 18:10:01 CET 2012

要將數字轉換為更具可讀性的內容,請嘗試

[0 1133 18:12:41] ~ % date -d @1331897657
Fri Mar 16 12:34:17 CET 2012

(所以顯然,你需要「常用sed技巧」來剪掉亞秒部分。)

我手邊沒有啟用 SE 的機器,但也許sealert -a也可以將時間戳解析為人類可讀的內容?

答案3

ausearch -i 

來自幫助:

-i,--interpret    Interpret results to be human readable

這不是正確的答案傑斯比林斯寫道。

無需運行 tail -f !

PS 該死的堆疊點!這就是為什麼我無法發表評論或投票的原因。

答案4

tail -f /var/log/audit/audit.log | ausearch -i

相關內容