Tripwireはファイルの改竄検知などで実績の多いツールになります。
日本でもセキュリティ要件の高い観光庁や金融系での導入が非常に多いツールとなります。
Tripwireは、1992年に米国パデュー大学に在学中のジーン・キム(Tripwire, Inc. 共同創立者)によって開発されたソフトウェアに付けられた名前です。当時のソフトウェアは、現在も Open Source Tripwire® の名でOSS (Open Source Software) として入手可能です。
1997 年に Tripwire, Inc. が米オレゴン州ポートランドに設立され、変更検知に特化した商用ソフトウェアの開発、販売を開始し、現在では9,000社以上の導入実績を持ちます。
「トリップワイヤ・ジャパン株式会社」より引用
現在でもOSSの「Open Source Tripwire」と製品版の「Tripwire Enterprise」があります。
今回はCentOS8にdnfでのインストールを行います。
・インストール環境:CentOS8
・インストールアプリ:tripwire-2.4.3.7-5.el8
Tripwireのインストール
ELEPを有効にする
dnfでのインストールはEPELのリポジトリを有効にする必要があります。
1 2 3 |
$ sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm |
インストール
インストールは以下で行います。
1 2 3 |
$ sudo dnf --enablerepo=epel -y install tripwire |
キーの生成
設定ファイルなどの作成には、暗号化・署名を行うための暗号鍵(サイトキー、ローカルキー)を生成が必要です。
tripwireでは以下の2種類のキーが必要になります。
【サイトキー】
サイト全体で共通の設定ファイル、ポリシーファイルの暗号化・署名に使用します。
「/etc/tripwire/site.key」が生成されます。
【ローカルキー】
ローカルデータベースの更新、レポートファイルの保護に使用します。
「/etc/tripwire/ホスト名-local.key」が生成されます。
キーの生成は以下のコマンドで行います。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
$ sudo 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. |
設定ファイルが生成されます。
設定ファイルの編集
設定ファイルはプログラムの場所やメールの設定など基本的な部分を記載する設定ファイルです。
設定の元となるテキストファイルを編集します。
1 2 3 4 |
$ cd /etc/tripwire $ vi twcfg.txt |
こちらのファイルを元に暗号署名した設定ファイルを生成します。
1 2 3 4 5 |
$ sudo twadmin --create-cfgfile --site-keyfile /etc/tripwire/site.key /etc/tripwire/twcfg.txt Please enter your site passphrase: Wrote configuration file: /etc/tripwire/tw.cfg |
システムから読み込み可能ファイルがこちらで生成されました。
設定ファイルの確認を行います。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ sudo twadmin -m f -c /etc/tripwire/tw.cfg 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 MAILNOVIOLATIONS =true EMAILREPORTLEVEL =3 REPORTLEVEL =3 MAILMETHOD =SENDMAIL SYSLOGREPORTING =false MAILPROGRAM =/usr/sbin/sendmail -oi -t |
こちらで設定ファイルの確認まで実施できました。
ポリシーファイルの設定と生成
ポリシーファイルは、Tripwireによってどのファイル・ディレクトリをどのようなルールで監視するかというポリシーを定めるものです。
こちらの設定を行いますがデフォルトでは存在しないファイルやディレクトリを多数チェックをされてエラーが出るので以下のファイルを使って修正を行います。
こちらのプログラムですがネットではかなり昔から流通しているようで元ファイルが何処か分からずで。
ライセンスも表示されているのでありがたく利用させていただきます。
1 2 3 |
$ vi /usr/local/src/twpolmake.pl |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
#!/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} # ---------------------------------------------------------------- # #ここまでを1回目で作成して行頭に「#」の無い行を挿入して、以下をします。 $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) ; |
変換をかけます。
1 2 3 |
$ perl /usr/local/src/twpolmake.pl /etc/tripwire/twpol.txt > /etc/tripwire/twpol.txt.new |
以下のコマンドでシステムから読み込み可能なポリシーファイルを作ります。
1 2 3 4 5 |
$ sudo twadmin --create-polfile --cfgfile /etc/tripwire/tw.cfg /etc/tripwire/twpol.txt.new Please enter your site passphrase: Wrote policy file: /etc/tripwire/tw.pol |
データベースの初期化
以下のコマンドでデータベースの初期化を行います。
1 2 3 |
$ sudo tripwire --init |
システム変更履歴のチェック
こちらで準備ができました。
それではシステムの変更履歴をチェックします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
$ sudo tripwire --check Parsing policy file: /etc/tripwire/tw.pol *** Processing Unix File System *** Performing integrity check... Wrote report file: /var/lib/tripwire/report/test01-20210412-161918.twr Open Source Tripwire(R) 2.4.3.7 Integrity Check Report Report generated by: root Report created on: Mon Apr 12 16:19:18 2021 Database last updated on: Never =============================================================================== Report Summary: =============================================================================== Host name: test01 Host IP address: xxx.xxx.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/test01.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 Libraries 66 0 0 0 Operating System Utilities 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) Critical Utility Sym-Links 100 0 0 0 Shell Binaries 100 0 0 0 Critical system boot files 100 0 0 0 Tripwire Data 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 Critical configuration files 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 (/proc/kcore) Total objects scanned: 36777 Total violations found: 0 =============================================================================== Object Summary: =============================================================================== ------------------------------------------------------------------------------- # Section: Unix File System ------------------------------------------------------------------------------- No violations. =============================================================================== Error Report: =============================================================================== No Errors ------------------------------------------------------------------------------- *** End of report *** Open Source Tripwire 2.4 Portions copyright 2000-2018 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. |
システムの変更など上記で確認できました。
以下の/etc/passwdと/etc/groupを変更するコマンドを入れてみます。
1 2 3 4 |
$ sudo groupadd -g 300 hogehoge $ sudo useradd -u 300 -g 300 hogehoge |
こちらの状態で再度確認を行っています。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
$ sudo tripwire --check Parsing policy file: /etc/tripwire/tw.pol *** Processing Unix File System *** Performing integrity check... Wrote report file: /var/lib/tripwire/report/test01-20210412-162025.twr Open Source Tripwire(R) 2.4.3.7 Integrity Check Report Report generated by: root Report created on: Mon Apr 12 16:20:25 2021 Database last updated on: Never =============================================================================== Report Summary: =============================================================================== Host name: test01 Host IP address: xxx.xxx.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/test01.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 Libraries 66 0 0 0 Operating System Utilities 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) Critical Utility Sym-Links 100 0 0 0 Shell Binaries 100 0 0 0 Critical system boot files 100 0 0 0 Tripwire Data 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 1 Login Scripts 100 0 0 0 * Critical configuration files 100 0 0 1 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 (/proc/kcore) Total objects scanned: 36777 Total violations found: 2 =============================================================================== Object Summary: =============================================================================== ------------------------------------------------------------------------------- # Section: Unix File System ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- Rule Name: Security Control (/etc/group) Severity Level: 100 ------------------------------------------------------------------------------- Modified: "/etc/group" ------------------------------------------------------------------------------- Rule Name: Critical configuration files (/etc/passwd) Severity Level: 100 ------------------------------------------------------------------------------- Modified: "/etc/passwd" =============================================================================== Error Report: =============================================================================== No Errors ------------------------------------------------------------------------------- *** End of report *** Open Source Tripwire 2.4 Portions copyright 2000-2018 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. |
システムの変更の状態を無事チェックしてくれました。
様々な設定がこちらから行えそうです