大橋のページ

RedHat-Linuxメモ

グループについて
syslogデーモンについて
rpmコマンドをアップデートする
E-IDEのHDDを増設する
opensshをインストールする
opensshをインストールする その2
Real Server Basicをインストールする
リモートマシンのバックアップをとる

tripwireのインストール

tripwireを入手

サーバに侵入したクラッカーは、悪質なプログラムをインストールするとともに、各種設定ファイルを書き換える(改竄する)にとどまらず、バイナリコマンドも置き換えてしまう。たとえば、lsコマンドやpsコマンドを置き換えることで、侵入した痕跡に気づかないようにすることで、さらに悪質な行為にその魔の手を広げるわけだ。

tripwireは、サーバ内の重要なファイルに関するデータベースをあらかじめ持っておいて、定期的に現在のファイルの状態とそのデータベースとをつきあわせることで、ファイルが改竄されていないかをチェックするためのものだ。

もともとtripwireは無料で利用できるソフトウェアだったが、ある時期から有料のソフトウェアとして販売されるようになった。しかし、Linux版に関してのみ、オープンソースとして公開されている。ここではそのLinux版tripwireをRedHat6.2にインストールしてみる。

1992年 アメリカのパデュー大学で開発され、Linux版が公開される
1997年 アメリカTripwire Inc.が独占契約し、商用化される(NT、Solaris、HP-UX)
1999年 東芝情報システムが英語版販売開始
2000年2月29日 アメリカTripwire社Linux版をオープンソースとし、GPLでソースコード公開
2000年 トリップワイヤ・ジャパン『Tripwire 2.2.1』日本語対応版販売開始

tripwireのLinux版は、Tripwire Open Source project「http://www.tripwire.org/」から入手できる。

http://www.tripwire.org/

「Download」をクリックするとオープンソースの「tripwire-2.3-47.bin.tar.gz」以外にRedHatのRPMパッケージ「Tripwire Open Source RPM 3.0 (Red Hat 5.x-6.2.x) tripwire-2.3-47.i386.tar.gz」と「Tripwire Open Source RPM 4.0 (Red Hat 7.x) tripwire-2.3-47.i386.tar.gz」の2つがある。

ここではRedHat6.xで使える「tripwire-2.3-47.i386.tar.gz」をダウンロードすることにするが、RedHat7.xには、たとえばRedHat7.1日本語版には「tripwire-2.3.0-58.i386.rpm」が収録されているようで、こちらのほうがバージョンが新しいように思える。

ftp://ftp.kddlabs.co.jp/.2/Linux/RedHat/redhat/linux/7.1/ja/os/i386/RedHat/RPMS/

●そのほかの関連ページ

Tripwire, Inc
http://www.tripwire.com/
http://www.tripwiresecurity.com/

トリップワイヤ・ジャパン
http://www.tripwire.co.jp/dl/index.html

東芝情報システムサイト内の関連ページ

http://www.tjsys.co.jp/tjplaza/pprovider/demo/tripwire/

WindowsNT版のTripwireに関するページ
http://www.port139.co.jp/ntsec_tripwire.htm

tripwireのインストール

ダウンロードしたRPMパッケージは圧縮されているため、Linuxに転送したら、まず解凍する。解凍したらrpmコマンドでインストールする。

$ tar zxvf tripwire-2.3-47.i386.tar.gz
tripwire-2.3-47.i386.rpm

$ ls
tripwire-2.3-47.i386.rpm        tripwire-2.3-47.i386.tar.gz
$ su
Password:

# rpm -ivv --test tripwire-2.3-47.i386.rpm
D: インストールするパッケージを数えています
D: 1 個のパッケージを見つけました
D: ダウンロードするパッケージを探しています
D: 0 個のパッケージを取得しました
D: 新しいヘッダ署名
D: 署名サイズ: 68
D: 署名パッド: 4
D: 署名サイズ     : 72
D: ヘッダ + アーカイブ: 3676860
D: 期待されるサイズ: 3676860
D: opening database mode 0x0 in /var/lib/rpm
D: 0 個のソースと 1 個のバイナリパッケージが見つかりました
D:  requires: /bin/sh   は db ファイルがリストを作ることによって満されます。
D:  requires: /bin/sh  は db ファイルがリストを作ることによって満されます。
D: バイナリパッケージをインストール中
D: マウントされたファイルシステムのリストを取得しています
D: 新しいヘッダ署名
D: 署名サイズ: 68
D: 署名パッド: 4
D: 署名サイズ     : 72
D: ヘッダ + アーカイブ: 3676860
D: 期待されるサイズ: 3676860
D: パッケージ: tripwire-2.3-47 ファイルテスト = 1
D:    file: /etc/tripwire/twinstall.sh.bak action: create
D:    file: /etc/tripwire/twpol.txt action: create
D:    file: /usr/doc/tripwire/COPYING action: create
D:    file: /usr/doc/tripwire/README action: create
D:    file: /usr/doc/tripwire/Release_Notes action: create
D:    file: /usr/doc/tripwire/TRADEMARK action: create
D:    file: /usr/doc/tripwire/policyguide.txt action: create
D:    file: /usr/man/man4/twconfig.4 action: create
D:    file: /usr/man/man4/twpolicy.4 action: create
D:    file: /usr/man/man5/twfiles.5 action: create
D:    file: /usr/man/man8/siggen.8 action: create
D:    file: /usr/man/man8/tripwire.8 action: create
D:    file: /usr/man/man8/twadmin.8 action: create
D:    file: /usr/man/man8/twintro.8 action: create
D:    file: /usr/man/man8/twprint.8 action: create
D:    file: /usr/sbin/siggen action: create
D:    file: /usr/sbin/tripwire action: create
D:    file: /usr/sbin/twadmin action: create
D:    file: /usr/sbin/twprint action: create
D:    file: /var/lib/tripwire/report action: create
D: --test を実行するようにインストールを中止しています

# rpm -ivv tripwire-2.3-47.i386.rpm
D: インストールするパッケージを数えています
D: 1 個のパッケージを見つけました
D: ダウンロードするパッケージを探しています
D: 0 個のパッケージを取得しました
D: 新しいヘッダ署名
D: 署名サイズ: 68
D: 署名パッド: 4
D: 署名サイズ     : 72
D: ヘッダ + アーカイブ: 3676860
D: 期待されるサイズ: 3676860
D: opening database mode 0x42 in /var/lib/rpm
D: 0 個のソースと 1 個のバイナリパッケージが見つかりました
D:  requires: /bin/sh   は db ファイルがリストを作ることによって満されます。
D:  requires: /bin/sh  は db ファイルがリストを作ることによって満されます。
D: バイナリパッケージをインストール中
D: マウントされたファイルシステムのリストを取得しています
D: 新しいヘッダ署名
D: 署名サイズ: 68
D: 署名パッド: 4
D: 署名サイズ     : 72
D: ヘッダ + アーカイブ: 3676860
D: 期待されるサイズ: 3676860
D: パッケージ: tripwire-2.3-47 ファイルテスト = 0
D:    file: /etc/tripwire/twinstall.sh.bak action: create
D:    file: /etc/tripwire/twpol.txt action: create
D:    file: /usr/doc/tripwire/COPYING action: create
D:    file: /usr/doc/tripwire/README action: create
D:    file: /usr/doc/tripwire/Release_Notes action: create
D:    file: /usr/doc/tripwire/TRADEMARK action: create
D:    file: /usr/doc/tripwire/policyguide.txt action: create
D:    file: /usr/man/man4/twconfig.4 action: create
D:    file: /usr/man/man4/twpolicy.4 action: create
D:    file: /usr/man/man5/twfiles.5 action: create
D:    file: /usr/man/man8/siggen.8 action: create
D:    file: /usr/man/man8/tripwire.8 action: create
D:    file: /usr/man/man8/twadmin.8 action: create
D:    file: /usr/man/man8/twintro.8 action: create
D:    file: /usr/man/man8/twprint.8 action: create
D:    file: /usr/sbin/siggen action: create
D:    file: /usr/sbin/tripwire action: create
D:    file: /usr/sbin/twadmin action: create
D:    file: /usr/sbin/twprint action: create
D:    file: /var/lib/tripwire/report action: create
D: プリインストールスクリプト(が有れば)を実行します
tripwire-2.3-47
GZDIO:    1518 reads, 12427368 total bytes in 2.240 secs
D: running postinstall scripts (if any)
+ TWADMIN=twadmin
+ TWADMPATH=/usr/sbin
+ TWLICENSEFILE=COPYING
+ TW_CONFIG_FILE=tw.cfg
+ CONF_PATH=/etc/tripwire
+ CLR_CONFIG_FILE=twcfg.txt
+ CLR_POLICY_FILE=twpol.txt
+ README=README
++ pwd
+ START_DIR=/
+ TW_SITE_PASS=
+ TW_LOCAL_PASS=
+ CLOBBER=false
+ PROMPT=true
+ TWDOCS=/usr/doc/tripwire
+ TWBIN=/usr/sbin
+ TWCFG=/etc/tripwire
+ TWPOLICY=/etc/tripwire
+ TWMAN=/usr/man
+ TWDB=/var/lib/tripwire
+ TWSITEKEYDIR=/etc/tripwire
+ TWLOCALKEYDIR=/etc/tripwire
+ TWREPORT=/var/lib/tripwire/report
+ TWEDITOR=/bin/vi
+ TWLATEPROMPTING=false
+ TWLOOSEDIRCHK=false
+ TWMAILNOVIOLATIONS=true
+ TWEMAILREPORTLEVEL=3
+ TWREPORTLEVEL=3
+ TWSYSLOG=false
+ TWMAILMETHOD=SENDMAIL
+ TWMAILPROGRAM=/usr/lib/sendmail -oi -t
+ HOST_NAME=localhost
+ [ 0 -eq 0 ]
++ uname -n
+ HOST_NAME=xxxxxx.hyperdyne.co.jp
+ LOCAL_KEY=/etc/tripwire/xxxxxx.hyperdyne.co.jp-local.key
+ SITE_KEY=/etc/tripwire/site.key
+ CONFIG_FILE=/usr/sbin/tw.cfg
+ POLICY_FILE=/etc/tripwire/tw.pol
+ TXT_CFG=/etc/tripwire/twcfg.txt
+ TXT_POL=/etc/tripwire/twpol.txt
+ TWADMIN=/usr/sbin/twadmin
+ echo

+ echo ----------------------------------------------
----------------------------------------------
+ echo Generating Tripwire configuration file...
Generating Tripwire configuration file...
+ cat
+ [ SENDMAIL = SMTP ]
+ cat
+ [ ! -s /etc/tripwire/twcfg.txt ]
+ chmod 0644 /etc/tripwire/twcfg.txt
+ echo

+ echo ----------------------------------------------
----------------------------------------------
+ echo Customizing default policy file...
Customizing default policy file...
+ sed /@@section GLOBAL/,/@@section FS/  {
  s?^\(TWROOT=\).*$?\1"/usr/sbin";?
  s?^\(TWBIN=\).*$?\1"/usr/sbin";?
  s?^\(TWPOL=\).*$?\1"/etc/tripwire";?
  s?^\(TWDB=\).*$?\1"/var/lib/tripwire";?
  s?^\(TWSKEY=\).*$?\1"/etc/tripwire";?
  s?^\(TWLKEY=\).*$?\1"/etc/tripwire";?
  s?^\(TWREPORT=\).*$?\1"/var/lib/tripwire/report";?
  s?^\(HOSTNAME=\).*$?\1xxxxxx.hyperdyne.co.jp;?
} /etc/tripwire/twpol.txt
+ cp /etc/tripwire/twpol.txt /etc/tripwire/twpol.txt.bak
+ mv /etc/tripwire/twpol.txt.tmp /etc/tripwire/twpol.txt
+ chmod 0644 /etc/tripwire/twpol.txt
+ chmod 0644 /etc/tripwire/twpol.txt.bak
+ cat

A clear-text version of the Tripwire policy file
/etc/tripwire/twpol.txt
has been created 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 signed copy of the Tripwire policy.

+ sed -e {
    s^_SITEKEYPATH_^/etc/tripwire^
    s^_LOCALKEYPATH_^/etc/tripwire^
    s^_ADMVAR_^/usr/sbin^
    s^_CONFPATH_^/etc/tripwire^
    } /etc/tripwire/twinstall.sh.bak
+ chmod 750 /etc/tripwire/twinstall.sh
+ [ -n  ]
+ [ -n  ]
+ echo IMPORTANT:  To complete the Tripwire 2.3 installation,
IMPORTANT:  To complete the Tripwire 2.3 installation,
+ echo you must run the configuration script: 
you must run the configuration script: 
+ echo /etc/tripwire/twinstall.sh
/etc/tripwire/twinstall.sh
+ echo

+ echo This script walks you through the processes of 
This script walks you through the processes of 
+ echo setting passphrases and encrypting the policy
setting passphrases and encrypting the policy
+ echo and configuration files.  If you wish to change the
and configuration files.  If you wish to change the
+ echo contents of your policy file, /etc/tripwire/twpol.txt
contents of your policy file, /etc/tripwire/twpol.txt
+ echo you may want to do so before running this script.
you may want to do so before running this script.
+ cat

----------------------------------------------
The installation succeeded.

Please refer to /usr/doc/tripwire/README
for release information and to the printed user documentation for
further instructions on using Open Source Tripwire 2.3 for Linux.

+ cd /

RPMパッケージでは、設定ファイルは「/etc/tripwire」ディレクトリ以下に、tripwireコマンドとtwadminコマンドが「/usr/sbin」ディレクトリに、データベースが「/var/lib/tripwire」ディレクトリに、チェックレポートが「/var/lib/tripwire/report」ディレクトリにインストールされます。ドキュメントは「/usr/doc/tripwire」、設定ファイルの編集用エディタはvi、メールは「/usr/lib/sendmail -oi -t」が使われる。

# cd /etc/tripwire
# ls
twcfg.txt  twinstall.sh  twinstall.sh.bak  twpol.txt  twpol.txt.bak

rpmコマンドによるファイルの配置がすんだら、シェルスクリプト「twinstall.sh」を使ってインストールをする。このインストールによって、データベースが作られ、tripwireの稼動環境が整う。実際には、twcfg.txtによって環境設定ファイル「tw.cfg」(バイナリ)が、twpol.txtによってポリシー設定ファイル「tw.pol」(バイナリ)が作られ、キーファイルとして「xxxxxxxx.xxxxxxx.xxx.xx-local.key」というように「ホスト名-local.key」という名前のものと「site.key」という名前のファイルができあがる。基本的な設定は、「twcfg.txt」が設定している。

# vi 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/xxxxxx.hyperdyne.co.jp-local.key
EDITOR=/bin/vi
LATEPROMPTING =false
LOOSEDIRECTORYCHECKING =false
MAILNOVIOLATIONS =true
EMAILREPORTLEVEL =3
REPORTLEVEL   =3
MAILMETHOD    =SENDMAIL
SYSLOGREPORTING =false
MAILPROGRAM   =/usr/lib/sendmail -oi -t

さて、twinstall.shを実行する前に2つのパスフレーズを決めておく必要がある。パスフレーズとは、暗号化するためのキーワードで、ローカルマシン用とサイト用の2つが必要で、これはrootのパスワードとは別のものにしておくほうが望ましい。とくにcronを使って自動実行するとき、パスフレーズをパラメータとして渡さなければならず、そのさいにそのまま記述することになるため、rootパスワードと同じものにしてはならない。

# ./twinstall.sh

----------------------------------------------
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 delete this file manually 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.

twinstall.shを実行したら、tripwireのデータベースを作る。作るには、tripwireコマンドを使う。tripwireのヘルプは次のようになっている。

# /usr/sbin/tripwire --help
tripwire: File integrity assessment application.

Tripwire(R) 2.3.0.47 for Linux

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.
Usage:

Database Initialization:  tripwire [-m i|--init] [options]
Integrity Checking:  tripwire [-m c|--check] [object1 [object2...]]
Database Update:  tripwire [-m u|--update]
Policy Update:  tripwire [-m p|--update-policy] policyfile.txt
Test:  tripwire [-m t|--test] --email address

Type 'tripwire [mode] --help' OR
'tripwire --help mode [mode...]' OR
'tripwire --help all' for extended help

データベースの初期化が「--init」、チェックが「--check」、データベースのアップデートが「--update」、ポリシーファイルの更新が「--update-policy ポリシーファイルの名前」、テストが「--test」になる。

「--init」オプションをつけてtripwireを実行してデータベースを作るが、このときたくさんエラーが出る。

# /usr/sbin/tripwire --init
Please enter your local passphrase: <----ローカル用パスフレーズの入力
Parsing policy file: /etc/tripwire/tw.pol
Generating the database...
*** Processing Unix File System ***
### Warning: File system error.
### Filename: /usr/sbin/fixrmtab
### No such file or directory
### Continuing...

(略)

### Warning: File system error.
### Filename: /root/.ICEauthority
### No such file or directory
### Continuing...
Wrote database file: /var/lib/tripwire/xxxxxx.hyperdyne.co.jp.twd
The database was successfully generated.
#

このエラーはチェック対象として定義されているファイルが実際には存在しないことに原因があり、RedHat6.x用とされているが、「twpol.txt」では「RedHat7.0」と記述されていることから、ポリシーファイルがRedHat7.x用になっているようだ(その後、RedHat7.xにもインストールしてみたが、ほぼ同じ状況で、とくにRedHatのバージョンに関わるものではなさそう)。このエラーを回避するてっとりばやい方法はエラーとなったファイルを「twpol.txt」から削除(またはコメントアウト)してしまうことだ。エラーを記録するには、telnetでログインしたのちログにとっておくといい。viで検索するには、「/」を入力してから検索対象とする文字列を入力する。

twpol.txtからエラーになった対象ファイルを削除または行の先頭に「#」を付けてコメントアウトしたら、もう一度「twinstall.sh」を実行して環境を整えなおす。とくにtwpol.txtからtw.polファイルを作り直さなければ、修正は反映されない。

修正に問題がなければ、「--init」オプション付きでtripwireコマンドを実行してもエラーが出なくなる。

# /usr/sbin/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/xxxxx.hyperdyne.co.jp.twd
The database was successfully generated.

データベースの初期化がすんだら、実際にデータベースと付き合わせて変更がないかどうかをチェックしてみる。

# /usr/sbin/tripwire  --check
Parsing policy file: /etc/tripwire/tw.pol
*** Processing Unix File System ***
Performing integrity check...
Wrote report file: /var/lib/tripwire/report/xxxxx.hyperdyne.co.jp-20010622-23242
2.twr


Tripwire(R) 2.3.0 Integrity Check Report

Report generated by:          root
Report created on:            Fri 22 Jun 2001 11:24:22 PM JST
Database last updated on:     Never

===============================================================================
Report Summary:
===============================================================================

Host name:                    xxxxx.hyperdyne.co.jp
Host IP address:              192.168.xxx.xxx
Host ID:                      None
Policy file used:             /etc/tripwire/tw.pol
Configuration file used:      /etc/tripwire/tw.cfg
Database file used:           /var/lib/tripwire/xxxxx.hyperdyne.co.jp.twd
Command line used:            /usr/sbin/tripwire --check 

===============================================================================
Rule Summary: 
===============================================================================

-------------------------------------------------------------------------------
  Section: Unix File System
-------------------------------------------------------------------------------

  Rule Name                       Severity Level    Added    Removed  Modified 
  ---------                       --------------    -----    -------  -------- 
  Invariant Directories           66                0        0        0        
  Temporary directories           33                0        0        0        
  Tripwire Data Files             100               0        0        0        
  Critical devices                100               0        0        0        
  User binaries                   66                0        0        0        
  Tripwire Binaries               100               0        0        0        
  Libraries                       66                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        
  Shell Releated Programs         100               0        0        0        
  Critical Utility Sym-Links      100               0        0        0        
  Critical system boot files      100               0        0        0        
  Critical configuration files    100               0        0        0        
  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        
  Operating System Utilities      100               0        0        0        
  Shell Binaries                  100               0        0        0        
  Root config files               100               0        0        0        

Total objects scanned:  9540
Total violations found:  0

===============================================================================
Object Summary: 
===============================================================================

-------------------------------------------------------------------------------
# Section: Unix File System
-------------------------------------------------------------------------------

No violations.

===============================================================================
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.
#

レポート中、「Wrote report file: /var/lib/tripwire/report/xxxxx.hyperdyne.co.jp-20010622-232422.twr」とあるように、「/var/lib/tripwire/report」ディレクトリに「ホスト名+西暦+月日-時分秒.twr」という名前のファイルでレポートが保存される。

tripwireの運用

実際にどうtripwireを使うかは、各管理者のセキュリティポリシーに依存するだろう。そのため、ここではいくつかポイントだけあげておくようにする。

まず、いくつかの設定ファイルはサーバ上から削除しておいたほうがいいように思う。とくにプレーンテキストの「twpol.txt」と「twcfg.txt」は削除しておいたほうがいいだろう。削除して、必要になったときは、twadminコマンドを使って次のようにテキストファイルにする。

# /usr/sbin/twadmin -m p > twpol.txt
# /usr/sbin/twadmin -m f > twcfg.txt

ちなみに「twpol.txt」から「tw.pol」を、「twcfg.txt」から「tw.cfg」を作るには、
# /usr/sbin/twadmin -m P -S site.key twpol.txt
Please enter your site passphrase:
Wrote policy file: /etc/tripwire/tw.pol
# /usr/sbin/twadmin -m F -S site.key twcfg.txt
Please enter your site passphrase:
Wrote configuration file: /etc/tripwire/tw.cfg
#

とする。それ以外にも、できるだけtripwire関連ファイルはサーバ内に置きっぱなしにしないようし、取り外しできるMOなどに格納するようにしたほうがいいだろう。

最後にチェック結果をメールで送信する方法だが、まず「--test」オプションを付けてtripwireコマンドを実行してテストしてみる。

# /usr/sbin/tripwire --test --email oohashi@hyperdyne.co.jp
Sending a test message to: oohashi@hyperdyne.co.jp
#

テストが無事終了すると「"Tripwire(R) 2.3.0.47" 」というようなアドレスで、指定したメールアドレス宛てに、Subject「Test email message from Tripwire」として、「「If you receive this message, email notification from tripwire is working correctly. 」という内容のメールが届く。

テストが成功したら、自動実行させる。自動実行では、チェックしたあとデータベースの更新をするようにする。データベースを更新しないとチェックするたびに毎回同じファイルがヒットしてしまうからだ。/etc/crontabに

0 1 * * * root /usr/sbin/tripwire --check | /bin/mail -s "tripwire report" root
0 10 * * * root /usr/sbin/tripwire --init -P xxxxxx

とする。このとき、「--init」オプションといっしょに「-P」オプションで渡しているのは、パスフレーズだ。そのため、/etc/crontabのパーミッションを「600」にしておいたほうがいい。それがむずかしいようならシェルスクリプトに書き出し、そのファイルのパーミッションを設定する。

ただし、crontabを使ったこの方法だと、メールの件名が「Cron /usr/sbin/tripwire --init -P xxxxxx」になってしまうため、メールが盗聴されるとパスフレーズが漏れてしまう。シェルスクリプト化したほうが安全だ。

シェルスクリプトにするときは、たとえば次のような内容にし(オーナーroot、グループrootで、700)

#!/bin/sh
/usr/sbin/tripwire --check | /bin/mail -s "tripwire report" root
/usr/sbin/tripwire --init -P xxxxxxx

crontabに次のような登録をする。

0 4 * * * root /xxxxxxxx/tripwire.sh > /dev/null 2>&1

それとは別に、RedHat7.0では、「/etc/cron.daily」に「tripwire-check」という名前で自動実行スクリプトがインストールされ、毎夜4時ころ(正確には4時2分)実行されている。

#!/bin/sh
HOST_NAME=`uname -n`
if [ ! -e /var/lib/tripwire/${HOST_NAME}.twd ] ; then
        echo "****    Error: Tripwire database for ${HOST_NAME} not found.    **
**"
        echo "**** Run "/etc/tripwire/twinstall.sh" and/or "tripwire --init". **
**"
else
        test -f /etc/tripwire/tw.cfg &&  /usr/sbin/tripwire --check
fi

tripwireのデータベースがあるかないか調べて、なければ「twinstall.sh」を実行したのち初期化をし、あればチェックを実行している。データベースの初期化は行なっていないようだ。

そのため「test」行に続けて「/usr/sbin/tripwire --init -P xxxxxxx」を書き込んでおけば、チェックがすんだあと、データベースの作成が行なわれる。

参考になるだろうページ
http://www.medinfo.m.ehime-u.ac.jp/kandalva/2001/tripwire/

tripwireのヘルプ

# /usr/sbin/tripwire --help all
tripwire: File integrity assessment application.

Tripwire(R) 2.3.0.47 for Linux

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.
Database Initialization mode:
  -m i                 --init
  -v                   --verbose
  -s                   --silent, --quiet
  -c cfgfile           --cfgfile cfgfile
  -p polfile           --polfile polfile
  -d database          --dbfile database
  -S sitekey           --site-keyfile sitekey
  -P passphrase        --local-passphrase passphrase
  -L localkey          --local-keyfile localkey
  -e                   --no-encryption

The -v and -s options are mutually exclusive.
The -L and -e options are mutually exclusive.
The -P and -e options are mutually exclusive.

Integrity Check mode:
  -m c                 --check
  -I                   --interactive
  -v                   --verbose
  -s                   --silent, --quiet
  -c cfgfile           --cfgfile cfgfile
  -p polfile           --polfile polfile
  -S sitekey           --site-keyfile sitekey
  -L localkey          --local-keyfile localkey
  -d database          --dbfile database
  -r report            --twrfile report
  -P passphrase        --local-passphrase passphrase
  -n                   --no-tty-output
  -V editor            --visual editor
  -E                   --signed-report
  -R rule              --rule-name rule
  -l {level | name}    --severity {level | name}
  -x section           --section section
  -i list              --ignore list
  -M                   --email-report
  -t { 0|1|2|3|4 }     --email-report-level { 0|1|2|3|4 }
[object1 [object2...]]

The -v and -s options are mutually exclusive.
The -l and -R options are mutually exclusive.
The -P option is only valid with -E or -I.
The -V option is only valid with -I.
The -t option is only valid with -M.
Specifying objects overrides the -l and -R options.

Database Update mode:
  -m u                 --update
  -v                   --verbose
  -s                   --silent, --quiet
  -c cfgfile           --cfgfile cfgfile
  -p polfile           --polfile polfile
  -S sitekey           --site-keyfile sitekey
  -L localkey          --local-keyfile localkey
  -d database          --dbfile database
  -r report            --twrfile report
  -P passphrase        --local-passphrase passphrase
  -V editor            --visual editor
  -a                   --accept-all
  -Z {low | high}      --secure-mode {low | high}

The -v and -s options are mutually exclusive.
The -a and -V options are mutually exclusive.

Policy Update mode:
  -m p                 --update-policy
  -v                   --verbose
  -s                   --silent, --quiet
  -c cfgfile           --cfgfile cfgfile
  -p polfile           --polfile polfile
  -S sitekey           --site-keyfile sitekey
  -L localkey          --local-keyfile localkey
  -d database          --dbfile database
  -P passphrase        --local-passphrase passphrase
  -Q passphrase        --site-passphrase passphrase
  -Z {low | high}      --secure-mode {low | high}
policyfile.txt

The -v and -s options are mutually exclusive.

Test mode:
  -m t                 --test
  -e user@domain.com   --email user@domain.com

Only one address may be entered.

#

twadminのヘルプ

# /usr/sbin/twadmin --help all
twadmin: Tripwire administrative tool.

Tripwire(R) 2.3.0.47 for Linux

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.
Create Configuration File mode:
  -m F                 --create-cfgfile
  -v                   --verbose
  -s                   --silent, --quiet
  -c cfgfile           --cfgfile cfgfile
  -S sitekey           --site-keyfile sitekey
  -Q passphrase        --site-passphrase passphrase
  -e                   --no-encryption
configfile.txt

The -v and -s options are mutually exclusive.
Exactly one of -e or -S must be specified.
The -Q option is valid only with -S.

Print Configuration File mode:
  -m f                 --print-cfgfile
  -v                   --verbose
  -s                   --silent, --quiet
  -c cfgfile           --cfgfile cfgfile

The -v and -s options are mutually exclusive.

Replace Policy File mode:
  -m P                 --create-polfile
  -v                   --verbose
  -s                   --silent, --quiet
  -c cfgfile           --cfgfile cfgfile
  -p polfile           --polfile polfile
  -S sitekey           --site-keyfile sitekey
  -Q passphrase        --site-passphrase passphrase
  -e                   --no-encryption
policyfile.txt

The -v and -s options are mutually exclusive.
The -e and -S options are mutually exclusive.
The -e and -Q options are mutually exclusive.

Print Policy File mode:
  -m p                 --print-polfile
  -v                   --verbose
  -s                   --silent, --quiet
  -c cfgfile           --cfgfile cfgfile
  -p polfile           --polfile polfile
  -S sitekey           --site-keyfile sitekey

The -v and -s options are mutually exclusive.

Remove Encryption mode:
  -m R                 --remove-encryption
  -v                   --verbose
  -s                   --silent, --quiet
  -c cfgfile           --cfgfile cfgfile
  -L localkey          --local-keyfile localkey
  -S sitekey           --site-keyfile sitekey
  -P passphrase        --local-passphrase passphrase
  -Q passphrase        --site-passphrase passphrase
file1 [file2 ...]

The -v and -s options are mutually exclusive.

Encryption mode:
  -m E                 --encrypt
  -v                   --verbose
  -s                   --silent, --quiet
  -c cfgfile           --cfgfile cfgfile
  -L localkey          --local-keyfile localkey
  -S sitekey           --site-keyfile sitekey
  -P passphrase        --local-passphrase passphrase
  -Q passphrase        --site-passphrase passphrase
file1 [file2 ...]

The -v and -s options are mutually exclusive.

Examine Encryption mode:
  -m e                 --examine
  -v                   --verbose
  -s                   --silent, --quiet
  -c cfgfile           --cfgfile cfgfile
  -L localkey          --local-keyfile localkey
  -S sitekey           --site-keyfile sitekey
file1 [file2 ...]

The -v and -s options are mutually exclusive.

Generate Keys mode:
  -m G                 --generate-keys
  -v                   --verbose
  -s                   --silent, --quiet
  -L localkey          --local-keyfile localkey
  -S sitekey           --site-keyfile sitekey
  -P passphrase        --local-passphrase passphrase
  -Q passphrase        --site-passphrase passphrase

The -v and -s options are mutually exclusive.
Exactly one of -S or -L must be specified.

#

著作権、商標等について (C) 2001 HyperDyne Inc.