■ FC2~FC6 / Fedora7 / Fedora8 / Fedora9
Tripwireはサーバーのファイルの改竄を検知するシステム。 Tripwireを使用すると、重要なシステムファイルとディレクトリに対する変更をすべて検出することで、それらの保全性を確保することができる。セキュリティを万全にするために、ファイルが改竄される前に、Tripwireをインストールして基準データベースを作成しておく。基準データベースが作成されると、Tripwireは現在のファイルをこれと比較し、変更、追加、削除のいずれかがあれば報告するようにする。
■Tripwireのインストール
* Fedora7 / Fedora8 / Fedora9
[root@linux ~]# yum -y install tripwire
* FC2~FC6
Tripwireをダウンロード (最新版 をダウンロード)
[root@linux ~]# wget http://keihanna.dl.sourceforge.net/sourceforge/tripwire/tripwire-2.4.0.1-x86-bin.tar.bz2 ダウンロードしたtripwireを展開 [root@linux ~]# tar jxvf tripwire-2.4.0.1-x86-bin.tar.bz2 Tripwireの展開先ディレクトリへ移動 [root@linux ~]# cd tripwire-2.4.0.1-x86-bin Tripwireの実行コマンドを/usr/sbin/へコピー [root@linux tripwire-2.4.0.1-x86-bin]# cp bin/* /usr/sbin/ Tripwireの設定ファイルのディレクトリを作成[root@linux tripwire-2.4.0.1-x86-bin]# mkdir /etc/tripwire ポリシーファイルをTripwireの設定ファイルのディレクトリへコピー[root@linux tripwire-2.4.0.1-x86-bin]# cp policy/twpol-Linux.txt /etc/tripwire/twpol.txt データベースのディレクトリを作成 [root@linux tripwire-2.4.0.1-x86-bin]# mkdir -p /var/lib/tripwire/report Tripwireの展開先ディレクトリを削除 [root@linux tripwire-2.4.0.1-x86-bin]# cd [root@linux ~]# rm -rf tripwire-2.4.0.1-x86-bin ダウンロードしたファイルを削除 [root@linux ~]# rm -f tripwire-2.4.0.1-x86-bin.tar.bz2
■Tripwireの設定
サイトキーを作成 [root@linux ~]# twadmin -m G -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: ← サイトパスフレーズを設定 Verify the site keyfile passphrase: ← サイトパスフレーズを再度入力 Generating key (this may take several minutes)...Key generation complete. ローカルキーを作成 [root@linux ~]# twadmin -m G -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: ← ローカルパスフレーズを設定 Verify the local keyfile passphrase: ← ローカルパスフレーズを再度入力 Generating key (this may take several minutes)...Key generation complete. 設定ファイル(テキスト版)を作成 [root@linux ~]# vi /etc/tripwire/twcfg.txt ROOT =/usr/sbin POLFILE =/etc/tripwire/tw.pol DBFILE =/var/lib/tripwire/$(HOSTNAME).twd REPORTFILE =/var/lib/tripwire/report/$(HOSTNAME)-$(DATE).twr SITEKEYFILE =/etc/tripwire/site.key LOCALKEYFILE =/etc/tripwire/$(HOSTNAME)-local.key EDITOR =/bin/vi LATEPROMPTING =false LOOSEDIRECTORYCHECKING =false ↓ LOOSEDIRECTORYCHECKING =true MAILNOVIOLATIONS =true EMAILREPORTLEVEL =3 REPORTLEVEL =3 ↓ REPORTLEVEL =4 MAILMETHOD =SENDMAIL SYSLOGREPORTING =false ↓ SYSLOGREPORTING =true MAILPROGRAM =/usr/sbin/sendmail -oi -t 設定ファイル(テキスト版⇒暗号署名版)を作成 [root@linux ~]# 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 セキュリティ確保のため設定ファイル(テキスト版)を削除 [root@linux ~]# rm -f /etc/tripwire/twcfg.txt 設定ファイル(テキスト版)を復活させる場合は以下のコマンドで復活できる [root@linux ~]# twadmin --print-cfgfile > /etc/tripwire/twcfg.txt
■ポリシーファイルの設定
ポリシーファイル(テキスト版)を編集
[root@linux ~]# vi /etc/tripwire/twpol.txt
各変数のパスを設定
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=linux.yokensaka.com;
ポリシーファイルの最適化スクリプトを作成
[root@linux ~]# vi /etc/tripwire/twpolmake.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 twpolmake.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) ;
ポリシーファイルの最適化
[root@linux ~]# perl /etc/tripwire/twpolmake.pl /etc/tripwire/twpol.txt > /etc/tripwire/twpol.txt.new
ポリシーファイル(暗号署名版)を作成
[root@linux ~]# 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: ← サイトパスフレーズを入力
Wrote policy file: /etc/tripwire/tw.pol
ポリシーファイル(テキスト版)を削除
[root@linux ~]# rm -f /etc/tripwire/twpol.txt*
ポリシーファイル(テキスト版)を復活させる場合は以下のコマンドで復活できる
[root@linux ~]# twadmin -m p -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key > /etc/tripwire/twpol.txt
■Tripwireのデータベース作成
ポリシーファイルよりデータベースを作成 [root@linux ~]# tripwire -m i -s -c /etc/tripwire/tw.cfg Please enter your local passphrase: ← ローカルパスフレーズを入力 ※データベースを作成するには結構時間がかかる
■Tripwireの確認
ファイル変更をチェック ※結構時間がかかる [root@linux ~]# tripwire -m c -s -c /etc/tripwire/tw.cfg Tripwire(R) 2.4.1 Integrity Check Report Report generated by: root Report created on: 2008年05月17日 00時06分35秒 Database last updated on: Never =============================================================================== Report Summary: =============================================================================== Host name: linux.yokensaka.com Host IP address: 60.46.228.222 Host ID: None Policy file used: /etc/tripwire/tw.pol Configuration file used: /etc/tripwire/tw.cfg Database file used: /var/lib/tripwire/linux.yokensaka.com.twd Command line used: tripwire -m c -s -c /etc/tripwire/tw.cfg =============================================================================== Rule Summary: =============================================================================== ------------------------------------------------------------------------------- Section: Unix File System ------------------------------------------------------------------------------- Rule Name Severity Level Added Removed Modified --------- -------------- ----- ------- -------- * Tripwire Data Files 0 1 0 0 * Monitor Filesystems 0 0 0 4 OS Binaries and Libraries 0 0 0 0 Tripwire Binaries 0 0 0 0 User Binaries and Libraries 0 0 0 0 Temporary Directories 0 0 0 0 RPM Checksum Files 0 0 0 0 System Boot Changes 0 0 0 0 Global Configuration Files 0 0 0 0 OS Boot Files and Mount Points 0 0 0 0 OS Devices and Misc Directories 0 0 0 0 Root Directory and Files 0 0 0 0 Total objects scanned: 126788 Total violations found: 5 =============================================================================== Object Summary: =============================================================================== ------------------------------------------------------------------------------- # Section: Unix File System ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- Rule Name: Monitor Filesystems (/var) Severity Level: 0 ------------------------------------------------------------------------------- Modified: "/var/lib/awstats/awstats062007.localhost.localdomain.txt" "/var/lib/ntp/drift" "/var/spool/postfix/public/pickup" "/var/spool/postfix/public/qmgr" ------------------------------------------------------------------------------- Rule Name: Tripwire Data Files (/var/lib/tripwire) Severity Level: 0 ------------------------------------------------------------------------------- Added: "/var/lib/tripwire/linux.yokensaka.com.twd" =============================================================================== Error Report: =============================================================================== No Errors ------------------------------------------------------------------------------- *** End of report *** Tripwire 2.4 Portions copyright 2000 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.
■Tripwireの定期自動実行設定
Tripwireの定期実行スクリプトを作成 [root@linux ~]# vi tripwire.sh #!/bin/bash PATH=/usr/sbin:/usr/bin:/bin # パスフレーズの設定 LOCALPASS=xxxxxxxx # ローカルパスフレーズを入力 SITEPASS=xxxxxxxx # サイトパスフレーズを入力 cd /etc/tripwire # Tripwireのチェック tripwire -m c -s -c tw.cfg|mail -s "Tripwire(R) Integrity Check Report `hostname`" root # ポリシーファイルの最新化 twadmin -m p -c tw.cfg -p tw.pol -S site.key > twpol.txt perl twpolmake.pl twpol.txt > 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 実行スクリプトに実行権を与える [root@linux ~]# chmod 700 tripwire.sh cronを編集 [root@linux ~]# crontab -e 00 01 * * * /root/tripwire.sh 毎日1:00にTripwireの定期実行スクリプトを実行