Tripwireインストール
[root@falcon21 ~]# yum -y install tripwire インストール済み: tripwire-2.4.3.7-5.el8.x86_64 完了しました! tripwire初期設定 setup-keyfiles」 [root@falcon21 ~]# 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. ------------------------- Tripwire設定 [root@falcon21 ~]# vi /etc/tripwire/twcfg.txt 9 LOOSEDIRECTORYCHECKING =true 12 REPORTLEVEL =4 [root@falcon21 ~]# 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@falcon21 ~]# rm -f /etc/tripwire/twcfg.txt ************************************************************* ポリシーファイルを最適化スクリプト作成 [root@falcon21 ~]# 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@falcon21 ~]# perl /etc/tripwire/twpolmake.pl /etc/tripwire/twpol.txt > /etc/tripwire/twpol.txt.new [root@falcon21 ~]# echo ! "/var/lib/tripwire/`hostname`.twd ;" >> /etc/tripwire/twpol.txt.new [root@falcon21 ~]# echo ! "/tmp/tripwire.log ;" >> /etc/tripwire/twpol.txt.new [root@falcon21 ~]# 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@falcon21 ~]# rm -f /etc/tripwire/twpol.txt* ------------------------------------------------- Tripwireデータベース作成 ・・・少し、時間がかかる。 [root@falcon21 ~]# tripwire -m i -s -c /etc/tripwire/tw.cfg Please enter your local passphrase: ***************************************************************************************************************************************************************** Tripwire確認 [root@falcon21 ~]# tripwire -m c -s -c /etc/tripwire/tw.cfgOpen Source Tripwire(R) 2.4.3.7 Integrity Check ReportReport generated by: rootReport created on: 2020年11月28日 14時32分42秒Database last updated on: Never===============================================================================Report Summary:===============================================================================Host name: falcon21.spaceHost IP address: 203.181.3.94Host ID: NonePolicy file used: /etc/tripwire/tw.polConfiguration file used: /etc/tripwire/tw.cfgDatabase file used: /var/lib/tripwire/falcon21.space.twdCommand line used: tripwire -m c -s -c /etc/tripwire/tw.cfg===============================================================================Rule Summary:===============================================================================-------------------------------------------------------------------------------Section: Unix File System-------------------------------------------------------------------------------Rule Name Severity Level Added Removed Modified--------- -------------- ----- ------- --------User binaries 66 0 0 0Tripwire Binaries 100 0 0 0Libraries 66 0 0 0Operating System Utilities 100 0 0 0File System and Disk Administraton Programs100 0 0 0Kernel Administration Programs 100 0 0 0Networking Programs 100 0 0 0System Administration Programs 100 0 0 0Hardware and Device Control Programs100 0 0 0System Information Programs 100 0 0 0Application Information Programs100 0 0 0(/sbin/rtmon)Critical Utility Sym-Links 100 0 0 0Shell Binaries 100 0 0 0Critical system boot files 100 0 0 0Tripwire Data Files 100 0 0 0System boot changes 100 0 0 0OS executables and libraries 100 0 0 0Security Control 100 0 0 0Login Scripts 100 0 0 0Critical configuration files 100 0 0 0Root config files 100 0 0 0Invariant Directories 66 0 0 0Temporary directories 33 0 0 0Critical devices 100 0 0 0(/proc/kcore)Total objects scanned: 58518Total 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 registeredtrademark of Tripwire, Inc. This software comes with ABSOLUTELY NO WARRANTY;for details use --version. This is free software which may be redistributedor modified only under certain conditions; see COPYING for details.All rights reserved.*************************************************************************** Tripwire定期自動実行スクリプト作成設定 [root@falcon21 ~]# vi tripwire.sh #!/bin/bash # 既存のTripwire定期自動実行設定削除 rm -f /etc/cron.daily/tripwire-check # パスフレーズ設定 LOCALPASS=1qazse4 SITEPASS=4eszaq1 TRIPWIRE=/usr/sbin/tripwire TWADMIN=/usr/sbin/twadmin TWPRINT=/usr/sbin/twprint cd /etc/tripwire # Tripwireチェック実行 # ※ファイル変更を検知した場合のみroot宛にサマリをメールする rm -f /var/lib/tripwire/report/`hostname`-`date +%Y%m%d`-*.twr ${TRIPWIRE} -m c -s -c tw.cfg > /tmp/tripwire.log if [ $(grep "Total violations found" /tmp/tripwire.log | awk '{print $4}') -ne 0 ]; then ${TWPRINT} -m r --report-level 1 -c tw.cfg -r /var/lib/tripwire/report/`hostname`-`date +%Y%m%d`-*.twr | \ mail -s "Tripwire Integrity Check Report from `hostname`" root fi # Tripwireチェック実行結果(過去分)削除 # ※過去90日分保管 tmpwatch -m 2160 /var/lib/tripwire/report # ポリシーファイル最新化 ${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* *.bak # データベース最新化 rm -f /var/lib/tripwire/*.twd* ${TRIPWIRE} -m i -s -c tw.cfg -P $LOCALPASS =============================================================================== No Errors * End of report * Open Source Tripwire 2.4 Portions copyright 2000-2017 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. *************************************************************************** [root@falcon21 ~]# chmod 700 tripwire.sh [root@falcon21 ~]# echo "0 3 * * * root /root/tripwire.sh" > /etc/cron.d/tripwire ************************************************************************* 変更がわかっているディレクトリやファイルについては検知されないようにする [root@falcon21 ~]# twadmin -m p -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key > /etc/tripwire/twpol.txt [root@falcon21 ~]# echo '!/var/log/sa ;' >> /etc/tripwire/twpol.txt [root@falcon21 ~]# echo '!/etc/sysconfig/iptables ;' >> /etc/tripwire/twpol.txt [root@falcon21 ~]# 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@falcon21 ~]# rm -f /etc/tripwire/twpol.txt /etc/tripwire/tw.pol.bak [root@falcon21 ~]# rm -f /var/lib/tripwire/*.twd* ; tripwire -m i -s -c /etc/tripwire/tw.cfg Please enter your local passphrase: ・・・少し、時間がかかる。 **********************************************************************************
投票数:0
平均点:0.00