好久没有认真写过文章了,主要觉得现在好多文章都有整理的比较完善,没有必要做那些无用功,把别人整理很好的文档自己再整理一次。
          不过最近我在安装数据完整性检测工具“Tripwire”的时候确遇见不少麻烦,主要是资料过老,或者不其,或者文章中提到包安装包找不到之类的问题。今天我就构建linux数据完整性检测写一个教程,避免继续有人走我的弯路。
 
 
一、简介。数据完整性检测工具的重要性我就不多提了,这个肯定是每个服务器必须的。对服务器被hack***后,的恢复和发现***有很大的作用。Tripwire软件是Dr.Eugene and Gene Kim  1992年写的。当时只是商业软件,而且很贵,直到1999年发布了源代码,并有了GPL得版权。现在Tripwire还有分商业版和开源版,开源版主要使用在linux上。
 
二、下载软件开源的tripwire的主页是 www.tripwire.org
 
http://sourceforge.net/projects/tripwire/files/下载2.4.1.2-x86-bin.tar.bz2 1.8M的源码包。
 
三、安装。好了,准备工作基本完成,现在我们开始安装Tripwire。
 
1、解压下载的源码包
#tar -jxvf tripwire-2.4.1.2-x86-bin.tar.bz2
# cd tripwire-2.4.1.2-x86-bin          进入安装包
[root@station253 tripwire-2.4.1.2-x86-bin]# cp ./install/install.sh ./      拷贝安装脚本install.sh 到当前目录
[root@station253 tripwire-2.4.1.2-x86-bin]# ./install.sh         在当前目录运行这个脚本,然后按照提示,先按回车,看了协议一定要输入accept。
 
结果会报错,错误提示如下
Error: configuration parameter $TWPOLICY undefined.
There is an error in the configuration file ./install/install.cfg.
发现时install.cfg有问题,我们就去看看。
[root@station253 tripwire-2.4.1.2-x86-bin]# vim install/install.cfg
查找TWPOLICY这个变量,结果发现时这个
TWPOLICY="${sysconfdir}"  原来是我们没有定义配置文件的目录
在此文件TWPOLICY变量前面,不印引向其他变量的地方添加如下设定
sysconfdir=/etc/tripwire/ 然后保存退出
[root@station253 tripwire-2.4.1.2-x86-bin]# mkdir /etc/tripwire       创建刚才定义的目录。
然后再运行 install.sh
 
又报错了,错误如下
*** No sendmail found. Edit install.cfg and set
*** TWMAILPROGRAM to full path to sendmail, or
*** change TWMAILMETHOD to SMTP and set SMTP
*** settings appropriately.
简单看下配置文件,原来有sendmail依耐关系,好的。我们安装sendmail,具体安装sendmail方法自己查资料。
[root@station253 tripwire-2.4.1.2-x86-bin]# vim install/install.cfg    打开安装配置文件,查找sendmail
if [ -z "$path_to_sendmail" ] ; then
   TWMAILPROGRAM=""
else
   TWMAILPROGRAM="${path_to_sendmail} -oi -t"
fi
在安装配置文件最后面,需要定义sendmail的路径。使用witch命令找到sendmail的路径,并修改。
[root@station253 tripwire-2.4.1.2-x86-bin]# which  sendmail
/usr/sbin/sendmail
if [ -z "/usr/sbin/sendmail" ] ; then
   TWMAILPROGRAM=""
else
   TWMAILPROGRAM="/usr/sbin/sendmail -oi -t"
fi
然后保存退出,接着我们在运行 install.sh试试
 
Verifying existence of binaries...
./bin/siggen found
./bin/tripwire found
./bin/twprint found
./bin/twadmin found
This program will copy Tripwire files to the following directories:
        TWBIN: /usr/sbin
        TWMAN: /usr/man
     TWPOLICY: /etc/tripwire
     TWREPORT: /usr/lib/tripwire/report
         TWDB: /usr/lib/tripwire
 TWSITEKEYDIR: /etc/tripwire
TWLOCALKEYDIR: /etc/tripwire
CLOBBER is false.
Continue with installation? [y/n]
 这次已经能成功走到这一步了,当然输入y。
 
在感觉要成功的时候又报错了。
Creating key files...
./install.sh: line 675: /usr/sbin/twadmin: No such file or directory
Error: site key generation failed
我们去看看这个install.sh的675行到底写了些什么东西。
“653 echo "Creating key files..."
654
655 ##-------------------------------------------------------
656 ## Site key file.
657 ##-------------------------------------------------------
658
659 # If clobber is true, and prompting is off (unattended operation)
660 # and the key file already exists, remove it.  Otherwise twadmin
661 # will prompt with an "are you sure?" message.
662
663 if [ "$CLOBBER" = "true" ] && [ "$PROMPT" = "false" ] && [ -f "$SITE_KEY" ] ; then
664         rm -f "$SITE_KEY"
665 fi
666
667 if [ -f "$SITE_KEY" ] && [ "$CLOBBER" = "false" ] ; then
668         echo "The site key file \"$SITE_KEY\""
669         echo 'exists and will not be overwritten.'
670 else
671         cmdargs="--generate-keys --site-keyfile \"$SITE_KEY\""
672         if [ -n "$TW_SITE_PASS" ] ; then
673                 cmdargs="$cmdargs --site-passphrase \"$TW_SITE_PASS\""
674         fi
675         eval "\"$TWADMIN\" $cmdargs"
676         if [ $? -ne 0 ] ; then
677                 echo "Error: site key generation failed"
678                 exit 1
679         else chmod 640 "$SITE_KEY"
680         fi
681 fi
”我们出错的地方就在这段语句,仔细看看,
675         eval "\"$TWADMIN\" $cmdargs" 原来是这句出了问题,在脚本里面搜索一下TWADMIN,发现如下有用信息
625 TWADMIN="${TWBIN}/twadmin"
原来是一个叫twadmin的命令需要执行,刚才的错误就是没有找到这个命令。我网上google了一下twadmin这个命令,没什么收获,不知道什么包里面的。在本地找了一下也没发现这个工具。最后在安装包的bin目录找到了这个执行命令。
[root@station253 tripwire-2.4.1.2-x86-bin]# ls ./bin/
siggen    tripwire  twadmin   twprint                            于是我把几个命令全部拷贝到/usr/sbin/里面去。
[root@station253 bin]# cp *  /usr/sbin/
然后修改install.sh配置文件
TWADMIN="/usr/sbin/twadmin" 然后在运行 install.sh试试
还有错误
 
Creating key files...
/usr/sbin/twadmin: error while loading shared libraries: libcrypto.so.0.9.8: cannot open shared object file: No such file or directory
Error: site key generation failed
这次是没有找到openssl的库文件,这个好办。[root@station253 tripwire-2.4.1.2-x86-bin]# ln -s /lib/libcrypto.so.0.9.8e /lib/libcrypto.so.0.9.8
然后再运行install.sh。
Enter the site keyfile passphrase:
现在要求输入keyfile的密码,你住你输入的密码。然后确认一次。
 
Enter the local keyfile passphrase:
然后再次输入local keyfile密码两次。
 
然后就是用你刚才的site密码创建配置文件和策略。
 
 
 
让人兴奋的东西终于出现了

----------------------------------------------
The installation succeeded.
Please refer to
for release information and to the printed user documentation
for further instructions on using Tripwire 2.4 Open Source.
已经succeeded了,剩下的就是其他配置工作,和如何使用tripwre,让自己的服务器更安全。
 
 
Centos5.3下构建数据完整性监测系统Tripwire(2.使用技巧)剩下的知识我讲尽快写出来,与大家分享。