[Server] Tripwire

インストール

# wget http://jaist.dl.sourceforge.net/sourceforge/tripwire/tripwire-2.4.1.1-src.tar.bz2

# tar jxvf tripwire-2.4.1.1-src.tar.bz2
# cd tripwire-2.4.1.1

twadmin -m G -S /etc/tripwire# vi install/install.cfg

TWPOLICY="/etc/tripwire"
TWDB="/var/lib/tripwire"

# ./configure
# make
# make install

設定

# vi /etc/tripwire/twpolmake.rb

#!/usr/bin/env ruby

in_rule = false;
ARGF.each do |line|
  line.chomp!
  if line =~ /^\{/
    in_rule = true
  elsif line =~ /^\}/
    in_rule = false
  elsif in_rule and line =~ /^(\s*\#?\s*)(\/\S+)\b(\s+->\s+.+)$/
    sharp = $1
    path = $2
    cond = $3
    if File.exist?(path)
      line = "#{sharp.gsub(/\#/, '')}#{path}#{cond}"
    else
      line = "#{sharp}\##{path}#{cond}" if sharp !~ /\#/
    end
  end
  puts line
end
最適化

# cat /etc/tripwire/twpol.txt | ruby /etc/tripwire/twpolmake.rb > /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

DB作成

# tripwire -m i -s -c /etc/tripwire/tw.cfg
# rm -f /etc/tripwire/*.txt

定期ファイル作成

# vi tripwire.sh

#!/bin/bash

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

# パスフレーズ設定
LOCALPASS=******** # ローカルキーファイルパスフレーズ
SITEPASS=********  # サイトキーファイルパスフレーズ
MAILTO=root        # チェック結果をメールで送る際の送信先

cd /etc/tripwire

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

# ポリシーファイル最新化
twadmin -m p -c tw.cfg -p tw.pol -S site.key | ruby twpolmake.rb > twpol.txt.new
twadmin -m P -c tw.cfg -p tw.pol -S site.key -Q $SITEPASS twpol.txt.new > /dev/null
rm -f twpol.txt*
rm -f *.bak

# データベース最新化
rm -f /var/lib/tripwire/*.twd*
tripwire -m i -s -c tw.cfg -P $LOCALPASS

# chmod 700 tripwire.sh
# mv tripwire.sh /etc/cron.daily