Last-modified: 2011-12-26 (月) 01:24:46
tripwire/CentOSへのインストール

概要

変更監視ツール tripwireをインストールする。

手順

  1. tripwireをインストールする。
    Everything is expanded.Everything is shortened.
      1
    
     
    
    yum install tripwire
  2. 初期設定を行う。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
    
    -
    !
     
    -
    |
    
    # 初期設定開始
    tripwire-setup-keyfiles
     
    # サイトパスフレーズを登録する
    # ローカルパスフレーズを登録する
    
  3. ポリシーファイルを調整するための確認を行う。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
    
    -
    !
    -
    !
    -
    !
     
    -
    |
    
    # DB初期化
    tripwire --init
    # チェック結果をresult.txtへリダイレクト
    tripwire --check > result.txt 2>&1
    # 失敗したパスを一覧表示する
    grep "### Filename" result.txt
     
    # 失敗している原因は、ポリシーファイルに書かれたパスが存在しないため。
    # このエラーはチェック時にも毎回表示されて見にくいので、ポリシーファイルを調整する。
    
  4. /etc/tripwire/twpol.txtを編集する。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
    
    -
    |
    |
    |
    
    # twpol.txtは平文状態のポリシーファイル。実際に使用されるのはtw.pol。
    # 同じくtwcfg.txtは平文状態の設定ファイルで、使用されるのはtw.cfg。
    # 先ほどエラーとなったパスを探してコメントアウトする。
    # 監視したいパスがあれば追加する。
    
  5. /etc/tripwire/twpol.txtを編集する。
    Everything is expanded.Everything is shortened.
      1
      2
    
    -
    !
    
    # ファイルの変更で親ディレクトリの変更を報告しない
    LOOSEDIRECTORYCHECKING =true
  6. 設定を反映する。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
    
    -
    !
    -
    !
    
    # twpol.txtからtw.polを作成
    twadmin -m P -S site.key twpol.txt
    # twcfg.txtからtw.cfgを作成
    twadmin -m F -S site.key twcfg.txt
  7. 再確認後、チェックを実行する。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
    
    -
    !
    -
    !
    
    # DB初期化
    tripwire --init
    # チェック
    tripwire --check
  8. 不要ファイル(*.txt、*.bak)を削除する。
    Everything is expanded.Everything is shortened.
      1
      2
    
     
     
    
    rm *.txt
    rm *.bak
  9. 私の環境ではtripwire_d.shを使用して定期実行を行っている。

補足

  1. /etc/tripwire/twpol.txtを編集。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
    
    -
    |
    !
    -
    !
     
     
    -
    |
    !
    -
    !
     
     
    -
    |
    |
    !
     
     
     
     
    -
    !
     
    
    # レポート送信先のメールアドレスを設定する。
    # アドレスをemailtoで設定し、括弧で適用範囲(ここでは全てを対象とする)を囲む。
     
    # 例.
    ファイル先頭
    ・・・
    SIG_HI        = 100 ;                # Critical files that are
    # significant points of
    # vulnerability
     
    # メール送信設定
    ( emailto = [email protected] )
    {
     
    #
    # Tripwire Binaries
    #
    (
        rulename = "Tripwire Binaries",
        severity = $(SIG_HI)
    )
    ・・・
    # メール送信設定閉じ括弧
    }
    ファイル末尾
  2. /etc/tripwire/twpol.txtを編集する。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
    
    -
    !
    -
    !
    
    # メール送信プロトコル
    MAILMETHOD    =SENDMAIL
    # メール送信プログラムパス
    MAILPROGRAM   =/usr/sbin/sendmail -oi -t
  3. 設定を反映する。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
    
    -
    !
    -
    !
    
    # twpol.txtからtw.polを作成
    twadmin -m P -S site.key twpol.txt
    # twcfg.txtからtw.cfgを作成
    twadmin -m F -S site.key twcfg.txt
  4. /etc/cron.daily/tripwire-checkを開く。
    デフォルトスクリプトではメールでレポートを飛ばさないうえ、DB初期化処理も入っていないので書き直す。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
    
    -
    !
     
     
     
     
     
     
    -
    !
    -
    !
    
    #!/bin/sh
     
    tripwire=/usr/sbin/tripwire
     
    [ -x $tripwire ] || exit 0
     
    umask 027
     
    # チェック実行
    tripwire --check --quiet --email-report
    # DB初期化
    tripwire --init -P [ローカルパスフレーズ]
  5. /etc/cron.daily/tripwireにローカルパスフレーズを直書きするので、アクセス権限を変更
    Everything is expanded.Everything is shortened.
      1
    
     
    
    chmod 700 /etc/cron.daily/tripwire-check

検証時の環境