|
|
wget [url]http://jaist.dl.sourceforge.net/sourceforge/tripwire/tripwire-2.3.1-2.tar.gz[/url] ← 下载源代码
tar zxvf tripwire-2.3.1-2.tar.gz
← 将被压缩的文件展开
cd tripwire-2.3.1-2 ← 进入被解压缩的目录 wget [url]http://distfiles-od.opendarwin.org/tw-20030919.patch.gz[/url] ← 下载 Tripwire Patch文件
gunzip tw-20030919.patch.gz
← 将 Tripwire Patch 文件解压缩
patch -p1 < tw-20030919.patch ← Patch编译 chmod 755 configure ← 赋予配置文件configure可执行的权限
./configure --sysconfdir=/etc/tripwire
← 运行configure
…………………………………… …………………………………… ……中间提示信息省略…… …………………………………… …………………………………… make ← 编译 …………………………………… …………………………………… ……中间提示信息省略…… ……需要花费一段时间…… …………………………………… …………………………………… make install ← 安装配置 …………………………………… …………………………………… ……中间提示信息省略………… …………………………………… ……………………………………
← 按回车键阅读协议
…………………………………… …………………………………… 协议浏览中按空格键翻页 …………………………………… …………………………………… accept ← 输入“accept”同意协议
y
← 键入y继续安装
← 输入“site keyfile”口令(输入后不会显示),并且记住这个口令
← 再次确认“site keyfile”口令
← 输入“local keyfile”口令(输入后不会显示),并且记住这个口令
← 再次确认“local keyfile”口令
← 输入“site keyfile”口令(输入后不会显示)
← 输入“site keyfile”口令(输入后不会显示)
cd ← 回到root用户的根目录rm -rf tripwire-2.3.1-2 tripwire-2.3.1-2.tar.gz ← 删除安装用过的原文件 |
|
vi /etc/tripwire/twcfg.txt ← 修改文本格式的Tripwire配置文件 LOOSEDIRECTORYCHECKING =false ← 找到这一个行,将false的值变为true(不监测所属目录的数据完整性) ↓ LOOSEDIRECTORYCHECKING =true ← 变为此状态 REPORTLEVEL =3 ← 找到这一行,将3变为4(改变监测结果报告的等级) ↓ REPORTLEVEL =4 ← 变为此状态 twadmin --create-cfgfile -S /etc/tripwire/site.key /etc/tripwire/twcfg.txt ← 从文本配置文件建立加密格式配置文件 ← 输入“site keyfile”口令(输入后不会显示) rm -f /etc/tripwire/twcfg.txt ← 为不留安全隐患,删除文本格式的配置文件 |
vi /etc/tripwire/twpolmake.pl ← 建立用于建立Policy文件的Perl脚本
#!/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>) {
perl /etc/tripwire/twpolmake.pl /etc/tripwire/twpol.txt > /etc/tripwire/twpol.txt.out ← 建立Policy文件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) ; rm -f /etc/tripwire/twpol.txt ← 删除默认Policy文件 mv /etc/tripwire/twpol.txt.out /etc/tripwire/twpol.txt ← 将新建立的Policy文件的名改为默认Policy文件的文件名 vi /etc/tripwire/twpol.txt ← 编辑Policy文件 ← 找到这一行,在这一行的下一行添加语句(113行前后) !$(TWDB)/$(HOSTNAME).twd ; ← 添加这一句(不对数据库进行监测) twadmin --create-polfile -S /etc/tripwire/site.key /etc/tripwire/twpol.txt ← 从文本配置文件建立加密格式配置文件 ← 输入“site keyfile”口令(输入后不会显示) rm -f /etc/tripwire/twcfg.txt ← 为不留安全隐患,删除文本格式的配置文件 |
tripwire --init ← 建立数据库 ← 输入“local keyfile”口令(输入后不会显示) |
|
vi tripwire-check ← 建立Tripwire运行脚本
#!/bin/bash
PATH=/usr/local/sbin:/usr/bin:/bin
SITEPASS= ******** # Site Key Passphrase ← 将星号部分换为Site Keyfile的口令 LOCALPASS= ******** # Local Key Passphrase ← 将星号部分换为Local Keyfile的口令 REPORTFILE=/usr/local/lib/tripwire/report/`hostname`-`date +%Y%m%d`.twr
# Run the Tripwire
tripwire --check -r "$REPORTFILE"| logger -t tripwire
# Mail the Tripwire Report to root
cd /etc/tripwire REPORTPRINT=`mktemp` twprint -m r -c tw.cfg -r "$REPORTFILE" -L `hostname`-local.key -t 4 > $REPORTPRINT if [ -z "$(grep 'Total violations found: 0' $REPORTPRINT)" ]; then cat $REPORTPRINT | mail -s "Tripwire(R) Integrity Check Report in `hostname`" root fi rm -f $REPORTPRINT
# Update the Policy File
# update the Databasecd /etc/tripwire twadmin --print-polfile > twpol.txt perl twpolmake.pl twpol.txt > twpol.txt.out twadmin --create-polfile -S site.key -Q $SITEPASS twpol.txt.out | logger -t tripwire rm -f twpol.* rm -f /usr/local/lib/tripwire/`hostname`.twd tripwire --init -P $LOCALPASS | logger -t tripwire chmod 700 tripwire-check ← 赋予运行脚本文件可执行的权限 |
./tripwire-check ← 运行一次脚本 由于增加了运行脚本本身,也被认作系统被作了改动,会发邮件通知root…查看邮箱回收到监测报告 ./tripwire-check ← 再次运行一次脚本 由于两次连续运行,之间不太可能有文件变更,所以请确认不会发送E-mail给root |
ls -l /usr/local/lib/tripwire/report/ ← 监测报告所在目录的文件列表 ← 比如想浏览此篇报告 cd /etc/tripwire ← 进入Tripwire配置文件所在目录 twprint -m r -c tw.cfg -r "/usr/local/lib/tripwire/report/sample.centospub.com-20060823.twr" -L sample.centospub.com-local.key -t 4 > tripwire-report ← 将监测报告保存到名为tripwire-report的文件中 cat tripwire-report ← 浏览监测报告 rm -f tripwire-report ← 删除监测报告 |
cd ← 进入Tripwire运行脚本所在的root目录 mv tripwire-check /etc/cron.daily/ ← 转移脚本到每天自动运行的目录中 |