[ 永遠的UNIX::UNIX技術資料的寶庫 ]   GB | BIG5

首頁 > 安全技術 > 工具 > 正文
系統遭受入侵使用TCT進行緊急恢復並分析
本文出自:http://xfocus.org/ 作者:inburst[inburst@263.net] (2001-09-09 07:05:00)
    從事系統管理工作,就算你非常小心翼翼地做好了一切防護,還是可能有入侵者能夠突破你 
的防護進入系統,並且更改或者刪除一些文件。這裡,我們借用honeynet project裡面的一些實 
例,來對一個unix下的實用工具軟件tct及其相關輔助軟件做簡要說明。並且在最再介紹另外 
一個比較不錯的能恢復ext2文件系統的軟件recover。 
    首先說一下相關的軟件: 
    1、The Coroners Toolkit:也就是我們所說的TCT,想要在國內下載的話,您可以到安全焦 
點(http://xfocus.org/tool/other/tct-1.07.tar.gz)下載。這是一個unix下的命令行文件系統 
工具集,支持FFS及ext2fs,從塊及結點處來對數據進行恢復。它能夠針對文件的最修改、訪 
問或者改變(MAC)的時間來進行分析,並且根據數據節點的值提取出文件列表以進行恢復。 
    2、TCTUTILs:在http://xfocus.org/tool/other/tctutils-1.01.tar.gz可以下載當前最新 
版本。它是對TCT的補充,提供了根據文件名對數據進行恢復的命令行工具。這兩個工具都需要 
使用者對一些底層基本知識比較了解。 
    3、Autopsy Forensic Browser:可以從http://xfocus.org/tool/other/autopsy-1.01.tar.gz 
下載。它提供了一個友好的html界面給tct及tctutils。它能使枯燥的分析工作相對輕鬆些:) 

    一、安裝:TCT在各種unix平台下都經過了比較好的測試。現在能夠支持FreeBSD、OpenBSD、 
SunOS、Linux等平台。TCTUTILs和Autopsy則不一定能跑得起來,我測試的平台是一台默認安裝 
的Red Hat 6.2系統。 

    1、tct 

    # tar zvfx tct-1.07.tar.gz -C /usr/local/tct/; cd /usr/local/tct/tct*; make 
    這樣把tct展開到/usr/local/tct/tct-1.07/的目錄下,並且進入,make。這裡,如果是make 
過之,需要重新在編譯的話,需要運行perl reconfig命令重新配置。 

    2、tctutils: 

    # tar zvfx tctutils-1.01.tar.gz -C /usr/local/tct;cd /usr/local/tct/tctu*;make 
    現在tctutils似乎只在OpenBSD 2.8、Debian Linux 2.2、Solaris 2.7下經過詳盡測試,而 
對FreeBSD還支持不好。通常make不會出現什問題,如果有,自己改下代碼或者Makefile即可。 

    3、Autopsy: 

    解包運行./configure,它會自己尋找一些實用工具如grep、strings、md5sum的路徑, 
並要求確認tct以及tctutils的路徑(如果沒找到會要求你輸入正確路徑)。最要求輸入需要檢 
查的文件系統所在,才生成程序autopsy。 

    二、honeynet scan15簡介: 

    關honeynet project的詳情,可以參見安全焦點(http://xfocus.org/honeynet/),他們 
現在維護著國外honeynet項目的中文鏡像。 
    scan15是honeynet在2001年3月15日一台受入侵的Linux機器上搜集到的數據而面臨的問題。 
入侵者下載了一些rootkit放在根目錄下,成功安裝刪除了。而honeynet project將當時的原始 
數據鏡像下來,作為題目出給網絡安全愛好者,要求對這一被刪除的rootkit進行恢復。 
    詳情可以參見http://xfocus.org/honeynet/scans/。 
    根據要求,我下載了honeynet.tar.gz的包,約13M,解壓是一個270M左右的文件honeypot.hda8.dd 
及一個README文件,README如下: 

    =================================================================== 

    SUMMARY 
    ------- 
    You have download the / partition of a compromised RH 6.2 
    Linux box.  Your mission is to recover the deleted rootkit 
    from the / partition.   Below are a list of all the partitions 
    that made up the compromised system. 

    /dev/hda8       /      <----- The partition you downloaded 
    /dev/hda1       /boot 
    /dev/hda6       /home 
    /dev/hda5       /usr 
    /dev/hda7       /var 
    /dev/hda9       swap 

           - The Honeynet Project 
             http://project.honeynet.org 

    ==================================================================== 
            圖一 

    任務非常明確。 

    三、操作過程 

    1、確認下載數據無誤 

    # md5sum honeynet.tar.gz 
    0dff8fb9fe022ea80d8f1a4e4ae33e21 honeynet.tar.gz 
    # md5sum honeypot.hda8.dd 
    5a8ebf5725b15e563c825be85f2f852e honeypot.hda8.dd 

    這些md5校驗值同honeynet網站上貼出來的一樣,說明文件下載無誤,未經篡改。 

    2、將下載下來的鏡像掛接到系統上 

    # mount honeypot.hda8.dd /mnt/ -oloop,ro 
     
    3、配置autopsy並運行之(其實在上面autopsy的configure過程中就做這步了) 

    ==================================================================== 
    [root@test autopsy-1.01]# ./configure 
       Autopsy Forensic Browser v.1.01 Installation 
    MD5 found: /usr/bin/md5sum 
    strings found: /usr/bin/strings 
    grep found: /bin/grep 
    Enter TCT Directory: 
    /usr/local/tct 
      TCT bin directory was found 
    Enter TCTUTILs Directory: 
    /usr/local/tctutils 
     TCTUTILs bin directory was found 
    Enter Morgue Directory: 
    /home/inburst       
    Enter Default Investigator Name (for the Autopsy Reports): 
    inburst 
    Settings saved to conf.pl 
    [root@test autopsy-1.01]# 
    ==================================================================== 
                圖二 

    然進入/home/inburst/,你存放honeypot.hda8.dd的地方,編輯文件fsmorgue,使其看來象 
下面這樣: 

    ==================================================================== 
    # fsmorgue file for Autopsy Forensic Browser 
    # 
    # local_file name can contain letters, digits, '-', '_', and '.' 
    # 
    # local_file    mount_point 
    honeypot.hda8.dd        /mnt/ 
    ==================================================================== 
                圖三 

    並且編輯zoneinfo,確定時間信息。 

    然可以運行命令: 

    # ./autopsy 9999 192.168.168.130 

    這裡192.168.168.130是我所用的工作機,9999是端口號,屏幕上會輸出: 

    ==================================================================== 
    Autopsy Forensic Browser ver 1.01 
    Investigator: inburst 

    Paste this as your browser URL on 192.168.168.130: 
        192.168.168.130:9999/1727589285/autopsy 
    ==================================================================== 
                圖四 

    將192.168.168.130:9999/1727589285/autopsy粘貼到你的瀏覽器url裡,就可以開始進一步的分析了。 

    4、恢復被刪除的rootkit,這裡我們先純用命令行來解決問題,其實利用autopsy可以令這些麻煩事 
看起來相對直觀些。 

    a、搜集信息 

    ==================================================================== 
    # ils honeypot.hda8.dd > ilsdump.txt 
    # cat ilsdump.txt 
    class|host|device|start_time 
    ils|test.inburst.com.cn|honeypot.hda8.dd|992134159 
    st_ino|st_alloc|st_uid|st_gid|st_mtime|st_atime|st_ctime|st_dtime|st_mode|st_nlink|st_size|st_block0|st_block1 
    23|f|0|0|984706608|984707090|984707105|984707105|100644|0|520333|307|308 
    2038|f|1031|100|984707105|984707105|984707105|984707169|40755|0|0|8481|0 
    …… 
    …… 
    ==================================================================== 
                圖五 

    ils命令是用來顯示inode信息的,它顯示了每個被刪除的文件節點的原始資料。上面顯示的第一個域是 
結點號。面數據恢復時需要用到,關這個輸出的詳細信息如下: 

    st_ino:The inode number. 
    st_alloc:Allocation status: `a' for allocated inode, `f' for free inode. 
    st_uid:Owner user ID. 
    st_gid:Owner group ID. 
    st_mtime:UNIX time (seconds) of last file modification. 
    st_atime:UNIX time (seconds) of last file access. 
    st_ctime:UNIX time (seconds) of last inode status change. 
    st_dtime:UNIX time (seconds) of file deletion (LINUX only). 
    st_mode:File type and permissions (octal). 
    st_nlink:Number of hard links. 
    st_size:File size in bytes. 
    st_block0,st_block1:The first two entries in the direct block address list. 

    ====================================================================   
    # /usr/local/tct/extras/ils2mac ilsdump.txt > deletedfiles.txt 
    # cat deletedfiles.txt 
    class|host|device|start_time 
    body|test.inburst.com.cn|honeypot.hda8.dd|992134159 
    md5|file|st_dev|st_ino|st_mode|st_ls|st_nlink|st_uid|st_gid|st_rdev|st_size|st_atime|st_mtime|st_ctime|st_blksize|st_blocks 
    |<honeypot.hda8.dd-dead-23>||23|100644|-rw-r--r--|0|0|0||520333|984707090|984706608|984707105|| 
    |<honeypot.hda8.dd-dead-2038>||2038|40755|drwxr-xr-x|0|1031|100||0|984707105|984707105|984707105|| 
    |<honeypot.hda8.dd-dead-2039>||2039|100755|-rwxr-xr-x|0|0|0||611931|984707090|1013173693|984707105|| 
    |<honeypot.hda8.dd-dead-2040>||2040|100644|-rw-r--r--|0|0|0||1|984707090|983201398|984707105|| 
    …… 
    …… 
    ==================================================================== 
                圖六 

    ils2mac重新排列輸出了上面的信息,這在你有多個磁盤分區需要分析時比較有用。 

    ==================================================================== 
    # mactime -p /mnt/etc/passwd -g /mnt/etc/group -b deletedfiles.txt 1/1/2001 > mactime.txt 
    # cat mactime.txt 
    Feb 08 02 21:08:13   611931 m.. -rwxr-xr-x root     root     <honeypot.hda8.dd-dead-2039> 
    Jan 27 01 23:11:32     3278 m.. -rw-r--r-- root     root     <honeypot.hda8.dd-dead-2044> 
    Jan 27 01 23:11:44    11407 m.. -rw-r--r-- root     root     <honeypot.hda8.dd-dead-2046> 
    Feb 26 01 22:46:04   632066 m.. -rwxr-xr-x root     root     <honeypot.hda8.dd-dead-2061> 
    Feb 26 01 23:22:55     4060 m.. -rwxr-xr-x root     root     <honeypot.hda8.dd-dead-2047> 
    Feb 26 01 23:22:59     8268 m.. -rwx------ root     root     <honeypot.hda8.dd-dead-2053> 
    Feb 26 01 23:23:10     4620 m.. -rwxr-xr-x root     root     <honeypot.hda8.dd-dead-2054> 
    Feb 26 01 23:23:55    53588 m.. -rwxr-xr-x root     root     <honeypot.hda8.dd-dead-2058> 
    Feb 26 01 23:24:03       75 m.. -rwx------ root     root     <honeypot.hda8.dd-dead-2059> 
    Feb 26 01 23:28:40       79 m.. -rwxr-xr-x root     root     <honeypot.hda8.dd-dead-2045> 
    Feb 26 01 23:29:51      688 m.. -rw-r--r-- root     root     <honeypot.hda8.dd-dead-2052> 
    Feb 26 01 23:29:58        1 m.. -rw-r--r-- root     root     <honeypot.hda8.dd-dead-2040> 
    Mar 03 01 11:05:12      708 m.. -rw-r--r-- root     root     <honeypot.hda8.dd-dead-2060> 
    Mar 03 01 11:08:37     3713 m.. -rwx------ root     root     <honeypot.hda8.dd-dead-2041> 
    Mar 15 01 19:17:36    33135 mac -rw-r--r-- root     root     <honeypot.hda8.dd-dead-56231> 
    Mar 15 01 19:19:37       16 ma. lrwxrwxrwx root     root     <honeypot.hda8.dd-dead-12107> 
                            16 ma. lrwxrwxrwx root     root     <honeypot.hda8.dd-dead-20883> 
                             16 ma. lrwxrwxrwx root     root     <honeypot.hda8.dd-dead-28172> 
    Mar 15 01 19:20:25       16 ..c lrwxrwxrwx root     root     <honeypot.hda8.dd-dead-12107> 
                            239 .ac -rw-r--r-- root     root     <honeypot.hda8.dd-dead-16110> 
    …… 
    …… 
    ==================================================================== 
                圖七 

    mactime命令則是按時間,inode對輸出進行排列、對比,顯示出哪些inodes被修改或者存取過。 
     
    OK,有趣的東西玩過了,讓我們來看看,其實用autopsy就不用這麻煩,大家可以從http://xfocus.org/tmp/autopsy.jpg 
看到相關的抓圖,從圖上就可以清楚地看出,我們要恢復的數據在哪裡了:)                                 
     
    b、恢復數據 
     
    通過上面的數據分析之,我們應該能夠自己判斷哪些數據可能是比較有趣的,然用icat命令加以提取。從上面的圖中我們可以 
知道,結點23處的lk.tgz應該是比較好玩的東西,好吧,讓我們來看看。     

    ==================================================================== 
    # icat honeypot.hda8.dd 23 > file-23    <--提取 
    # file file-23        <--看文件類型 
    file-23: gzip compressed data, deflated, last modified: Sat Mar  3 11:09:06 2001, os: Unix 
    # tar zvfx file-23    <--解包 
    last/ 
    tar: Archive contains future timestamp 2002-02-08 21:08:13 
    last/ssh 
    last/pidfile 
    last/install 
    last/linsniffer 
    last/cleaner 
    last/inetd.conf 
    last/lsattr 
    last/services 
    last/sense 
    last/ssh_config 
    last/ssh_host_key 
    last/ssh_host_key.pub 
    last/ssh_random_seed 
    last/sshd_config 
    last/sl2 
    last/last.cgi 
    last/ps 
    last/netstat 
    last/ifconfig 
    last/top 
    last/logclear 
    last/s 
    last/mkxfs 
    ==================================================================== 
                圖八 

    很容易地就把被刪除的rk.tgz恢復出來了。如果感興趣的話,我們還可以對圖中結點2038處的/last目錄也一並恢復。現在 
先看看2038裡放著的是什: 

    ==================================================================== 
    # ils honeypot.hda8.dd 2038 
    …… 
    2038|f|1031|100|984707105|984707105|984707105|984707169|40755|0|0|8481|0 
                                      ^^^^ 
                                       | 
                                       +-->注意這裡 
    # bcat -h honeypot.hda8.dd 8481 512 
    0       f6070000 0c000102 2e000000 02000000     .... .... .... .... 
    16      f4030202 2e2e0000 f7070000 0c000301     .... .... .... .... 
    32      73736800 f8070000 10000701 70696466     ssh. .... .... pidf 
    48      696c6500 f9070000 10000701 696e7374     ile. .... .... inst 
    64      616c6c00 fa070000 14000801 636f6d70     all. .... .... comp 
    80      75746572 65720000 fb070000 10000701     uter er.. .... .... 
    96      636c6561 6e657200 fc070000 14000a01     clea ner. .... .... 
    112     696e6574 642e636f 6e660000 fd070000     inet d.co nf.. .... 
    128     10000601 6c736174 74720000 fe070000     .... lsat tr.. .... 
    144     20000801 73657276 69636573 ff070000      ... serv ices .... 
    160     10000501 73656e73 65000000 00080000     .... sens e... .... 
    176     28000a01 7373685f 636f6e66 69670000     (... ssh_ conf ig.. 
    192     01080000 14000c01 7373685f 686f7374     .... .... ssh_ host 
    208     5f6b6579 02080000 30001001 7373685f     _key .... 0... ssh_ 
    224     686f7374 5f6b6579 2e707562 03080000     host _key .pub .... 
    240     18000f01 7373685f 72616e64 6f6d5f73     .... ssh_ rand om_s 
    256     65656400 04080000 fc020b01 73736864     eed. .... .... sshd 
    272     5f636f6e 66696700 05080000 0c000301     _con fig. .... .... 
    288     736c3200 06080000 dc020801 6c617374     sl2. .... .... last 
    304     2e636769 07080000 2c000201 70730000     .cgi .... ,... ps.. 
    320     08080000 20000701 6e657473 74617400     ....  ... nets tat. 
    336     09080000 10000801 6966636f 6e666967     .... .... ifco nfig 
    352     0a080000 0c000301 746f7000 0b080000     .... .... top. .... 
    368     10000801 6c6f6763 6c656172 0c080000     .... logc lear .... 
    384     84020101 73000000 0d080000 78020501     .... s... .... x... 
    400     6d6b7866 73000000 00000000 00000000     mkxf s... .... .... 
    416     00000000 00000000 00000000 00000000     .... .... .... .... 
    432     00000000 00000000 00000000 00000000     .... .... .... .... 
    448     00000000 00000000 00000000 00000000     .... .... .... .... 
    464     00000000 00000000 00000000 00000000     .... .... .... .... 
    480     00000000 00000000 00000000 00000000     .... .... .... .... 
    496     00000000 00000000 00000000 00000000     .... .... .... .... 
    ==================================================================== 
                圖九 

    我們可以看出last目錄其實就是lk.tgz的解包,沒有太大的恢復價值了;) 
     
    c、進一步分析 

    現在rootkit也已經找到了,我們就應該來看看究竟它們被裝到哪裡了,有個簡單的辦法,可以不用 
我們花太多的精力手工尋找。 
     
    # find /mnt -type f -exec md5sum {} \; > md5.all 

    這樣將我們mount上的盤中所有可執行文件都提取出來,用md5sum取它的hash,並且存入md5.all文件 
中,準備跟rootkit進行對比。 

    ==================================================================== 
    # for i in last/* 
    > do echo $i; 
    > grep `md5sum $i` md5.all; 
    > done; 
    last/cleaner 
    last/ifconfig 
    md5.all:086394958255553f6f38684dad97869e  /mnt/sbin/ifconfig 
    last/inetd.conf 
    md5.all:b63485e42035328c0d900a71ff2e6bd7  /mnt/etc/inetd.conf 
    last/install 
    last/last.cgi 
    last/linsniffer 
    md5.all:6c0f96c1e43a23a21264f924ae732273  /mnt/dev/ida/.drag-on/linsniffer 
    md5.all:6c0f96c1e43a23a21264f924ae732273  /mnt/dev/ida/.. /linsniffer 
    last/logclear 
    md5.all:5f22ceb87631fbcbf32e59234feeaa5b  /mnt/dev/ida/.drag-on/logclear 
    md5.all:5f22ceb87631fbcbf32e59234feeaa5b  /mnt/dev/ida/.. /logclear 
    last/lsattr 
    last/mkxfs 
    md5.all:18a2d7d3178f321b881e7c493af72996  /mnt/dev/ida/.drag-on/mkxfs 
    md5.all:18a2d7d3178f321b881e7c493af72996  /mnt/dev/ida/.. /mkxfs 
    last/netstat 
    md5.all:2b07576213c1c8b942451459b3dc4903  /mnt/bin/netstat 
    last/pidfile 
    md5.all:68b329da9893e34099c7d8ad5cb9c940  /mnt/etc/at.deny 
    last/ps 
    md5.all:7728c15d89f27e376950f96a7510bf0f  /mnt/bin/ps 
    last/s 
    md5.all:06d04fa3c4941b398756d029de75770e  /mnt/dev/ida/.drag-on/s 
    md5.all:06d04fa3c4941b398756d029de75770e  /mnt/dev/ida/.. /s 
    last/sense 
    md5.all:464dc23cac477c43418eb8d3ef087065  /mnt/dev/ida/.drag-on/sense 
    md5.all:464dc23cac477c43418eb8d3ef087065  /mnt/dev/ida/.. /sense 
    last/services 
    md5.all:54e41f035e026f439d4188759b210f07  /mnt/etc/services 
    last/sl2 
    md5.all:4cfae8c44a6d1ede669d41fc320c7325  /mnt/dev/ida/.drag-on/sl2 
    md5.all:4cfae8c44a6d1ede669d41fc320c7325  /mnt/dev/ida/.. /sl2 
    last/ssh 
    last/ssh_config 
    last/ssh_host_key 
    md5.all:c2c1b08498ed71a908c581d634832672  /mnt/dev/ida/.drag-on/ssh_host_key 
    md5.all:c2c1b08498ed71a908c581d634832672  /mnt/dev/ida/.. /ssh_host_key 
    last/ssh_host_key.pub 
    last/ssh_random_seed 
    md5.all:ad265d3c07dea3151bacb6930e0b72d3  /mnt/dev/ida/.. /ssh_random_seed 
    last/sshd_config 
    last/top 
    ==================================================================== 
                圖十 

    這種方法對入侵檢測有著極大幫助。從上面的輸出我們可以非常輕鬆地判斷出rootkit被安裝在幾 
個隱藏目錄下,如 
    /dev/ida/.. / 
    /dev/ida/.drag-on/ 

    d、由本文的重點不是放在入侵檢測上,所以對該image中其它入侵者留下的痕跡就不再做進一步 
分析了,建議如果感覺興趣同志可以自己去下載這個包來進行一次模擬入侵實戰,並且可以從honeynet 
的高手們的分析過程中得出很多經驗。 
     
    最,介紹一個由叫recover的軟件。這個軟件可以恢復ext2下被刪除的文件,但是沒有tct那樣功能 
強大。只是相對更“傻瓜”一些,操作起來比較方便。可以在http://xfocus.org/tool/other/recover-1.2.tar 
獲取。 
    它的運行簡單,只要運行./recover就OK了,然會問你需要恢復的數據所以磁盤、刪除時間、文件 
大小等一系統信息,以幫助精確定位需要恢復的文件,但最恢復出來的東西,都是以數字排序,分析 
起來有一定的難度。 

    大致如此,have fun。 

參考資料: 
1、《Honeynet Scan of the Month #15》 by Brian Carrier 
2、http://www.xfocus.org/honeynet/ 安全焦點陷阱網絡 
3、tct\tctutils\autopsy的man page(http://www.xfocus.org/tmp/tct_man.zip) 
4、http://www.incident-response.org/  
(http://www.fanqiang.com)
    進入【UNIX論壇

相關文章
 

★  樊強制作 歡迎分享  ★