logwatchついて



●設定

 参考URL:LogWatchで、サーバーのログをチェック!

 LogWatchの設定ファイルは /usr/share/logwatch/default.conf/logwatch.conf です。
 しかし、設定を変更する場合は /etc/logwatch/conf/logwatch.conf を利用します。
 後者に変更したい情報を記載することで基本情報が上書きされます。
# cat /etc/logwatch/conf/logwatch.conf
# Local configuration options go here (defaults are in /usr/share/logwatch/default.conf/logwatch.conf)
 
# vi /etc/logwatch/conf/logwatch.conf
MailTo = (送付先メールアドレス)
Detail = Low
 Lowの他に、Mid、Highを選択できます。または、0~10までの数字を指定します。
 High(または、数字が大きい方)が、「詳細に」解析します。

●LogWatchテスト

 下記コマンドを実行することによりテスト的にメールが送信されます。
# logwatch --output mail


●logwatchで通知されるunmatched entriesを記録されないようにしたい

 参考URL:LogWatchで、サーバーのログをチェック!
 参考URL:logwatchのpostfix欄に記載されているUnmatched Entriesについて
 参考URL:アクセスログの改ざんと検出方法 (2/2)
 参考URL:logwatchによるログ監視

 logwatchのUnmatched Entriesは、そのログを処理する方法が規定されていないため、無視してよいかどうかわからない、判断を人間にゆだねるため出ているもの、らしいです。
 ということであれば無視しても良さそう。

 実際に対処したいのは、logwatch内のConnections (secure-log)で大量に記録されている下記となります。

audit: CRED_ACQ pid=9995 uid=0 auid=4294967295 ses=4294967295 msg='op=PAM:setcred grantors=pam_env,pam_unix acct="cacti" exe="/usr/sbin/crond" hostname=? addr=?
terminal=cron res=success': 1 Time(s)

audit: CRED_DISP pid=10040 uid=0 auid=986 ses=2879 msg='op=PAM:setcred grantors=pam_env,pam_unix acct="cacti" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron
res=success': 1 Time(s)

audit: CRYPTO_KEY_USER pid=1000 uid=0 auid=4294967295 ses=4294967295 msg='op=destroy kind=server fp=SHA256:f9:dd:71:90:91:73:36:k0:58:af:26:90:e6:28:6e:57:d8:cf:12:22:76:b6:9d:90:99:a6:81:d3:8b:cb:19:5b direction=? spid=1000 suid=0 exe="/usr/sbin/sshd" hostname=?
addr=192.168.0.1 terminal=? res=success': 1 Time(s)


 3通りの設定方法があるようです。

 /etc/logwatch/conf/ignore.confに、正規表現を記載する方法
 *RemoveService(=チェック対象外のサービス(文字列)のパターンを指定)を設定する方法
 *Remove(=指定した文字列にマッチした行はチェック対象外にする(大文字小文字の区別なし)を設定する方法

 「ignore.conf」による対応

 個人的な環境でVMWareのログで「S.M.A.R.Tの値がおかしい」ために、これを検知してしまいます。
Mar 16 18:52:36 serverA smartd: [warn] naa.************8113: REALLOCATED SECTOR CT below threshold (0 < 140)
Mar 16 18:52:37 serverA smartd: [warn] naa.************d86b: REALLOCATED SECTOR CT below threshold (0 < 140)
Mar 16 18:52:37 serverA smartd: [warn] naa.************ef11: REALLOCATED SECTOR CT below threshold (0 < 140)
 これが鬱陶しかったため、/etc/logwatch/conf/ignore.confに「REALLOCATED SECTOR CT」に追記しました。
# cat /etc/logwatch/conf/ignore.conf
REALLOCATED SECTOR CT
 下記コマンドを実行し、該当行が表示されないことを確認します。
# logwatch --output stdout
 表示されなければ作業は完了です。
 複数の文字列を除外したい場合、1行に1除外対象文字列を記載してください。

 「*RemoveService」による対応

 「*RemoveService」を/usr/share/logwatch/default.conf/logfiles/secure.confに追記します。
 追記した行は *RemoveService = audit です。
 追記後にログレポートを標準出力に表示させます。

# logwatch --output stdout

※secure-logのみ抜粋
--------------------- Connections (secure-log) Begin ------------------------

Failed adding users:
cacti: 1 Time(s)


**Unmatched Entries**
CROND: pam_ldap(crond:session): error opening connection to nslcd: No such file or directory: 115 Time(s)
crond: pam_ldap(crond:session): error opening connection to nslcd: No such file or directory: 115 Time(s)
httpd: DIGEST-MD5 common mech free: 70 Time(s)
php: DIGEST-MD5 common mech free: 7367 Time(s)
polkitd: Acquired the name org.freedesktop.PolicyKit1 on the system bus: 1 Time(s)
polkitd: Finished loading, compiling and executing 12 rules: 1 Time(s)
polkitd: Loading rules from directory /etc/polkit-1/rules.d: 1 Time(s)
polkitd: Loading rules from directory /usr/share/polkit-1/rules.d: 1 Time(s)
runuser: pam_systemd(runuser-l:session): Failed to create session: Connection timed out: 1 Time(s)
slapcat: DIGEST-MD5 common mech free: 2 Time(s)
slapd: DIGEST-MD5 common mech free: 1 Time(s)
su: (to root) user on pts/0: 1 Time(s)
su: (to root) user on pts/1: 3 Time(s)
su: (to test5000) user on pts/1: 2 Time(s)
su: (to xymon) root on none: 1 Time(s)
su: pam_ldap(su-l:account): error opening connection to nslcd: No such file or directory: 8 Time(s)
su: pam_ldap(su-l:auth): error opening connection to nslcd: No such file or directory: 6 Time(s)
su: pam_ldap(su-l:auth): failed to get password: 認証トークン操作エラー: 1 Time(s)
su: pam_ldap(su-l:session): error opening connection to nslcd: No such file or directory: 21 Time(s)
su: pam_systemd(su-l:session): Cannot create session: Already running in a session: 3 Time(s)
su: pam_systemd(su-l:session): Failed to create session: Connection timed out: 1 Time(s)
systemd-logind: New seat seat0.: 1 Time(s)
systemd-logind: New session 15945 of user root.: 1 Time(s)
systemd-logind: New session 15956 of user root.: 1 Time(s)
systemd-logind: New session 15958 of user root.: 1 Time(s)
systemd-logind: New session 15962 of user root.: 1 Time(s)
systemd-logind: New session 15980 of user root.: 1 Time(s)
systemd-logind: New session 15985 of user root.: 1 Time(s)
systemd-logind: New session 15987 of user root.: 1 Time(s)
systemd-logind: New session 15988 of user root.: 1 Time(s)
systemd-logind: Removed session 15945.: 1 Time(s)
systemd-logind: Removed session 15956.: 1 Time(s)
systemd-logind: Removed session 15958.: 1 Time(s)
systemd-logind: Removed session 15962.: 1 Time(s)
systemd-logind: Removed session 15980.: 1 Time(s)
systemd-logind: Removed session 15985.: 1 Time(s)
systemd-logind: Removed session 15987.: 1 Time(s)
systemd-logind: Removed session 15988.: 1 Time(s)
systemd-logind: Watching system buttons on /dev/input/event0 (Power Button): 1 Time(s)
systemd-logind: Watching system buttons on /dev/input/event1 (Power Button): 1 Time(s)
systemd-logind: Watching system buttons on /dev/input/event2 (Video Bus): 1 Time(s)
systemd-logind: Watching system buttons on /dev/input/event3 (HP WMI hotkeys): 1 Time(s)
systemd: pam_ldap(systemd-user:session): error opening connection to nslcd: No such file or directory: 10 Time(s)
webmin: Webmin starting: 1 Time(s)

---------------------- Connections (secure-log) End -------------------------


 期待通りの結果となりました。

 下記は設定変更前の出力結果です。

# logwatch --output stdout

※secure-logから抜粋

audit: AVC avc: denied { siginh } for pid=538 comm="kmod" scontext=system_u:system_r:init_t:s0 tcontext=system_u:system_r:insmod_t:s0 tclass=process permissive=1: 1 Time(s)
audit: AVC avc: denied { siginh } for pid=718 comm="audispd" scontext=system_u:system_r:auditd_t:s0 tcontext=system_u:system_r:audisp_t:s0 tclass=process permissive=1: 1 Time(s)

audit: CONFIG_CHANGE audit_enabled=0 old=1 auid=4294967295 ses=4294967295 subj=system_u:system_r:unconfined_service_t:s0 res=1: 2 Time(s)
audit: CONFIG_CHANGE audit_enabled=1 old=1 auid=4294967295 ses=4294967295 subj=system_u:system_r:auditd_t:s0 res=1: 1 Time(s)
audit: CONFIG_CHANGE audit_enabled=1 old=1 auid=4294967295 ses=4294967295 subj=system_u:system_r:syslogd_t:s0 res=1: 1 Time(s)
audit: CONFIG_CHANGE audit_pid=22001 old=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:auditd_t:s0 res=1: 1 Time(s)
audit: CONFIG_CHANGE audit_pid=716 old=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:auditd_t:s0 res=1: 1 Time(s)

audit: CRED_ACQ pid=10040 uid=0 auid=4294967295 ses=4294967295 msg='op=PAM:setcred grantors=pam_env,pam_unix acct="cacti" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron res=success': 1 Time(s)
audit: CRED_ACQ pid=10061 uid=0 auid=4294967295 ses=4294967295 msg='op=PAM:setcred grantors=pam_env,pam_unix acct="cacti" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron res=success': 1 Time(s)
audit: CRED_ACQ pid=10064 uid=0 auid=4294967295 ses=4294967295 msg='op=PAM:setcred grantors=pam_env,pam_unix acct="cacti" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron res=success': 1 Time(s)

audit: CRED_DISP pid=10040 uid=0 auid=986 ses=2879 msg='op=PAM:setcred grantors=pam_env,pam_unix acct="cacti" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron res=success': 1 Time(s)
audit: CRED_DISP pid=10061 uid=0 auid=986 ses=3465 msg='op=PAM:setcred grantors=pam_env,pam_unix acct="cacti" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron res=success': 1 Time(s)
audit: CRED_DISP pid=10064 uid=0 auid=986 ses=2628 msg='op=PAM:setcred grantors=pam_env,pam_unix acct="cacti" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron res=success': 1 Time(s)

audit: CRYPTO_KEY_USER pid=1000 uid=0 auid=4294967295 ses=4294967295 msg='op=destroy kind=server
fp=SHA256:5b:fc:38:e0:28:3e:09:93:a2:9a:bd:68:23:2b:26:c1:23:24:ea:74:06:08:2f:5d:47:e6:e6:9c:30:de:13:10 direction=?
spid=1000 suid=0 exe="/usr/sbin/sshd" hostname=? addr=192.168.0.1 terminal=? res=success': 1 Time(s)
audit: CRYPTO_KEY_USER pid=1000 uid=0 auid=4294967295 ses=4294967295 msg='op=destroy kind=server
fp=SHA256:98:d8:71:28:91:73:36:ac:58:af:26:90:e6:26:6e:57:0b:cf:94:15:76:b6:f3:90:99:a5:81:d3:8b:cb:19:5b direction=?
spid=1000 suid=0 exe="/usr/sbin/sshd" hostname=? addr=192.168.0.1 terminal=? res=success': 1 Time(s)
audit: CRYPTO_KEY_USER pid=1000 uid=0 auid=4294967295 ses=4294967295 msg='op=destroy kind=server
fp=SHA256:25:dd:a2:10:e7:14:50:5e:61:db:ad:60:b4:c9:d3:ae:62:47:3b:23:33:32:e0:ae:20:0f:a2:2c:84:40:69:f8 direction=?
spid=1000 suid=0 exe="/usr/sbin/sshd" hostname=? addr=192.168.0.1 terminal=? res=success': 1 Time(s)


 「*Remove」による対応

 「*Remove」を/usr/share/logwatch/default.conf/services/secure.confに追記します(同じフォルダにあるsshd.conf及びsshd2.confに記載して期待通りに動作しませんでした。)。
 追記した行は *Remove = audit です。
 追記後にログレポートを標準出力に表示させます。 

# logwatch --output stdout

※logwatchから抜粋

--------------------- Connections (secure-log) Begin ------------------------

Failed adding users:
cacti: 1 Time(s)


**Unmatched Entries**
CROND: pam_ldap(crond:session): error opening connection to nslcd: No such file or directory: 115 Time(s)
crond: pam_ldap(crond:session): error opening connection to nslcd: No such file or directory: 115 Time(s)
httpd: DIGEST-MD5 common mech free: 70 Time(s)
php: DIGEST-MD5 common mech free: 7367 Time(s)
polkitd: Acquired the name org.freedesktop.PolicyKit1 on the system bus: 1 Time(s)
polkitd: Finished loading, compiling and executing 12 rules: 1 Time(s)
polkitd: Loading rules from directory /etc/polkit-1/rules.d: 1 Time(s)
polkitd: Loading rules from directory /usr/share/polkit-1/rules.d: 1 Time(s)
runuser: pam_systemd(runuser-l:session): Failed to create session: Connection timed out: 1 Time(s)
slapcat: DIGEST-MD5 common mech free: 2 Time(s)
slapd: DIGEST-MD5 common mech free: 1 Time(s)
su: (to root) user on pts/0: 1 Time(s)
su: (to root) user on pts/1: 3 Time(s)
su: (to test5000) user on pts/1: 2 Time(s)
su: (to xymon) root on none: 1 Time(s)
su: pam_ldap(su-l:account): error opening connection to nslcd: No such file or directory: 8 Time(s)
su: pam_ldap(su-l:auth): error opening connection to nslcd: No such file or directory: 6 Time(s)
su: pam_ldap(su-l:auth): failed to get password: 認証トークン操作エラー: 1 Time(s)
su: pam_ldap(su-l:session): error opening connection to nslcd: No such file or directory: 21 Time(s)
su: pam_systemd(su-l:session): Cannot create session: Already running in a session: 3 Time(s)
su: pam_systemd(su-l:session): Failed to create session: Connection timed out: 1 Time(s)
systemd-logind: New seat seat0.: 1 Time(s)
systemd-logind: New session 15945 of user root.: 1 Time(s)
systemd-logind: New session 15956 of user root.: 1 Time(s)
systemd-logind: New session 15958 of user root.: 1 Time(s)
systemd-logind: New session 15962 of user root.: 1 Time(s)
systemd-logind: New session 15980 of user root.: 1 Time(s)
systemd-logind: New session 15985 of user root.: 1 Time(s)
systemd-logind: New session 15987 of user root.: 1 Time(s)
systemd-logind: New session 15988 of user root.: 1 Time(s)
systemd-logind: Removed session 15945.: 1 Time(s)
systemd-logind: Removed session 15956.: 1 Time(s)
systemd-logind: Removed session 15958.: 1 Time(s)
systemd-logind: Removed session 15962.: 1 Time(s)
systemd-logind: Removed session 15980.: 1 Time(s)
systemd-logind: Removed session 15985.: 1 Time(s)
systemd-logind: Removed session 15987.: 1 Time(s)
systemd-logind: Removed session 15988.: 1 Time(s)
systemd-logind: Watching system buttons on /dev/input/event0 (Power Button): 1 Time(s)
systemd-logind: Watching system buttons on /dev/input/event1 (Power Button): 1 Time(s)
systemd-logind: Watching system buttons on /dev/input/event2 (Video Bus): 1 Time(s)
systemd-logind: Watching system buttons on /dev/input/event3 (HP WMI hotkeys): 1 Time(s)
systemd: pam_ldap(systemd-user:session): error opening connection to nslcd: No such file or directory: 10 Time(s)
webmin: Webmin starting: 1 Time(s)

---------------------- Connections (secure-log) End -------------------------


 こちらも期待通りの結果となりました。

●root宛に変なメール

 root宛にいつからか下記のようなメールが送られていました。
/etc/cron.daily/0logwatch:
You have old files in your logwatch tmpdir (/var/cache/logwatch):
	logwatch.118ksY6m
The directories listed above were most likely created by a
logwatch run that failed to complete successfully.  If so, you
may delete these directories.


 対処方法

 /var/cache/logwatchディレクトリを削除することにより解決しました。