openSUSE16.1 : Tripwire , Logwatch インストール

1. Tripwire

1.1 インストール、設定

① インストール

# zypper -n install tripwire

② ローカルキーパスフレーズの作成

# twadmin --generate-keys -L /etc/tripwire/${HOSTNAME}-local.key

(When selecting a passphrase, keep in mind that good passphrases typically
have upper and lower case letters, digits and punctuation marks, and are
at least 8 characters in length.)

Enter the local keyfile passphrase: [Password]
Verify the local keyfile passphrase: [Password]
Generating key (this may take several minutes)...Key generation complete.

③サイトキーパスフレーズの作成

# twadmin --generate-keys -S /etc/tripwire/site.key

(When selecting a passphrase, keep in mind that good passphrases typically
have upper and lower case letters, digits and punctuation marks, and are
at least 8 characters in length.)

Enter the site keyfile passphrase: [Password]
Verify the site keyfile passphrase: [Password]
Generating key (this may take several minutes)...Key generation complete.

④ Tripwire の設定

# vi /etc/tripwire/twcfg.txt

最終行に追加
LOOSEDIRECTORYCHECKING =true
REPORTLEVEL =4

⑤Tripwire設定ファイル(暗号署名版)作成

# twadmin -m F -c /etc/tripwire/tw.cfg -S /etc/tripwire/site.key /etc/tripwire/twcfg.txt
Please enter your site passphrase: ← [Site Passphrase]
Wrote configuration file: /etc/tripwire/tw.cfg

Tripwire設定ファイル(テキスト版)削除

# rm -f /etc/tripwire/twcfg.txt

※Tripwire設定ファイル(テキスト版)を復元する場合
# twadmin -m f -c /etc/tripwire/tw.cfg > /etc/tripwire/twcfg.txt

⑥ ポリシーファイルテキスト版作成

# vi /etc/tripwire/twpol.txt

@@section GLOBAL
TWROOT=/usr/sbin;
TWBIN=/usr/sbin;
TWPOL=/etc/tripwire;
TWDB=/var/lib/tripwire;
TWSKEY=/etc/tripwire;
TWLKEY=/etc/tripwire;
TWREPORT=/var/lib/tripwire/report;
HOSTNAME=myhostname;
Device        = +pugsdr-intlbamcCMSH ;
Dynamic       = +pinugtd-srlbamcCMSH ;
Growing       = +pinugtdl-srbamcCMSH ;
IgnoreAll     = -pinugtsdrlbamcCMSH ;
IgnoreNone    = +pinugtsdrbamcCMSH-l ;
ReadOnly      = +pinugtsdbmCM-rlacSH ;
Temporary     = +pugt ;
@@section FS
(
  rulename = "Tripwire Binaries",
)
{
  $(TWBIN)/siggen                      -> $(ReadOnly) ;
  $(TWBIN)/tripwire                    -> $(ReadOnly) ;
  $(TWBIN)/twadmin                     -> $(ReadOnly) ;
  $(TWBIN)/twprint                     -> $(ReadOnly) ;
}
(
  rulename = "Tripwire Data Files",
)
{
  $(TWDB)                              -> $(Dynamic) -i ;
  $(TWPOL)/tw.pol                      -> $(ReadOnly) -i ;
  $(TWPOL)/tw.cfg                      -> $(ReadOnly) -i ;
  $(TWLKEY)/$(HOSTNAME)-local.key      -> $(ReadOnly) ;
  $(TWSKEY)/site.key                   -> $(ReadOnly) ;
  # don't scan the individual reports
  $(TWREPORT)                          -> $(Dynamic) (recurse=0) ;
}
(
  rulename = "Global Configuration Files",
)
{
  /etc                           -> $(IgnoreNone) -SHa ;
}
(
  rulename = "OS Boot Files and Mount Points",
)
{
  /boot                         -> $(ReadOnly) ;
}
(
  rulename = "OS Devices and Misc Directories",
)
{
  /opt                          -> $(Dynamic) ;
}
(
  rulename = "OS Binaries and Libraries",
)
{
  /bin                          -> $(ReadOnly) ;
  /lib                          -> $(ReadOnly) ;
  /lib64                         -> $(ReadOnly) ;
  /sbin                         -> $(ReadOnly) ;
  /usr/bin                      -> $(ReadOnly) ;
  /usr/lib                      -> $(ReadOnly) ;
  /usr/lib64                      -> $(ReadOnly) ;
  /usr/sbin                     -> $(ReadOnly) ;
}
(
  rulename = "User Binaries and Libraries",
)
{
  /usr/local                    -> $(ReadOnly) ;
  /usr/local/bin                -> $(ReadOnly) ;
  /usr/local/etc                -> $(ReadOnly) ;
  /usr/local/include            -> $(ReadOnly) ;
  /usr/local/lib                -> $(ReadOnly) ;
  /usr/local/sbin               -> $(ReadOnly) ;
  /usr/local/share              -> $(ReadOnly) ;
}
(
  rulename = "Root Directory and Files",
)
{
  /root                         -> $(IgnoreNone) -SHa ;
}
(
  rulename = "Monitor Filesystems",
)
{
  /home                         -> $(ReadOnly) ;  # Modify as needed
  /usr                          -> $(ReadOnly) ;
  /var                          -> $(ReadOnly) ;
}

⑦ポリシーファイル設定

# cd /etc/tripwire/
# vi twpolmake.pl

twpolmake.plの内容

#!/usr/bin/perl
#
$POLFILE=$ARGV[0];

open(POL,"$POLFILE") or die "open error: $POLFILE" ;
my($myhost,$thost) ;
my($sharp,$tpath,$cond) ;
my($INRULE) = 0 ;

while (<POL>) {
chomp;
if (($thost) = /^HOSTNAME\s*=\s*(.*)\s*;/) {
$myhost = `hostname` ; chomp($myhost) ;
if ($thost ne $myhost) {
$_="HOSTNAME=\"$myhost\";" ;
}
}
elsif ( /^{/ ) {
$INRULE=1 ;
}
elsif ( /^}/ ) {
$INRULE=0 ;
}
elsif ($INRULE == 1 and ($sharp,$tpath,$cond) = /^(\s*\#?\s*)(\/\S+)\b(\s+->\s+.+)$/) {
$ret = ($sharp =~ s/\#//g) ;
if ($tpath eq '/sbin/e2fsadm' ) {
$cond =~ s/;\s+(tune2fs.*)$/; \#$1/ ;
}
if (! -s $tpath) {
$_ = "$sharp#$tpath$cond" if ($ret == 0) ;
}
else {
$_ = "$sharp$tpath$cond" ;
}
}
print "$_\n" ;
}
close(POL) ;

⑧ポリシーファイル最適化

# perl /etc/tripwire/twpolmake.pl /etc/tripwire/twpol.txt > /etc/tripwire/twpol.txt.new

⑨最適化済ポリシーファイルを元に、ポリシーファイル(暗号署名版)作成

# twadmin -m P -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key /etc/tripwire/twpol.txt.new
Please enter your site passphrase: ←Enter your site passphrase
Wrote policy file: /etc/tripwire/tw.pol

⑩ データベースを作成、動作確認

# tripwire --init
Please enter your local passphrase: ←Enter your local passphrase
Parsing policy file: /etc/tripwire/tw.pol
Generating the database...
*** Processing Unix File System ***
The object: "/var/lib/snapd/snap/certbot/5940" is on a different file system...ignoring.
The object: "/var/lib/snapd/snap/core24/2307" is on a different file system...ignoring.
The object: "/var/lib/snapd/snap/snapd/28332" is on a different file system...ignoring.
The object: "/boot/grub2/i386-pc" is on a different file system...ignoring.
The object: "/boot/grub2/x86_64-efi" is on a different file system...ignoring.
Wrote database file: /var/lib/tripwire/Lepard.twd
The database was successfully generated.

⑪テスト用ファイルを作成し、Tripwire の動作確認

# echo test > /root/test.txt
# tripwire --check

成功すると下記のように表示される

Parsing policy file: /etc/tripwire/tw.pol
*** Processing Unix File System ***
Performing integrity check...
The object: "/var/lib/snapd/snap/certbot/5940" is on a different file system...ignoring.
The object: "/var/lib/snapd/snap/core24/2307" is on a different file system...ignoring.
The object: "/var/lib/snapd/snap/snapd/28332" is on a different file system...ignoring.
The object: "/boot/grub2/i386-pc" is on a different file system...ignoring.
The object: "/boot/grub2/x86_64-efi" is on a different file system...ignoring.
Wrote report file: /var/lib/tripwire/report/Lepard-20261119-084928.twr


Open Source Tripwire(R) 2.4.3.7 Integrity Check Report

Report generated by:          root
Report created on:            Thu 19 Nov 2026 08:49:28 AM JST
Database last updated on:     Never

===============================================================================
Report Summary:
===============================================================================

Host name:                    Lepard
Host IP address:              Unknown IP
Host ID:                      None
Policy file used:             /etc/tripwire/tw.pol
Configuration file used:      /etc/tripwire/tw.cfg
Database file used:           /var/lib/tripwire/Lepard.twd
Command line used:            tripwire --check 

===============================================================================
Rule Summary: 
===============================================================================

-------------------------------------------------------------------------------
  Section: Unix File System
-------------------------------------------------------------------------------

  Rule Name                       Severity Level    Added    Removed  Modified 
  ---------                       --------------    -----    -------  -------- 
* Monitor Filesystems             0                 0        0        9        
  OS Binaries and Libraries       0                 0        0        0        
  Tripwire Binaries               0                 0        0        0        
  User Binaries and Libraries     0                 0        0        0        
  (/usr/local)
* Tripwire Data Files             0                 1        0        0        
  Global Configuration Files      0                 0        0        0        
  (/etc)
  OS Boot Files and Mount Points  0                 0        0        0        
  (/boot)
* Root Directory and Files        0                 1        0        0        
  (/root)

Total objects scanned:  88563
Total violations found:  11

===============================================================================
Object Summary: 
===============================================================================

-------------------------------------------------------------------------------
# Section: Unix File System
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
Rule Name: Monitor Filesystems (/var)
Severity Level: 0
-------------------------------------------------------------------------------

Modified:
"/var/lib/nagios/status.dat"
"/var/log/apache2/suse.korodes.com.access.log"
"/var/log/journal/fdf2421d0293444c92a13fbe31fd26c7/system.journal"
"/var/log/mail"
"/var/log/mail.info"
"/var/log/messages"
"/var/log/suricata/eve.json"
"/var/log/suricata/stats.log"
"/var/log/vmware-vmsvc-root.log"

-------------------------------------------------------------------------------
Rule Name: Tripwire Data Files (/var/lib/tripwire)
Severity Level: 0
-------------------------------------------------------------------------------

Added:
"/var/lib/tripwire/Lepard.twd"

-------------------------------------------------------------------------------
Rule Name: Root Directory and Files (/root)
Severity Level: 0
-------------------------------------------------------------------------------

Added:
"/root/test.txt"

===============================================================================
Error Report: 
===============================================================================

No Errors

-------------------------------------------------------------------------------
*** End of report ***

Open Source Tripwire 2.4 Portions copyright 2000-2018 Tripwire, Inc.  Tripwire is a registered
trademark of Tripwire, Inc. This software comes with ABSOLUTELY NO WARRANTY;
for details use --version. This is free software which may be redistributed
or modified only under certain conditions; see COPYING for details.
All rights reserved.
Integrity check complete.

テスト用ファイルを削除

# rm -f /root/test.txt

1.2 Tripwire を定期実行させる

①Tripwire メール通知用自動実行スクリプト作成

# cd /srv/www/system
# vi tripwire.sh

「tripwire.sh」の内容
パスフレーズ設定のLOCALPASS、SITEPASS それぞれの「xxxxxxxx」に設定したローカルパスフレーズ、サイトパスフレーズを入力

#!/bin/bash
PATH=/usr/sbin:/usr/bin:/bin:/usr/local/tripwire/sbin

# パスフレーズ設定
LOCALPASS=xxxxx # ローカルパスフレーズ
SITEPASS=xxxxx # サイトパスフレーズ

#通知先メールアドレス指定
MAIL="mail address"

cd /etc/tripwire

# Tripwireチェック実行
tripwire -m c -s -c tw.cfg|mail -s "Tripwire(R) Integrity Check Report in `hostname`" $MAIL

# ポリシーファイル最新化
twadmin --create-polfile -S /etc/tripwire/site.key -Q $SITEPASS /etc/tripwire/twpol.txt
rm -f twpol.txt* *.bak

# データベース最新化
rm -f /var/lib/tripwire/*.twd*
tripwire --init -P $LOCALPASS
# chmod 700 tripwire.sh

②Tripwire が定期的に実行されるようcron に追加

# crontab -e
0 3 * * * /srv/www/system/tripwire.sh

下記コマンドを実行し、指定のメールアドレスに通知が届くことを確認する

# /srv/www/system/tripwire.sh

2. Logwatch

① Logwatch インストール

# zypper -n install logwatch

② 設定ファイルの編集
サンプルファイルをインストールディレクトリーにコピーし、編集する

# cat /usr/share/logwatch/default.conf/logwatch.conf >> /etc/logwatch/conf/logwatch.conf

# vi /etc/logwatch/conf/logwatch.conf
77 行目 : 追加 通知を受け取りたいメールアドレスを設定
#MailTo = root
MailTo = <mail.address>

116 行目 : 追加 ログ通知の詳細度を設定
#Detail = Low
Detail = High

③ Logwatch のレポートを出力

# logwatch --output stdout

################### Logwatch 7.15 (07/22/26) #################### 
        Processing Initiated: Thu Nov 19 09:31:07 2026
        Date Range Processed: yesterday
                              ( 2026-Nov-18 )
                              Period is day.
        Detail Level of Output: 10
        Type of Output/Format: stdout / text
        Logfiles for Host: Lepard
 ################################################################## 
------------------------Omit----------------------------------

 --------------------- lm_sensors output Begin ------------------------ 

 No sensors found!
 Make sure you loaded all the kernel drivers you need.
 Try sensors-detect to find out which these are.
 
 ---------------------- lm_sensors output End ------------------------- 

 
 ###################### Logwatch End ######################### 

下記のような表示があった場合は、該当行のPerlを書き換えます
これは、Perl 5.42以降で追加された演算子優先順位に関する警告です。論理否定演算子 ! の優先順位が比較演算子よりも高いために発生します。

Possible precedence problem between ! and string eq at /usr/lib/perl5/vendor_perl/5.42.1/Date/Manip/Delta.pm line 2712.


Possible precedence problem between ! and string eq at /usr/lib/perl5/vendor_perl/5.42.1/Date/Manip/Delta.pm line 1117.

次のように書き換える

# vi /usr/lib/perl5/vendor_perl/5.42.1/Date/Manip/Date.pm
2712行目
if (! ref($date) eq 'Date::Manip::Date') {  → if (! (ref($date) eq 'Date::Manip::Date')) {

# vi /usr/lib/perl5/vendor_perl/5.42.1/Date/Manip/Delta.pm
1117行目
if (! ref($delta) eq 'Date::Manip::Delta') {  → if (! (ref($delta) eq 'Date::Manip::Delta')) {

④ 設定したアドレスにレポートが届くかテストを行う

# logwatch --output mail

これで指定したメールアドレスにレポートが届きます