当服务器遭到黑客攻击时,在多数情况下,黑客可能对系统文件等等一些重要的文件进行修改。对此,我们用Tripwire建立数据完整性监测系统。虽然它不能抵御黑客攻击以及黑客对一些重要文件的修改,但是可以监测文件是否被修改过以及哪些文件被修改过,从而在被攻击后有的放矢的策划出解决办法。Tripwire的原理是Tripwire被安装、配置后,将当前的系统数据状态建立成数据库,随着文件的添加、删除和修改等等变化,通过系统数据现状与不断更新的数据库进行比较,来判定哪些文件被添加、删除和修改过。正因为初始的数据库是在Tripwire本体被安装、配置后建立的原因,我们务必应该在服务器开放前,或者说操作系统刚被安装后用Tripwire构建数据完整性监测系统。
环境:OS:Centos6.2软件:tripwire-2.4.2.2-src.tar.bz2
二、安装
1、解压
#tar-jxvftripwire-2.4.2.2-src.tar.bz2#cdtripwire-2.4.2.2-src2、配置
#./configure--prefix=/opt/tripwire←设置安装目录注:如果出现这样的错误:
#yuminstallglibc-headers#yuminstallgcc-c++3、编译
#make--过程省略--
4、安装过程
#makeinstall--出现协议--
licenseagreement.[donotaccept]accept←输入“accept”同意协议。
--过程省略--
Continuewithinstallation[y/n]y←键入y继续安装。
Enterthesitekeyfilepassphrase:←输入“sitekeyfile”口令(输入后不会显示),并且记住这个口令。Verifythesitekeyfilepassphrase:←再次确认“sitekeyfile”口令。
Enterthelocalkeyfilepassphrase:←输入“localkeyfile”口令(输入后不会显示),并且记住这个口令。Verifythelocalkeyfilepassphrase:←再次确认“localkeyfile”口令。
Pleaseenteryoursitepassphrase:←输入“sitekeyfile”口令(输入后不会显示)第一次。
Pleaseenteryoursitepassphrase:←输入“sitekeyfile”口令(输入后不会显示)第二次。
安装完成。
三、文件说明
(1)、配置文件:定义数据库、策略文件和Tripwire可执行文件的位置:
/opt/tripwire/etc/twcfg.txt
(2)、策略:定义检测的对象及违规时采取的行为:
/opt/tripwire/etc/twpol.txt
(3)、数据库:用于存放生成的快照:
/opt/tripwire/lib/tripwire/$(HOSTNAME).twd
(4)、Tripwire为了自身的安全,防止自身被篡改,也会对自身进行加密和签名处理。其中,包括两个密钥:
(4.1)、site密钥:用于保护策略文件和配置文件,只要使用相同的策略和配置的机器,都可以使用相同的site密钥:
/usr/local/tripwire/etcsite.key
(4.2)、local密钥:用户保护数据库和分析报告,这肯定不会重复的:
/usr/local/tripwire/etc/$(HOSTNAME)-local.key
四、设置tripwire
4.1、编辑twcfg.txt文件
vi/opt/tripwire/etc/twcfg.txt←修改文本格式的Tripwire配置文件LOOSEDIRECTORYCHECKING=false←找到这一个行,将false的值变为true(不监测所属目录的数据完整性)LOOSEDIRECTORYCHECKING=true←变为此状态REPORTLEVEL=3←找到这一行,将3变为4(改变监测结果报告的等级)REPORTLEVEL=4←变为此状态#wq←保存退出4.2、建立加密格式
#cd/opt/tripwire/etc#/opt/tripwire/sbin/twadmin--create-cfgfile-Ssite.keytwcfg.txt←从文本配置文件建立加密格式配Pleaseenteryoursitepassphrase:←输入“sitekeyfile”口令Wroteconfigurationfile:/usr/local/tripwire/etc/tw.cfg完成。五、初始化数据库
#/opt/tripwire/sbin/tripwire--init←初始化数据库Pleaseenteryourlocalpassphrase:←输入“localkeyfile”口令六、更新数据库
当你更新了twpol.txt后需用此命令更新数据库
#cd/opt/tripwire#./sbin/tripwire--update-policy--secure-modelow/opt/tripwire/etc/twpol.txtPleaseenteryourlocalpassphrase:←输入“localkeyfile”口令Pleaseenteryoursitepassphrase:←输入“sitekeyfile”口令
Wrotedatabasefile:/usr/local/tripwire/lib/tripwire/localhost.localdomain.twdThedatabasewassuccessfullygenerated
七、检查文件异动
安装完tripwire后你可以定期检查文件是否存在异动。加上interactive在当前显示结果。
./sbin/tripwire--check--interactive八、查看报告
所有tripwire的报告以.twr后缀保存在lib/tripwire目录下,需要使用twprint命令来转化成文本格式。
#./sbin/twprint--print-report--twrfile/lib/tripwire/report/localhost.localdomain-20100225-164220.twr>/tmp/tripwire_readable.txt#vi/tmp/tripwire_readable.txt或直接查看#./sbin/twprint--print-report--twrfile/lib/tripwire/report/localhost.localdomain-20100225-164220.twr