| トップ | Solaris | FreeBSD | Gentoo | CentOS | Fedora | Windows | Tips | 自宅サーバの動作確認 | サイト内検索(Namazu) | サイト内検索(HE) |
ファイルの改竄を検知する為に「Tripwire」を導入する。
Fedora Core 5の場合
[root@Fedora ~]# wget http://jaist.dl.sourceforge.net/sourceforge/tripwire/tripwire-2.4.0.1-x86-bin.tar.bz2 <= 「Tripwire」のダウンロード [root@Fedora ~]# tar jxf tripwire-2.4.0.1-x86-bin.tar.bz2 <= ダウンロードしたファイルの展開 [root@Fedora ~]# cd tripwire-2.4.0.1-x86-bin <= 展開したディレクトリへ移動 各種ファイルをコピーする [root@Fedora tripwire-2.4.0.1-x86-bin]# cp bin/* /usr/sbin/ <= 実行コマンドのコピー [root@Fedora tripwire-2.4.0.1-x86-bin]# cp man/man4/*.4 /usr/share/man/man4/ <= オンラインマニュアルのコピー [root@Fedora tripwire-2.4.0.1-x86-bin]# cp man/man5/*.5 /usr/share/man/man5/ <= オンラインマニュアルのコピー [root@Fedora tripwire-2.4.0.1-x86-bin]# cp man/man8/*.8 /usr/share/man/man8/ <= オンラインマニュアルのコピー [root@Fedora tripwire-2.4.0.1-x86-bin]# mkdir /etc/tripwire <= 設定ファイル格納ディレクトリの作成 [root@Fedora tripwire-2.4.0.1-x86-bin]# cp policy/twpol-Linux.txt /etc/tripwire/twpol.txt <= ポリシーファイルのコピー [root@Fedora tripwire-2.4.0.1-x86-bin]# cp policy/policyguide.txt /etc/tripwire/ <= ポリシーファイル作成ガイドのコピー [root@Fedora tripwire-2.4.0.1-x86-bin]# mkdir -p /var/lib/tripwire/report <= データベース格納ディレクトリの作成 [root@Fedora tripwire-2.4.0.1-x86-bin]# cd ../ <= 展開先ディレクトリを抜ける [root@Fedora ~]# rm -rf tripwire-2.4.0.1-x86-bin <= 展開したディレクトリの削除 [root@Fedora ~]# rm -f tripwire-2.4.0.1-x86-bin.tar.bz2 <= ダウンロードしたパッケージの削除 |
Fedora Core 4の場合
[root@Fedora ~]# yum -y install tripwire <= 「Tripwire」のインストール [root@Fedora ~]# yum clean packages <= ダウンロードしたパッケージの削除 |
Fedora Core 3の場合
[root@Fedora ~]# vi /etc/yum.repos.d/fedora-extras.repo <= Fedora Extrasのyum用リポジトリ設定ファイルの作成 [extras] name=Fedora Extras - $releasever - $basearch baseurl=http://download.fedora.redhat.com/pub/fedora/linux/extras/$releasever/$basearch/ gpgcheck=1 [root@Fedora ~]# rpm --import http://download.fedora.redhat.com/pub/fedora/linux/extras/RPM-GPG-KEY-Fedora-Extras <= GPGキーのインポート [root@Fedora ~]# yum -y install tripwire <= 「Tripwire」のインストール [root@Fedora ~]# yum clean packages <= ダウンロードしたパッケージの削除 |
セットアップ(「Fedora Core 5」の場合)
サイトキー作成
[root@Fedora ~]# 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@Fedora ~]# 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. |
セットアップ(「Fedora Core 3」、「Fedora Core 4」の場合)
セットアップスクリプトを実行し、サイトパスフレーズとローカルパスフレーズを設定する。
[root@Fedora ~]# tripwire-setup-keyfiles <= セットアップスクリプトの実行 ---------------------------------------------- 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: <= サイトパスフレーズの入力 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: <= ローカルパスフレーズの入力 Verify the local keyfile passphrase: <= ローカルパスフレーズの入力(確認) Generating key (this may take several minutes)...Key generation complete. ---------------------------------------------- Signing 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 move this file to a secure location and/or encrypt it in place (using a tool such as GPG, for example) after you have examined it. ---------------------------------------------- Signing 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. Once you have a satisfactory Tripwire policy file, you should move the clear-text version to a secure location and/or encrypt it in place (using a tool such as GPG, for example). Now run "tripwire --init" to enter Database Initialization Mode. This reads the policy file, generates a database based on its contents, and then cryptographically signs the resulting database. Options can be entered on the command line to specify which policy, configuration, and key files are used to create the database. The filename for the database can be specified as well. If no options are specified, the default values from the current configuration file are used. |
テキスト版の設定ファイルを編集
・「Fedora Core 5」の場合
設定ファイルが無いので、新規作成する。
[root@Fedora ~]# 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).twr SITEKEYFILE =/etc/tripwire/site.key LOCALKEYFILE =/etc/tripwire/$(HOSTNAME)-local.key EDITOR =/bin/vi LATEPROMPTING =false LOOSEDIRECTORYCHECKING =true MAILNOVIOLATIONS =false EMAILREPORTLEVEL =4 REPORTLEVEL =4 MAILMETHOD =SENDMAIL SYSLOGREPORTING =true MAILPROGRAM =/usr/sbin/sendmail -oi -t |
・「Fedora Core 3」、「Fedora Core 4」の場合)
基本となる設定ファイルがすでに作成されている為、設定ファイルを修正する。
[root@Fedora ~]# vi /etc/tripwire/twcfg.txt <= 設定ファイルの編集 REPORTFILE =/var/lib/tripwire/report/$(HOSTNAME)-$(DATE).twr ↓ REPORTFILE =/var/lib/tripwire/report/$(HOSTNAME).twr <= レポートファイル名を変更 LOOSEDIRECTORYCHECKING =false ↓ LOOSEDIRECTORYCHECKING =true <= ファイル変更検知時に所属ディレクトリまで変更検知しない MAILNOVIOLATIONS =true ↓ MAILNOVIOLATIONS =false <= ファイル変更検知時のみメールを送信する EMAILREPORTLEVEL =3 ↓ EMAILREPORTLEVEL =4 <= ファイル変更チェック結果レポートレベルの変更 REPORTLEVEL =3 ↓ REPORTLEVEL =4 <= ファイル変更チェック結果レポートレベルの変更 |
設定ファイルの暗号化
[root@Fedora ~]# 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@Fedora ~]# rm -f /etc/tripwire/twcfg.txt <= テキスト版の設定ファイルの削除 ・暗号化されたファイルから設定ファイル(テキスト版)を作成する場合 [root@Fedora ~]# twadmin --print-cfgfile > /etc/tripwire/twcfg.txt |
ポリシーファイルの設定
全てのファイル変更チェックの結果をroot宛にメールを送信するようにする。
[root@Fedora ~]# 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="Fedora.crimson-snow.net";
ここまで
( emailto = root ) <= 追加
{ <= 追加
# Tripwire Binaries
{
/bin -> $(SEC_BIN) ;
/lib -> $(SEC_BIN) ;
}
} <= 追加
# disabled-entries: 184
|
ポリシーファイルの作成
デフォルトのポリシーファイルでは存在しないファイルのチェックが有効であったり、
存在するファイルのチェックが無効になっている。
そこで、和泉宏明氏の作成された
Perlスクリプトを利用し、
ポリシーファイルを作成する。
[root@Fedora ~]# wget http://www.aritia.org/hizumi/linux/tripwire_pol.pl.txt <= スクリプトファイルの取得
[root@Fedora ~]# mv tripwire_pol.pl.txt /etc/tripwire/tripwire_pol.pl <= スクリプトファイルを移動
[root@Fedora ~]# chmod 700 /etc/tripwire/tripwire_pol.pl <= スクリプトファイルに実行権限付加
[root@Fedora ~]# cat /etc/tripwire/tripwire_pol.pl <= Perlスクリプトの確認
#!/usr/bin/perl
# Tripwire Policy File customize tool for Redhat 8.0
# ----------------------------------------------------------------
# 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) = /^HOSTNAMEs*=\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 (! -e $tpath) {
$_ = "$sharp#$tpath$cond" if ($ret == 0) ;
}
else {
$_ = "$sharp$tpath$cond" ;
}
}
print "$_\n" ;
}
close(POL) ;
[root@Fedora ~]# /etc/tripwire/tripwire_pol.pl /etc/tripwire/twpol.txt > /etc/tripwire/twpol.txt.tmp
<= デフォルトのポリシーファイルを基にポリシーファイル作成
[root@Fedora ~]# rm -f /etc/tripwire/twpol.txt <= デフォルトのポリシーファイルを削除
[root@Fedora ~]# mv /etc/tripwire/twpol.txt.tmp /etc/tripwire/twpol.txt
<= 作成したポリシーファイルをデフォルトのポリシーファイル名にリネーム
|
ポリシーファイルの暗号化
[root@Fedora ~]# twadmin -m P -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key /etc/tripwire/twpol.txt <= 暗号化したポリシーファイルの作成(テキスト版=>暗号署名版) Please enter your site passphrase: <= サイトパスフレーズ入力 Wrote policy file: /etc/tripwire/tw.pol [root@Fedora ~]# rm -f /etc/tripwire/twpol.txt <= ポリシーファイル(テキスト版)を削除 ・暗号化されたファイルからポリシーファイル(テキスト版)を作成する場合 [root@Fedora ~]# twadmin --print-polfile > /etc/tripwire/twpol.txt |
ポリシーファイルよりデータベースを作成する。
[root@Fedora ~]# tripwire --init <= データベースの作成 Please enter your local passphrase: <= ローカルパスフレーズ入力 Parsing policy file: /etc/tripwire/tw.pol Generating the database... *** Processing Unix File System *** Wrote database file: /var/lib/tripwire/Fedora.crimson-snow.net.twd The database was successfully generated. |
[root@Fedora ~]# tripwire --check <= ファイル変更チェック
Parsing policy file: /etc/tripwire/tw.pol
*** Processing Unix File System ***
Performing integrity check...
Wrote report file: /var/lib/tripwire/report/Fedora.crimson-snow.net.twr
Tripwire(R) 2.3.0 Integrity Check Report
Report generated by: root
Report created on: 2005年10月15日 10時41分21秒
Database last updated on: Never
===============================================================================
Report Summary:
===============================================================================
Host name: Fedora.crimson-snow.net
Host IP address: 127.0.0.1
Host ID: None
Policy file used: /etc/tripwire/tw.pol
Configuration file used: /etc/tripwire/tw.cfg
Database file used: /var/lib/tripwire/Fedora.crimson-snow.net.twd
Command line used: tripwire --check
===============================================================================
Rule Summary:
===============================================================================
-------------------------------------------------------------------------------
Section: Unix File System
-------------------------------------------------------------------------------
Rule Name Severity Level Added Removed Modified
--------- -------------- ----- ------- --------
User binaries 66 0 0 0
Tripwire Binaries 100 0 0 0
Critical configuration files 100 0 0 0
Libraries 66 0 0 0
Operating System Utilities 100 0 0 0
Critical system boot files 100 0 0 0
File System and Disk Administraton Programs
100 0 0 0
Kernel Administration Programs 100 0 0 0
Networking Programs 100 0 0 0
System Administration Programs 100 0 0 0
Hardware and Device Control Programs
100 0 0 0
System Information Programs 100 0 0 0
Application Information Programs
100 0 0 0
(/sbin/rtmon)
Shell Related Programs 100 0 0 0
Critical Utility Sym-Links 100 0 0 0
Shell Binaries 100 0 0 0
* Tripwire Data Files 100 1 0 0 <= Tripwire Data Filesに1件の追加を検出
System boot changes 100 0 0 0
OS executables and libraries 100 0 0 0
Security Control 100 0 0 0
Login Scripts 100 0 0 0
Root config files 100 0 0 0
Invariant Directories 66 0 0 0
Temporary directories 33 0 0 0
Critical devices 100 0 0 0
Total objects scanned: 45379
Total violations found: 1
===============================================================================
Object Summary:
===============================================================================
-------------------------------------------------------------------------------
# Section: Unix File System
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Rule Name: Tripwire Data Files (/var/lib/tripwire)
Severity Level: 100
-------------------------------------------------------------------------------
Added:
"/var/lib/tripwire/Fedora.crimson-snow.net.twd" <= /var/lib/tripwire/Fedora.crimson-snow.net.twdの追加を検出
(Tripwireのデータベースの為、問題無し)
===============================================================================
Error Report:
===============================================================================
No Errors
-------------------------------------------------------------------------------
*** End of report ***
Tripwire 2.3 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.
Integrity check complete.
|
「Tripwire」を実行するスクリプトを作成し、cronに登録して自動実行するようにする。
[root@Fedora ~]# vi tripwire.sh <= スクリプトの作成 #!/bin/sh # 設定 TRIPWIRE=/usr/sbin/tripwire TWADMIN=/usr/sbin/twadmin TRIPWIRE_POL=/etc/tripwire/tripwire_pol.pl LOG=/var/log/tripwire.log LOCALPASS=ローカルパスフレーズ <= ローカルパスフレーズを入力 SITEPASS=サイトパスフレーズ <= サイトパスフレーズを入力 # Tripwire実行 $TRIPWIRE --check --email-report > $LOG # ポリシーファイル最新化 $TWADMIN --print-polfile > /etc/tripwire/twpol.txt $TRIPWIRE_POL /etc/tripwire/twpol.txt > /etc/tripwire/twpol.txt.tmp $TWADMIN -m P -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key -Q $SITEPASS /etc/tripwire/twpol.txt.tmp >> $LOG rm -f /etc/tripwire/twpol.* # データベース最新化 rm -f /var/lib/tripwire/Fedora.crimson-snow.net.twd $TRIPWIRE --init -P $LOCALPASS >> $LOG [root@Fedora ~]# chmod 700 /root/tripwire.sh <= 作成したスクリプトに実行権限付加 |
スクリプトの自動実行
[root@Fedora ~]# crontab -e <= cron編集 00 06 * * * /root/tripwire.sh <= 追加(毎日6:00にスクリプト実行) |