您当前的位置: 首页 > CERNET > 疑难解答
Tripwire 应用
  对unix管理员来说,主机系统的安全一直是个课题,一方面管理员通过更新patch,安装软硬件防火墙等手段努力使自己的系统可靠性增强,而另一方面unix操作系统的漏洞总是不断被发现并被公布出来,如BUGTRAQ这样的安全列表,从这个角度上可以很绝对的说,互联网上没有安全的主机。任何一台放在Internet上的主机被入侵的潜在可能性是不可逃脱的,而且,对入侵者而言,利用漏洞进入系统往往只是第一步,如果想得到更多的,如超级用户的密码,数据库的口令等,往往需要下点功夫,最便捷也是最有效的就是改动或特洛伊化受侵害的主机上的文件,如放置自己的监听程序,替代某些关键文件,修改编辑可信文件,设置suid文件等。

  一些管理员通unix自带的命令来检查文件的安全性,如检查文件生成的时间戳,但这样的可靠性微乎其微,有经验的入侵者可以很轻松的修改文件生成时间,有兴趣的管理员可以试试以下操作:
  # echo "+ +" > /.rhosts
  这一步生成一个.rhosts文件,看看它的时间。
  # ls -l /.rhosts
  -rw-r--r-- 1 root other 4 Jul 2 16:45 /.rhosts
  好,我们如下操作看看会怎么样?
  # touch -r /bin/sh /.rhosts
  #ls -l /.rhosts
  -rw-r--r-- 1 root other 4 Apr 5 16:32 /.rhosts

  我们看到时间戳已经变了。变成了一个"老"文件,这样很可能就会逃脱管理员的视线。比如,入侵者替换掉了su文件,在正当用户每次试图su时,这个特洛伊化的su文件都会读取口令并将口令记载下来,然后才把控制权交给真正的su程序,口令通过这种途径泄密了,虽然这不是管理员所期望的,但毕竟unix太大太复杂,发现起来很困难。

  Tripwire就是解决这一问题的经典工具,它是目前最为著名的unix下文件系统完整性检查的软件工具,这一软件采用的技术核心就是对每个要监控的文件产生一个数字签名,保留下来。当文件现在的数字签名与保留的数字签名不一致时,那么现在这个文件必定被改动过了。具体到监控项目,在Tripwire的配置文件中有如下相应说明:
  access permissions and file mode settings, including effective execution settings inode number in the file system

  number of links
  user ID of the owner
  group ID of the group of users to which access may be granted
  size of the item
  date and time the item was last accessed, the last modification made to the item, and the creation date and time associated with the items inode
  由上,我们可以看到Tripwire对文件的管理面是很宽的。

  2: Tripwire的工作原理
  当Tripwire运行在数据库生成模式时,会根据管理员设置的一个配置文件对指定要监控的文件进行读取,对每个文件生成相应数字签名,并将这些结果保存在自己的数据库中,在缺省状态下,MD5和SNCFRN(Xerox的安全哈希函数)加密手段被结合用来生成文件的数字签名。除此以外,管理员还可使用MD4,CRC32,SHA等哈希函数,但实际上,使用上述两种哈希函数的可靠性已相当高了,而且结合MD5和sncfrn两种算法(尤其是sncfrn)对系统资源的耗费已较大,所以在使用时可根据文件的重要性做取舍。当怀疑系统被入侵时,可由Tripwire根据先前生成的,数据库文件来做一次数字签名的对照,如果文件被替换,则与Tripwire数据库内相应数字签名不匹配, 这时Tripwire会报告相应文件被更动,管理员就明白系统不"干净"了。

  有一点要注意,上述保障机制的重点在于数据库内的数字签名,如果数据库是不可靠的,则一切工作都丧失意义。所以在Tripwire生成数据库后,这个库文件的安全极为重要。比较常见的做法是将数据库文件, Tripwire二进制文件,配置文件单独保留到"可拿走并锁起来"的质上,如软盘,将上述文件复制到软盘后,关闭写保护口,锁到保险柜中。除软盘外, 一次性介质,如cd-r也是很好的选择,这样即使侵入者拿到盘也无计可施。除这种办法外,利用PGP等加密工具对上述关键文件进行数字签名也是一个很好的选择。

  当然,当管理员自身对某些文件更动时, Tripwire的数据库必然是需要随之更新的, Tripwire考虑到了这一点,它有四种工作模式:数据库生成,完整性检查,数据库更新。交互更新。当管理员更动文件后,可运行数据库更新模式来产生新的数据库文件。

  3:下载Tripwire,安装前的准备工作
  Tripwire支持绝大多数Unix操作系统,它的安装需要编译环境,如gcc,cc等,还需要gzip,gunzip等解压工具。这些工具管理员可从相应站点获取,这里不讨论。Tripwire可从www.tripwire.com获得,到它的主页download部分,可以看到当前可免费download的Tripwire1.3 ASR版本,下载下来就是。

  4:安装Tripwire
  Tripwire的tar包解开后,我们可以看到如下目录结构,建议先看看根下的README文件,对Tripwire有个整体的了解。随后,我们就可以一步步的安装这个软件了。

  步骤1:匹配主机环境

  在Tripwire的根下有Ported这个文件,它是对支持的系统及相关配置文件的描述,管理员第一步需要打开这个文件,找到符合自己系统的描述,本文的测试环境是solaris2.6,我们截取相关部分来看看,
  vendor: Sun Microsystems, Inc.
  os: SunOS
  os version: 5.x (Solaris 2.x)
  compiler: cc
  cflags: -O
  ldflags:
  libs:
  conf.h: conf-svr4.h
  tw.config: tw.Conf.sunos5
  notes:
  在这一段描述中,要尤其注意的是conf.h 和tw.config对应的行,在下几步的配置中需要用到它们两个对应的文件。此处要注意的是:每种操作系统这两个地方所对应的文件是不同的。

  步骤2:配置监控目标

  进入include目录,编辑config.h文件,将第一步Ported中conf.h后对应的文件名和路径写入config.h开始#include部分,此例中即为
  #include "../configs/conf-svr4.h"
同时注意的是,在configh文件中还有Tripwire配置文件,Tripwire数据库文件的放置路径及生成数据库的文件名等设置,管理员按照个人喜好设置即可编辑好config.h后,还要根据本机情况编辑修改位于configs目录下的Tripwire配置文件,也就是上面Ported 文件中tw.config对应的tw.conf.sunos5,我们知道,对文件,目录等的监控就是在这里设置的。我们一段段的选取一部分这个文件来看看:
  #
  # - : ignore the following atributes
  # + : do not ignore the following attributes
  #
  # p : permission and file mode bits a: access timestamp
  # i : inode number m: modification timestamp
  # n : number of links (ref count) c: inode creation timestamp
  # u : user id of owner 1: signature 1
  # g : group id of owner 2: signature 2
  # s : size of file
  注意上述p,I,n,u,g,s,a,c,1,2等,它表示可以对文件,目录设置的监控项目,管理员可组合使用,最前面的-,+号表示选取或忽略这些属性。如下例:
  /var +pinugsm12-a
  它表示对目录/var下所有文件检查,监控项目分别有文件属性,inode,链接数,属组,属主,修改时间,生成时间,数字签名等,但是,对这个目录下的文件的访问不加监控,如果访问也监控的话,正常的用户访问也会被Tripwire捕捉,这没有必要。
  为了方便起见,Tripwire作者把常见组合做成了模板,如下,
  #
  # Templates: (default) R : [R]ead-only (+pinugsm12-a)
  # L : [L]og file (+pinug-sam12)
  # N : ignore [N]othing (+pinusgsamc12)
  # E : ignore [E]verything (-pinusgsamc12)
  #
  tw.conf.sunos5这个文件再向下,就是管理员根据情况填写了,把需要监控的文件及目录加入列表,赋予相应属性即可。如下:
  / R
  /.rhosts R # may not exist
  /.profile R # may not exist
  /etc/dfs/dfstab R
  /etc/hosts.equiv R
  /etc/inet/inetd.conf R
  /etc/inet/protocols R
  /etc/inet/services R
  /etc/init.d R
  /etc/motd L
  #/etc/named.boot R # may not exist
  /etc/opt R
  /etc/passwd L
  /etc/profile R

  步骤3:编译

  完成上两步后,就可以编译了,在Tripwire的根下,执行make,系统即会自动编译,编译成功后,可以再执行make test,Tripwire会自动检查编译情况及工作状态,它会一段一段的测试,我们选取一段如下:
  === test.Update.sh: DESCRIPTION
  This shell script exercises all the Tripwire integrity checking
  and database update functionalities。
  === test.update.sh: Setting up auxiliary scripts ===
  === test.update.sh: BEGIN ===
  ../src/tripwire -loosedir -c /tmp/twtest/tw.config -d /tmp/twtest/tw.db -i all
  === test.update.sh: testing GROWING (safe) files ===
  === test.update.sh: testing GROWING (unsafe) files ===
  === test.update.sh: testing ADDED files ===
  === test.update.sh: testing DELETED files ===
  === test.update.sh: testing CHANGED files ===
  === test.update.sh: testing input schemes ===
  === test.update.sh: tw.config from stdin
  === test.update.sh: database from stdin
  === test.update.sh: testing complex UPDATE cases
  === test.update.sh: changed ignore-mask (UPDATE file)
  === test.update.sh: changed ignore-mask (UPDATE entry)
  === test.update.sh: testing UPDATED files (7 cases)
  === test.update.sh: case 1: update: add new file ===
  === test.update.sh: case 2: update: delete file ===
  === test.update.sh: case 3: update: update file ===
  === test.update.sh: case 4: nonsense case (skipping) ===
  === test.update.sh: case 6: update: delete entry ===
  === test.update.sh: case 5: update: add entry ===
  === test.update.sh: case 7: update: update entry ===
  === test.update.sh: PASS ===
  我们可以看到,Tripwire对update功能一项项的做检测,并在最后PASS了,当Tripwire所有的检测项目都PASS后,编译就OK了。

  步骤4:生成数据库

  成功编译Tripwire,我们准备开始对需要监控的文件进行扫描,以生成Tripwire数据库,在Tripwire 的src目录下:如下操作。/tripwire -init,则系统会根据tw.conf.sunos5文件内的设置,开始扫描并生成相应的数据库,上面提到,数据库文件的路径是在第二步configh中设置的,在本例中为/var/tripwire,我们得到了名为tw.db_secu.unix.com的数据库文件。建议此时将Tripwire可执行文件,数据库文件,配置文件COPY到软盘等地方,放到安全的地方。以后需要安全鉴别时直接在软盘上执行即可。

  步骤5:测试

  数据库生成了,我们来测试一下吧,首先我们在根下touch生成一个goadd文件,其次我们把根下的.cshrc文件做一下改动,在里面加入几个#注释号。然后我们来运行一下Tripwire看如何:
  / Tripwire -c ./tw.config.sunos5 -d ./tw.db_secu.unix.com
  Tripwire(tm) ASR (Academic Source Release) 1.3.1
  File Integrity Assessment Software
  (c) 1992, Purdue Research Foundation, (c) 1997, 1999 Tripwire
  Security Systems, Inc。 All Rights Reserved。 Use Restricted to
  Authorized Licensees。
  ### Phase 1: Reading configuration file
  ### Phase 2: Generating file list
  ./tripwire: /.profile: No such file or directory
  ./tripwire: /kernel/unix: No such file or directory
  ### Phase 3: Creating file information database
  ### Phase 4: Searching for inconsistencies
  ###
  ### Total files scanned: 4437
  ### Files added: 1
  ### Files deleted: 0
  ### Files changed: 1
  ###
  ### Total file violations: 2
  ###
  added: -rw-r--r-- root 0 Jul 3 18:45:31 2000 /goadd
  changed: -r--r--r-- root 669 Jul 3 18:46:15 2000 /.cshrc
  ### Phase 5: Generating observed/expected pairs for changed files
  ###
  ### Attr Observed (what it is) Expected (what it should be)
  ### =========== ============================= =============================
  /.cshrc
  st_size: 669 668
  st_mtime: Mon Jul 3 18:46:15 2000 Mon Jul 3 09:00:41 2000
  st_ctime: Mon Jul 3 18:46:15 2000 Mon Jul 3 09:00:41 2000
  md5 (sig1): 3z9gKjlZGq5GbeWOxpYaF9 1Z7K0n3ZKAyuPpAZB1G8uq
  snefru (sig2): 1vCDeMR45lpRCChmDithiW 1oRYPpQ:oZA6hVx6Zi4.NG

  可以看到,系统运行经过了5个步骤,首先读取配置文件,其次生成配置文件中设置为需要监控,但实际并不存在的文件列表。第三部生成文件信息库,第四步报告检查情况。我们看到共扫描了4437个文件,其中有一个文件是新增加的,有一个文件发生了改变。在下面它列出了这两个文件-正是我们做了手脚的文件!在最后一步Tripwire将发生了改变的文件现在字节数,生成时间,修改时间, md5, snefru签名及数据库中的记录对比列出,是不是很爽?

  上面我们讲到的是Tripwire的主要功能,在命令行状态下敲入tripwire -h 就会有其它使用参数的介绍,有兴趣的管理员不妨一试。   The Tripwire Product Line
  Tripwire HQ Connector Bundle The HQ Connector bundle is comprised of Tripwires award-winning file integrity software,Tripwire version 2.2.1, and a communications agent that allows the software engine to "talk" to the Tripwire HQ Manager. Tripwire provides support for multiple platforms, including Windows NT, Solaris, Linux, HP-UX, IBM-AIX and others. With the Tripwire HQ Connector bundle, you can unequivocally answer the question: is my data the same today as it was yesterday? This information will help you keep your system in optimal working order and manage any changes - malicious or inadvertent - giving you complete control over data integrity. Tripwire HQ Manager HQ Manager is a software console with a graphical user interface that allows you to control hundreds of installations of HQ Connector. Named HQ Managerbecause its designed to operate as your information integrity headquarters, this product provides you with the very best way to manage data integrity across an enterprise network from a single, centralized location. Tripwire 2.2.1 for Linux With all the same great features as Tripwire 2.2.1 for other operating systems, Tripwire for Linux is available as a free download (without the agent that communicates with HQ Manager). In support of the open source community, Tripwire plans to release an open source version of this product this fall. For more information and future announcements about the open source release, check out www.tripwire.org. Tripwire Academic Source Release 1.3.1 With only slight changes, the Tripwire Academic Source Release (ASR) version 1.3.1 is the same as the original Tripwire software that was developed in 1992 by Dr. Eugene Spafford and Tripwire CTO Gene Kim. Tripwire offers this version as a free download, but does not provide product support for it.
  
  

相关文章:

中国教育和科研计算机网版权与免责声明
①凡本网未注明稿件来源的所有文字、图片和音视频稿件,版权均属本网所有,任何媒体、网站或个人未经本网协议授权不得转载、链接、转贴或以其他方式复制发表。已经本网协议授权的媒体、网站,在下载使用时必须注明"稿件来源:中国教育和科研计算机网",违者本网将依法追究责任。
② 本网注明稿件来源为其他媒体的文/图等稿件均为转载稿,本网转载出于非商业性的教育和科研之目的,并不意味着赞同其观点或证实其内容的真实性。如转载稿涉及版权等问题,请作者在两周内速来电或来函联系。

Copyright(c) 1994-2020 CERNIC,CERNET 京ICP备15006448号-16 京网文[2017]10376-1180号
关于假冒中国教育网的声明 | 版权所有:中国教育和科研计算机网网络中心