Tripwireのインストール

概要:ファイル改竄検知システム(Tripwire) をインストールする。
前提:

1. Tripwireのソースのダウンロード

# cd /tmp/work
# wget http://jaist.dl.sourceforge.net/sourceforge/tripwire/tripwire-2.4.2-src.tar.bz2

注:最新版のURLはダウンロードページ[http://sourceforge.net/projects/tripwire/]で確認すること。

2. TripwireのInstall

# tar jxvf tripwire-2.4.2-src.tar.bz2 ← tripwire展開
# cd tripwire-2.4.2-src ← tripwire展開先ディレクトリへ移動
# ./configure --prefix=/usr/local/tripwire sysconfdir=/etc/tripwire && make && make install
  ← tripwireインストール
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
  :
  :
Installer program for:
Tripwire(R) 2.4 Open Source

Copyright (C) 1998-2000 Tripwire (R) Security Systems, Inc.  Tripwire (R)
is a registered trademark of the Purdue Research Foundation and is
licensed exclusively to Tripwire (R) Security Systems, Inc.


LICENSE AGREEMENT for Tripwire(R) 2.4 Open Source

Please read the following license agreement.  You must accept the
agreement to continue installing Tripwire.

Press ENTER to view the License Agreement. ← 空ENTER SPACEキー押下でライセンス表示を流す


                    GNU GENERAL PUBLIC LICENSE
                       Version 2, June 1991
                                :
                                :
Please type "accept" to indicate your acceptance of this
license agreement. [do not accept] accept ← accept応答
Using configuration file ./install/install.cfg

Checking for programs specified in install configuration file....

/usr/sbin/sendmail -oi -t exists.  Continuing installation.

/bin/vi exists.  Continuing installation.


----------------------------------------------
Verifying existence of binaries...

./bin/siggen found
./bin/tripwire found
./bin/twprint found
./bin/twadmin found

This program will copy Tripwire files to the following directories:

        TWBIN: /usr/local/tripwire/sbin
        TWMAN: /usr/local/tripwire/man
     TWPOLICY: /etc/tripwire
     TWREPORT: /usr/local/tripwire/lib/tripwire/report
         TWDB: /usr/local/tripwire/lib/tripwire
 TWSITEKEYDIR: /etc/tripwire
TWLOCALKEYDIR: /etc/tripwire

CLOBBER is false.

Continue with installation? [y/n] y ← y応答

----------------------------------------------
Creating directories...

/usr/local/tripwire/sbin: already exists
/etc/tripwire: created
/usr/local/tripwire/lib/tripwire/report: created
/usr/local/tripwire/lib/tripwire: already exists
/etc/tripwire: already exists
/etc/tripwire: already exists
/usr/local/tripwire/man: created
/usr/local/tripwire/doc/tripwire: created

----------------------------------------------
Copying files...

/usr/local/tripwire/doc/tripwire/COPYING: copied
/usr/local/tripwire/doc/tripwire/TRADEMARK: copied
/usr/local/tripwire/doc/tripwire/policyguide.txt: copied
/etc/tripwire/twpol-Linux.txt: copied

----------------------------------------------
The Tripwire site and local passphrases are used to
sign a variety of files, such as the configuration,
policy, and database files.

Passphrases should be at least 8 characters in length
and contain both letters and numbers.

See the Tripwire manual for more information.

----------------------------------------------
Creating key files...

(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: ← 任意のサイトパスフレーズ応答  : sitepasswd
Verify the site keyfile passphrase: ← 任意のサイトパスフレーズ応答(確認)
Generating key (this may take several minutes)...Key generation complete.

(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: ← 任意のローカルパスフレーズ応答 : localpasswd
Verify the local keyfile passphrase: ← 任意のローカルパスフレーズ応答(確認)
Generating key (this may take several minutes)...Key generation complete.

----------------------------------------------
Generating Tripwire configuration file...

----------------------------------------------
Creating signed configuration file...
Please enter your site passphrase: ← サイトパスフレーズ応答
Wrote configuration file: /etc/tripwire/tw.cfg

A clear-text version of the Tripwire configuration file
/etc/tripwire/twcfg.txt
has been preserved for your inspection.  It is recommended
that you delete this file manually after you have examined it.


----------------------------------------------
Customizing default policy file...

----------------------------------------------
Creating signed policy file...
Please enter your site passphrase: ← サイトパスフレーズ応答
Wrote policy file: /etc/tripwire/tw.pol

A clear-text version of the Tripwire policy file
/etc/tripwire/twpol.txt
has been preserved for your inspection.  This implements
a minimal policy, intended only to test essential
Tripwire functionality.  You should edit the policy file
to describe your system, and then use twadmin to generate
a new signed copy of the Tripwire policy.


----------------------------------------------
The installation succeeded.

Please refer to
for release information and to the printed user documentation
for further instructions on using Tripwire 2.4 Open Source.

make[3]: ディレクトリ `/tmp/work/tripwire-2.4.2-src' から出ます
make[2]: ディレクトリ `/tmp/work/tripwire-2.4.2-src' から出ます
make[1]: ディレクトリ `/tmp/work/tripwire-2.4.2-src' から出ます

# cd ← rootのHOMEディレクトリーに移動
# echo PATH=$PATH:/usr/local/tripwire/sbin >> .bashrc ← tripwire実行ファイル格納ディレクトリへパスを通す
# . ./.bashrc ← .bashrcを実行して有効にする。初めのピリオッドに注意。

3. manのPATH設定

# vi /etc/man.config
  :
MANPATH /usr/local/tripwire/share/man ← 最終行に追加する。
# man tripwire ← manの設定の確認。

4. Tripwire設定
概要:
 設定ファイル   twcfg.txt → twcfg.txt(修正) → tw.cfg(暗号化)
 ポリシーファイル twpol.txt → twpol.txt(修正) → twpol.txt.tmp(最適化) → tw.pol(暗号化)
 テキスト版のtwcfg.txtとtwpol.txt、twpol.txt.tmpは暗号化後削除する。

  1. ) Tripwire設定
    # vi /etc/tripwire/twcfg.txt ← Tripwire設定ファイル(テキスト版)修正
    
    ROOT          =/usr/local/tripwire/sbin
    POLFILE       =/etc/tripwire/tw.pol
    DBFILE        =/usr/local/tripwire/lib/tripwire/$(HOSTNAME).twd
    REPORTFILE    =/usr/local/tripwire/lib/tripwire/report/$(HOSTNAME)-$(DATE).twr
            ← Databaseの更新の場合、Reportファイル名も同じであることが必要。
    REPORTFILE    =/usr/local/tripwire/lib/tripwire/report/$(HOSTNAME).twr
    SITEKEYFILE   =/etc/tripwire/site.key
    LOCALKEYFILE  =/etc/tripwire/ホスト名-local.key    ← ホスト名を変更した場合変更が必要。
    EDITOR        =/bin/vi
    LATEPROMPTING =false
    LOOSEDIRECTORYCHECKING =false
            ← ファイル変更時に所属ディレクトリの変更を通知しないようにする
    LOOSEDIRECTORYCHECKING =true
    MAILNOVIOLATIONS =true
            ← ファイル変更チェック結果レポートレベルの変更
    MAILNOVIOLATIONS =false
    EMAILREPORTLEVEL =3
            ← ファイル変更チェック結果レポートレベルの変更
    EMAILREPORTLEVEL =4
    REPORTLEVEL   =3
            ← ファイル変更チェック結果レポートレベルの変更
    REPORTLEVEL   =4
    MAILMETHOD    =SENDMAIL
    SYSLOGREPORTING =false
    MAILPROGRAM   =/usr/sbin/sendmail -oi -t
    
  2. ) Tripwire設定ファイル(暗号署名版)作成
    # twadmin -m F -c /etc/tripwire/tw.cfg -S /etc/tripwire/site.key /etc/tripwire/twcfg.txt
    Please enter your site passphrase: ← サイトパスフレーズ応答
    Wrote configuration file: /etc/tripwire/tw.cfg
    
    # rm -f /etc/tripwire/twcfg.txt ← Tripwire設定ファイル(テキスト版)削除
    
    ※Tripwire設定ファイル(テキスト版)を復元する場合
    # twadmin -m f -c /etc/tripwire/tw.cfg > /etc/tripwire/twcfg.txt
    
  3. ) ポリシーファイル設定
    1. ポリシーファイルの修正
      # vi /etc/tripwire/twpol.txt ← 設定ファイルの編集
      
      @@section GLOBAL
      各変数を以下のように指定。twcfg.txtの内容と合わせる。
      TWROOT="/usr/local/tripwire/sbin";
      TWBIN="/usr/local/tripwire/sbin";
      TWPOL="/etc/tripwire";
      TWDB="/usr/local/tripwire/lib/tripwire";
      TWSKEY="/etc/tripwire";
      TWLKEY="/etc/tripwire";
      TWREPORT="/usr/local/tripwire/lib/tripwire/report";
      HOSTNAME="ホスト名";       ← ホスト名を変更した場合変更が必要。
        :
        :
      ( emailto = root ) ← メールを送信するため追加
      { ← 追加
      # Tripwire Binaries
         :
         :
      }
      } ← 最終行に追加
      
    2. ポリシーファイル最適化スクリプト作成
      デフォルトのポリシーファイルでは存在しないファイルのチェックが有効であったり、存在するファイルのチェックが無効になっている。 そこで、和泉宏明氏の作成された Perlスクリプトを利用し、ポリシーファイルを作成する。
      # vi /etc/tripwire/tripwire_pol.pl ← ポリシーファイル最適化スクリプト作成
      
      #!/usr/bin/perl
      # Tripwire Policy File customize tool
      # ----------------------------------------------------------------
      # Copyright (C) 2003 Hiroaki Izumi
      # This program is free software; you can redistribute it and/or
      # modify it under the terms of the GNU General Public License
      # as published by the Free Software Foundation; either version 2
      # of the License, or (at your option) any later version.
      # This program is distributed in the hope that it will be useful,
      # but WITHOUT ANY WARRANTY; without even the implied warranty of
      # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      # GNU General Public License for more details.
      # You should have received a copy of the GNU General Public License
      # along with this program; if not, write to the Free Software
      # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
      # ----------------------------------------------------------------
      # Usage:
      #    perl tripwire_pol.pl {Pol file}
      # ----------------------------------------------------------------
      #
      $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) ;
      
    3. ポリシーファイル最適化
      # perl /etc/tripwire/tripwire_pol.pl /etc/tripwire/twpol.txt > /etc/tripwire/twpol.txt.tmp
      # diff twpol.txt twpol.txt.tmp ← 変更内容の表示
      
    4. ポリシーファイルの暗号化
      # twadmin -m P -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key /etc/tripwire/twpol.txt.tmp
      Please enter your site passphrase: ← サイトパスフレーズ応答
      Wrote policy file: /etc/tripwire/tw.pol
      
      ※ポリシーファイル(テキスト版)を復元する場合
      # twadmin -m p > /etc/tripwire/twpol.txt
      
    5. データベース作成
      # tripwire -m i -s -c /etc/tripwire/tw.cfg
        Please enter your local passphrase: ← ローカルパスフレーズ応答
      #                              ← データベース作成に時間がかかる。
      
        オプションの説明
        -m i       : Database初期化モード
        -s         : Silent出力モード
        -c cfgfile : 指定設定ファイル(cfgfile)を使用
        -m c       : 整合性チェックモード ← 定期自動実行設定で使用
        -m u       : Database更新モード  ← 定期自動実行設定で使用
      

5. Tripwire確認

# tripwire -m c -s -c /etc/tripwire/tw.cfg ← Tripwireチェック実行
  時間がかかる。
# echo test > test.txt ← 試しにテストファイルを作成する
# tripwire -m c -s -c /etc/tripwire/tw.cfg ← Tripwireチェック再実行

# rm -f test.txt ← テストファイル削除(後始末)

6. メール送信のテスト

# tripwire --test --email root@localhost ← 例)送信先がroot@localhost

メールが届いているか確認する。

7. Tripwire定期自動実行設定

# vi tripwire.sh ← Tripwire定期自動実行スクリプト作成
#!/bin/bash

PATH=/usr/sbin:/usr/bin:/bin:/usr/local/tripwire/sbin

# パスフレーズ設定
LOCALPASS=xxxxxxxx # ローカルパスフレーズ

cd /etc/tripwire

# Tripwireチェック実行
tripwire -m c -s -c tw.cfg -M

# データベース更新
tripwire -m u -s -c tw.cfg -a -P $LOCALPASS

Tripwire定期自動実行スクリプトの実行権限付加

# chmod 700 tripwire.sh

CRONへの登録

# vi /etc/cron.d/tripwire
0 5 * * * root /root/tripwire.sh ← 毎日5:00に実行する場合

8. Tripwireの運用
Tripwireの運用については、ITmediaエンタープライズの以下の記事を参考にする。
第5回 Tripwireを運用するときの注意点 [ http://www.itmedia.co.jp/enterprise/0212/06/epn03.html ]


最終更新のRSS
Last-modified: 2014-03-11 (火) 01:59:57 (3693d)