tripwire 原理

安装Tripwire检查文件完整性

发布: 2009-8-07 17:05 | 作者: 守住每一天 | 来源: IT运维专家网

安装Tripwire检查文件完整性C1G军火库 作者:C1G
当服务器遭到黑客攻击时,在多数情况下,黑客可能对系统文件等等一些重要的文件进行修改。对此,我们用Tripwire建立数据完整性监测系统。虽然它不能抵御黑客攻击以及黑客对一些重要文件的修改,但是可以监测文件是否被修改过以及哪些文件被修改过,从而在被攻击后有的放矢的策划出解决办法。
Tripwire的原理是Tripwire被安装、配置后,将当前的系统数据状态建立成数据库,随着文件的添加、删除和修改等等变化,通过系统数据现状与不断更新的数据库进行比较,来判定哪些文件被添加、删除和修改过。正因为初始的数据库是在Tripwire本体被安装、配置后建立的原因,我们务必应该在服务器开放前,或者说操作系统刚被安装后用Tripwire构建数据完整性监测系统。
和tripwire差不多的还有AIDE
一.工作原理

二.下载tripwire
tripwire 在sf上的地址
  1. wget http://sourceforge.net/projects/ ... rc.tar.bz2/download
  2. tar jxvf tripwire-2.4.1.2-src.tar.bz2
  3. cd tripwire-2.4.1.2-src

三.安装tripwire
  1. ./configure --prefix=/usr/local/tripwire
  2. make
  3. make install

license agreement. [do not accept] accept
Continue with installation? [y/n] y
Enter the site keyfile passphrase:c1gstudio
Verify the site keyfile passphrase:c1gstudio
Enter the local keyfile passphrase:abcdefgh
Verify the local keyfile passphrase:abcdefgh
Please enter your site passphrase: c1gstudio
Please enter your site passphrase: c1gstudio
四.设置tripwire
编辑twpol.txt来控制对哪些目录进行检查,我这里省略了很多目录
vi /usr/local/tripwire/etc/twpol.txt
  1. #Global Configuration Files
  2. #注释以下目录
  3.   #/etc/mail/statistics           -> $(Growing) ;
  4. #OS Boot Files and Mount Points
  5. #注释以下目录
  6.   #/cdrom                        -> $(Dynamic) ;
  7.   #/floppy                       -> $(Dynamic) ;
  8.   #/mnt                          -> $(Dynamic) ;
  9.   #OS Devices and Misc Directories
  10.   #禁止检查以下目录
  11.   #/opt                          -> $(Dynamic) ;
  12.   #/lost+found                   -> $(Dynamic) ;
  13.   #/var/lost+found               -> $(Dynamic) ;
  14.   #/home/lost+found              -> $(Dynamic) ;
  15. #OS Binaries and Libraries
  16. #禁止检查以下目录
  17.   #/lib                          -> $(ReadOnly) ;
  18.   #/usr/lib                      -> $(ReadOnly) ;
  19.   #/usr/libexec                  -> $(ReadOnly) ;
  20.   #/usr/X11R6/lib                -> $(ReadOnly) ;
  21. #User Binaries and Libraries
  22. #只保留以下三个
  23.   /usr/local/bin                -> $(ReadOnly) ;
  24.   /usr/local/etc                -> $(ReadOnly) ;
  25.   /usr/local/sbin               -> $(ReadOnly) ;
  26. #Temporary Directories
  27. #禁止全部目录
  28.   #/usr/tmp                      -> $(Temporary) ;
  29.   #/var/tmp                      -> $(Temporary) ;
  30.   #/tmp                          -> $(Temporary) ;
  31. #Monitor Filesystems
  32. #禁止全部目录
  33.   #/                             -> $(ReadOnly) ;
  34.   #/home                         -> $(ReadOnly) ;  # Modify as needed
  35.   #/usr                          -> $(ReadOnly) ;
  36.   #/var                          -> $(ReadOnly) ;

五.初始化数据库
/usr/local/tripwire/sbin/tripwire --init
六.更新数据库
当你更新了twpol.txt后需用此命令更新数据库
cd /usr/local/tripwire
./sbin/tripwire --update-policy --secure-mode low ./etc/twpol.txt
  1. Please enter your local passphrase: abcdefgh
  2. Please enter your site passphrase: c1gstudio
  3. ======== Policy Update: Processing section Unix File System.
  4. ======== Step 1: Gathering information for the new policy.
  5. The object: "/etc/rhgb/temp" is on a different file system...ignoring.
  6. ### Warning: Policy Update Changed Object.
  7. ### An object has been changed since the database was last updated.
  8. ### Object name: Conflicting properties for object
  9. ### /usr/local/tripwire/etc/tw.pol
  10. ### > Modify Time
  11. ### > CRC32
  12. ### > MD5
  13. ### Continuing...
  14. ### Warning: Policy Update Changed Object.
  15. ### An object has been changed since the database was last updated.
  16. ### Object name: Conflicting properties for object /etc/cups/certs
  17. ### > Modify Time
  18. ### > Change Time
  19. ### Continuing...
  20. ### Warning: Policy Update Changed Object.
  21. ### An object has been changed since the database was last updated.
  22. ### Object name: Conflicting properties for object /etc/cups/certs/0
  23. ### > Modify Time
  24. ### > Change Time
  25. ### > CRC32
  26. ### > MD5
  27. ### Continuing...
  28. ======== Step 2: Updating the database with new objects.
  29. ======== Step 3: Pruning unneeded objects from the database.
  30. Wrote policy file: /usr/local/tripwire/etc/tw.pol
  31. Wrote database file: /usr/local/tripwire/lib/tripwire/local.c1gstudio.com.twd

七.检查文件异动
安装完tripwire后你可以定期检查文件是否存在异动
加上interactive在当前显示结果
./sbin/tripwire --check --interactive
  1. Parsing policy file: /usr/local/tripwire/etc/tw.pol
  2. *** Processing Unix File System ***
  3. Performing integrity check...
  4. The object: "/etc/rhgb/temp" is on a different file system...ignoring.
  5. Wrote report file: /usr/local/tripwire/lib/tripwire/report/local.c1gstudio.com-20090807-112337.twr
  6. Open Source Tripwire(R) 2.4.1 Integrity Check Report
  7. Report generated by:          root
  8. Report created on:            2009年08月07日 星期五 11时23分37秒
  9. Database last updated on:     2009年08月07日 星期五 11时09分27秒
  10. ===============================================================================
  11. Report Summary:
  12. ===============================================================================
  13. Host name:                    local.c1gstudio.com
  14. Host IP address:              127.0.0.1
  15. Host ID:                      None
  16. Policy file used:             /usr/local/tripwire/etc/tw.pol
  17. Configuration file used:      /usr/local/tripwire/etc/tw.cfg
  18. Database file used:           /usr/local/tripwire/lib/tripwire/local.c1gstudio.com.twd
  19. Command line used:            ./sbin/tripwire --check --interactive
  20. ===============================================================================
  21. Rule Summary:
  22. ===============================================================================
  23. -------------------------------------------------------------------------------
  24.   Section: Unix File System
  25. -------------------------------------------------------------------------------
  26.   Rule Name                       Severity Level    Added    Removed  Modified
  27.   ---------                       --------------    -----    -------  --------
  28. * Tripwire Data Files             0                 0        0        1
  29.   Tripwire Binaries               0                 0        0        0
  30.   User Binaries and Libraries     0                 0        0        0
  31.   OS Binaries and Libraries       0                 0        0        0
  32. * Global Configuration Files      0                 0        0        2
  33.   System Boot Changes             0                 0        0       0  RPM Checksum Files              0                 0        0       0  OS Boot Files and Mount Points  0                 0        0       0
  34.   (/boot)  OS Devices and Misc Directories 0                 0       0        0  Root Directory and Files        0                 0       0        0
  35. Total objects scanned:  64406
  36. Total violations found:  3
  37. ===============================================================================
  38. Object Summary:===============================================================================
  39. -------------------------------------------------------------------------------
  40. # Section: Unix File System-------------------------------------------------------------------------------
  41. -------------------------------------------------------------------------------
  42. Rule Name: Tripwire Data Files (/usr/local/tripwire/etc/tw.pol)
  43. Severity Level: 0-------------------------------------------------------------------------------
  44. Remove the "x" from the adjacent box to prevent updating the database
  45. with the new values for this object.
  46. Modified:
  47. [x] "/usr/local/tripwire/etc/tw.pol"
  48. -------------------------------------------------------------------------------Rule Name: Global Configuration Files (/etc)
  49. Severity Level: 0-------------------------------------------------------------------------------
  50. Remove the "x" from the adjacent box to prevent updating the databasewith the new values for this object.
  51. Modified:[x] "/etc/cups/certs"
  52. [x] "/etc/cups/certs/0"
  53. ===============================================================================
  54. Object Detail:===============================================================================
  55. -------------------------------------------------------------------------------
  56.   Section: Unix File System-------------------------------------------------------------------------------
  57. -------------------------------------------------------------------------------RuleName: Tripwire Data Files (/usr/local/tripwire/etc/tw.pol)
  58. Severity Level: 0-------------------------------------------------------------------------------
  59.   ----------------------------------------
  60.   Modified Objects: 1
  61.   ----------------------------------------
  62. Modified object name:  /usr/local/tripwire/etc/tw.pol
  63.    Property:            Expected                    Observed            -------------        -----------                 -----------         Object Type          Regular File                Regular File        Device Number        64768                       64768               Mode                 -rw-r-----                  -rw-r-----          Num Links            1                           1                   UID                  root (0)                    root (0)            GID                  root (0)                    root (0)            Size                 4159                        4159
  64. * Modify Time          2009年08月07日 星期五 11时05分06秒                                                  2009年08月07日 星期五 11时16分18秒  Blocks              24                          24                 * CRC32               BbMp+k                      CasvDM             * MD5                 AedDw/7U0K3jGZeAQ+TluE      BqtFj3lGlb5i44+KkjyB9u
  65. -------------------------------------------------------------------------------Rule Name: Global Configuration Files (/etc)
  66. Severity Level:0------------------------------------------------------------------------------- ----------------------------------------
  67.   Modified Objects: 2  ----------------------------------------
  68. Modified object name:  /etc/cups/certs
  69.    Property:            Expected                    Observed            -------------        -----------                 -----------         Object Type          Directory                   Directory           Device Number        64768                       64768               File Device Number   0                           0                   Inode Number         1557621                     1557621             Mode                 drwx--x--x                  drwx--x--x          Num Links            2                           2                   UID                  root (0)                    root (0)            GID                  sys (3)                     sys (3)             Size                 4096                        4096
  70. * Modify Time          2009年08月07日 星期五 11时07分09秒                                                   2009年08月07日 星期五 11时22分12秒
  71. * Change Time          2009年08月07日 星期五 11时07分09秒                                                  2009年08月07日 星期五 11时22分12秒  Blocks              16                          16
  72. Modified object name:  /etc/cups/certs/0
  73.    Property:            Expected                    Observed            -------------        -----------                 -----------         Object Type          Regular File                Regular File        Device Number        64768                       64768               File Device Number   0                           0                   Inode Number         1556488                     1556488             Mode                 -r--r-----                  -r--r-----          Num Links            1                           1                   UID                  root (0)                    root (0)            GID                  sys (3)                     sys (3)             Size                 32                          32
  74. * Modify Time          2009年08月07日 星期五 11时07分09秒                                                   2009年08月07日 星期五 11时22分12秒
  75. * Change Time          2009年08月07日 星期五 11时07分09秒                                                  2009年08月07日 星期五 11时22分12秒  Blocks              16                          16                 * CRC32               Bh604c                      DClI5t             * MD5                 CYQG5hqBS+c69bcyXaK6Wl      DDovWtxN44ScT7sn/IJiZa
  76. ===============================================================================
  77. Error Report:===============================================================================
  78. No Errors
  79. -------------------------------------------------------------------------------*** End of report ***
  80. Open Source Tripwire 2.4 Portions copyright 2000 Tripwire, Inc.Tripwire is a registeredtrademark of Tripwire, Inc. This software comeswith ABSOLUTELY NO WARRANTY;for details use --version. This is freesoftware which may be redistributed
  81. or modified only under certain conditions; see COPYING for details.All rights reserved.

八.查看报告
所有tripwire的报告以.twr后缀保存在lib/tripwire目录下,需要使用twprint命令来转化成文本格式
./sbin/twprint --print-report --twrfile./lib/tripwire/report/local.c1gstudio.com-20090807-112337.twr>/tmp/tripwire_readable.txt
cat /tmp/tripwire_readable.txt
九.定期检查
每天4点定期检查
  1. 00 4 * * * /usr/local/tripwire/sbin/tripwire  --check

十.查看当前配置
./sbin/twadmin --print-polfile
  1. @@section GLOBAL
  2. TWDOCS="/usr/local/tripwire/doc/tripwire";
  3. TWBIN="/usr/local/tripwire/sbin";
  4. TWPOL="/usr/local/tripwire/etc";
  5. TWDB="/usr/local/tripwire/lib/tripwire";
  6. TWSKEY="/usr/local/tripwire/etc";
  7. TWLKEY="/usr/local/tripwire/etc";
  8. TWREPORT="/usr/local/tripwire/lib/tripwire/report";
  9. HOSTNAME=local.c1gstudio.com;

./sbin/twadmin --print-cfgfile
  1. ROOT          =/usr/local/tripwire/sbin
  2. POLFILE       =/usr/local/tripwire/etc/tw.pol
  3. DBFILE        =/usr/local/tripwire/lib/tripwire/$(HOSTNAME).twd
  4. REPORTFILE    =/usr/local/tripwire/lib/tripwire/report/$(HOSTNAME)-$(DATE).twr
  5. SITEKEYFILE   =/usr/local/tripwire/etc/site.key
  6. LOCALKEYFILE  =/usr/local/tripwire/etc/local.c1gstudio.com-local.key
  7. EDITOR        =/bin/vi
  8. LATEPROMPTING =false
  9. LOOSEDIRECTORYCHECKING =false
  10. MAILNOVIOLATIONS =true
  11. EMAILREPORTLEVEL =3
  12. REPORTLEVEL   =3
  13. MAILMETHOD    =SENDMAIL
  14. SYSLOGREPORTING =false
  15. MAILPROGRAM   =/usr/sbin/sendmail -oi -t

参考:
Tripwire Tutorial: Linux Host Based Intrusion Detection System
Tripwire-2.4.1.2 tutorial
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章