| トップ | Solaris | FreeBSD | Gentoo | CentOS | Fedora | Windows | Tips | 自宅サーバの動作確認 | サイト内検索(Namazu) | サイト内検索(HE) |
ファイルの改竄を検知する為に「Tripwire」を導入する。
「CentOS4.1」の場合
CentOS向けのRPMは提供されていない為、FedoraCore3のextrasからRPMを入手する。
[root@CentOS ~]# rpm --import http://ftp.kddilabs.jp/Linux/packages/fedora/extras/RPM-GPG-KEY-Fedora-Extras <= GPGキーのインポート [root@CentOS ~]# wget http://ftp.kddilabs.jp/Linux/packages/fedora/extras/3/i386/tripwire-2.3.1-21.i386.rpm <= 「Tripwire」のダウンロード [root@CentOS ~]# rpm -ivh tripwire-2.3.1-21.i386.rpm <= 「Tripwire」のインストール |
「CentOS5.0」の場合
CentOS向けのRPMは提供されていない為、Red Hat Enterprise Linux 4.0用のSRPMをrebuildする。
[root@CentOS ~]# wget ftp://mirror.switch.ch/mirror/fedora/linux/extras/4/SRPMS/tripwire-2.3.1-22.src.rpm <= TripwireのSRPMをダウンロード [root@CentOS ~]# rpm -ivh tripwire-2.3.1-22.src.rpm <= SRPMファイルのインストール |
specファイルの修正とパッチファイルの作成を行う。
[root@CentOS ~]# vi /usr/src/redhat/SPECS/tripwire.spec <= specファイルの修正
Patch4: tripwire-siggen-man8.patch
Patch5: pipedmailmessage.patch
Patch100: tripwire-2.3.1-compile-centos5.patch <= 追加
%patch4 -p1 -b .siggen.manpage
%patch5 -p1 -b .pipedmailmessage
%patch100 -p1 -b .centos5 <= 追加
[root@CentOS ~]# vi /usr/src/redhat/SOURCES/tripwire-2.3.1-compile-centos5.patch <= パッチファイルの作成
--- tripwire-2.3.1-2/src/fco/fconame.h.centos5 2006-04-04 01:40:46.000000000 +0900
+++ tripwire-2.3.1-2/src/fco/fconame.h 2006-04-04 01:32:27.000000000 +0900
@@ -49,6 +49,7 @@
///////////////////////////////////////////////////////////////////////////////
class cFCONameTblNode;
class cFCONameIter;
+class cFCOName_i;
class cFCOName : public iTypedSerializable
{
--- tripwire-2.3.1-2/src/fco/fcosetimpl.h.centos5 2000-10-28 09:25:39.000000000 +0900
+++ tripwire-2.3.1-2/src/fco/fcosetimpl.h 2006-04-04 01:43:06.000000000 +0900
@@ -46,6 +46,8 @@
#include "fconame.h"
#endif
+class cFCOIterImpl;
+
class cFCOSetImpl : public iFCOSet
{
friend class cFCOIterImpl;
--- tripwire-2.3.1-2/src/tw/fcoreport.h.centos5 2006-04-04 01:40:46.000000000 +0900
+++ tripwire-2.3.1-2/src/tw/fcoreport.h 2006-04-04 01:43:06.000000000 +0900
@@ -85,6 +85,7 @@
class cFileHeaderID;
class cErrorQueue;
class cFCOReportGenreHeader;
+class cFCOReportSpecIter;
class cFCOReport : public iTypedSerializable
{
|
rpmファイルを作成してインストールする。
[root@CentOS ~]# rpmbuild -bb --clean /usr/src/redhat/SPECS/tripwire.spec <= rpmファイルの作成 [root@CentOS ~]# rpm -ivh /usr/src/redhat/RPMS/i386/tripwire-2.3.1-22.i386.rpm <= 「Tripwire」のインストール |
セットアップ
セットアップスクリプトを実行し、サイトパスフレーズとローカルパスフレーズを設定する。
[root@CentOS ~]# 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. |
テキスト版の設定ファイルを編集する。
[root@CentOS ~]# 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@CentOS ~]# twadmin --create-cfgfile -S /etc/tripwire/site.key /etc/tripwire/twcfg.txt <= 暗号化した設定ファイルの作成(テキスト版=>暗号署名版) Please enter your site passphrase: <= サイトパスフレーズ入力 Wrote configuration file: /etc/tripwire/tw.cfg [root@CentOS ~]# rm -f /etc/tripwire/twcfg.txt <= テキスト版の設定ファイルの削除 ・暗号化されたファイルから設定ファイル(テキスト版)を作成する場合 [root@CentOS ~]# twadmin --print-cfgfile > /etc/tripwire/twcfg.txt |
ポリシーファイルの作成
デフォルトのポリシーファイルでは存在しないファイルのチェックが有効であったり、
存在するファイルのチェックが無効になっている。
そこで、和泉宏明氏の作成された
Perlスクリプトを利用し、
ポリシーファイルを作成する。
[root@CentOS ~]# wget http://www.aritia.org/hizumi/linux/tripwire_pol.pl.txt <= スクリプトファイルの取得
[root@CentOS ~]# mv tripwire_pol.pl.txt /etc/tripwire/tripwire_pol.pl <= スクリプトファイルを移動
[root@CentOS ~]# chmod 700 /etc/tripwire/tripwire_pol.pl <= スクリプトファイルに実行権限付加
[root@CentOS ~]# 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@CentOS ~]# /etc/tripwire/tripwire_pol.pl /etc/tripwire/twpol.txt > /etc/tripwire/twpol.txt.tmp
<= デフォルトのポリシーファイルを基にポリシーファイル作成
[root@CentOS ~]# rm -f /etc/tripwire/twpol.txt <= デフォルトのポリシーファイルを削除
[root@CentOS ~]# mv /etc/tripwire/twpol.txt.tmp /etc/tripwire/twpol.txt
<= 作成したポリシーファイルをデフォルトのポリシーファイル名にリネーム
|
ポリシーファイルの設定
全てのファイル変更チェックの結果をroot宛にメールを送信するようにする。
[root@CentOS ~]# vi /etc/tripwire/twpol.txt <= 設定ファイルの作成
( emailto = root ) <= 追加
{ <= 追加
# Tripwire Binaries
{
/bin -> $(SEC_BIN) ;
/lib -> $(SEC_BIN) ;
}
} <= 追加
# disabled-entries: 184
|
ポリシーファイルの暗号化
[root@CentOS ~]# twadmin --create-polfile -S /etc/tripwire/site.key /etc/tripwire/twpol.txt <= 暗号化したポリシーファイルの作成(テキスト版=>暗号署名版) Please enter your site passphrase: <= サイトパスフレーズ入力 Wrote policy file: /etc/tripwire/tw.pol [root@CentOS ~]# rm -f /etc/tripwire/twpol.txt <= ポリシーファイル(テキスト版)を削除 ・暗号化されたファイルからポリシーファイル(テキスト版)を作成する場合 [root@CentOS ~]# twadmin --print-polfile > /etc/tripwire/twpol.txt |
ポリシーファイルよりデータベースを作成する。
[root@CentOS ~]# 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/CentOS.crimson-snow.net.twd The database was successfully generated. |
[root@CentOS ~]# tripwire --check <= ファイル変更チェック
Parsing policy file: /etc/tripwire/tw.pol
*** Processing Unix File System ***
Performing integrity check...
Wrote report file: /var/lib/tripwire/report/CentOS.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: CentOS.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/CentOS.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/CentOS.crimson-snow.net.twd" <= /var/lib/tripwire/CentOS.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@CentOS ~]# 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 --create-polfile -S /etc/tripwire/site.key -Q $SITEPASS /etc/tripwire/twpol.txt.tmp >> $LOG rm -f /etc/tripwire/twpol.* # データベース最新化 rm -f /var/lib/tripwire/CentOS.crimson-snow.net.twd $TRIPWIRE --init -P $LOCALPASS >> $LOG [root@CentOS ~]# chmod 700 /root/tripwire.sh <= 作成したスクリプトに実行権限付加 |
スクリプトの自動実行
[root@CentOS ~]# crontab -e <= cron編集 00 06 * * * /root/tripwire.sh <= 追加(毎日6:00にスクリプト実行) |