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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章