歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> 關於Unix >> UNIX系統下的應急響應工具介紹

UNIX系統下的應急響應工具介紹

日期:2017/2/28 11:27:29   编辑:關於Unix


UNIX系統下的應急響應工具介紹
原作者:Holt Sorenson
原文:Incident Response Tools For Unix, Part One: System Tools
Last Updated: March 27, 2003
翻譯:Refdom
(注:這是一篇基礎的應急工具介紹文檔。適合經驗不多者。限於水平,不足之處請指出。)
整個文章分三個系列介紹對於 OpenBSD, Linux, 或者Solaris系統的應急響應和取證過程中有用的工具。本部份聚焦在系統工具上,第二部份主要是介紹文件系統工具,最後部分則主要是網絡工具。本文用到的都是基於 OpenBSD 3.2, Debian GNU/Linux 3.0 (woody), RedHat 8.0 (psyche), and Solaris 9 (aka Solaris 2.9 or SunOS 5.9)的。
依賴於你所使用的操作系統,本文討論的許多軟件可能不是默認安裝的。這種情況下,請根據文章後面的參考部分獲得這些工具。
The Soapbox
那些可以用來處理入侵威脅的工具不在本系列討論內容中,本文只覆蓋在入侵發生之後使用的工具。入侵通常是可以防止的。使用一些比如保證系統更新安裝最新補丁的技術,按照最小化服務配置系統,使用設計為安全的操作系統,使用能夠加固系統的核心補丁等等,這些來防范入侵的技術可能讓你根本就從來不會使用在本系列文章中介紹到的這些工具。
讀者應該命令,一旦攻擊者獲得了系統控制權,這個系統就基本不應該被信任。我們討論的工具多數都操作在用戶方式。一個欺騙的核心模塊可能不會讓你正常地檢查系統,比如,這個系統已經被入侵的情況下。這些欺騙的模塊會采用多種辦法來隱藏自己,比如根據系統設計來讓自己在系統運行的時候不能輕易檢測到。這意味著,你不應該相信你使用的那些工具的輸出結果。這意味著在響應入侵事件中,應該采取懷疑、研究和謹慎的方式。
你用於分析系統的工具應該是你可以去信任,而且沒有被修改的。下面討論了一些技術,比如將工具保存在離線的只讀介質中,這樣,你就更可以信賴,而不是那些在已經被入侵的系統上的二進制程序。
你已經做了所有正確的事情,可以進行下面的一些練習,你的系統已經被入侵了。現在怎麼辦呢?
Breaking Out the Toolbelt
現在首先應該檢查那些我們後面需要用到的工具。這裡不說man(1)提供的信息,特別是因為命令參數因為系統不同而不同。檢查這樣的信息是留給讀者的一種練習。
vmstat - 這是可以快速察看內存、CPU和磁盤子系統的命令。vmstat 通常執行一個短時間,以便可以察看子系統利用的趨勢。vmstat 經常可以在系統性能有一些問題的時候幫助我們知道哪些地方應該去深究。
mpstat - 這個命令在Linux和Solaris上都有,可以用它察看處理器利用的統計。mpstat 提供一個選項,允許在多處理器系統中察看指定CPU的統計。vmstat 沒有這個功能。
iostat - 顯示比vmstat更詳細的跟子系統相關的統計信息。
sar,sa,lastcomm,last - 這些是檢查歷史數據和一些近來的系統事件。sar是一個Solaris和Linux的系統性能分析工具。這些可以用於檢查的性能數據類似於vmstat, mpstat和 iostat的顯示。 sar的數據是一段時間保存的內容,因此可以察看過去的信息。 lastcomm可以現在系統最近被執行的命令。這些可以用在系統審計中。sa 可以在*BSD和Linux中找到,它給用戶在系統審計中更多的選項來收集信息。
ps - 立足於進程狀態,用於顯示系統執行的進程和他們的信息。
top - 顯示的信息同ps接近,但是top可以了解到CPU消耗,可以根據用戶指定的時間來更新顯示。
lsof - 列舉打開的文件,顯示系統當前打開的所有文件。Unix系統的所有東西幾乎都可以看作是文件,因此lsof也顯示了系統的狀態中有重要意義的內容。
file - 判斷文件是什麼,不同的文件格式可以16進制的形式現實文件的內容
readelf - 顯示二進制文件的ELF(可執行鏈接和格式)頭的細節。這些內容可以判斷可執行提供的函數。
od - 以用戶指定的格式輸出文件內容。od對於在文件內容中有一些解釋的情況下察看原始內容是有幫助的。
ldd - 讀取ELF頭的內容,並顯示可執行文件依賴的對象庫。
string - 現實文件中的ASCII字符串。對於在二進制文件中查找其中可讀的字符串是非常有用處的。
find - 用於在文件系統中查找指定的對象。
strace - 這個工具開始或者附加到一個當前運行的進程中,顯示這個進程所作的所有系統調用。這可以用來判斷程序運行的行為,並且來決定是否是合適的程序。strace 存在於Linux上。在 Solaris上是truss, *BSD提供的ktrace可以達到相似的功能。
sudo - 可以讓管理員給用戶以其他用戶的權限執行命令的能力,而不用給該用戶密碼。
grep - 用於按照用戶指定的模式查詢。 grep用匹配規則。
less - 頁面調度程序,用來按頁顯示文本。
在參考部分中的"CD-ROM and Floppy distributions"[3]中,一些站點介紹了怎麼編譯這些工具以便用於不同的操作系統,並放置在CD-ROM。現在,開始檢查運行的系統了。
運氣就是在機會面前有所准備
運氣對於技術來說,並不是可求解的。攻擊者可以采用很多方法來危及OS的安全。威脅系統安全的漏洞可能是OS提供商,也可以是那些應用軟件。當漏洞還沒有大面積公布,或者還沒有讓它的相關提供商自己知道的時候,攻擊者已經在IRC裡面知道那種系統可以被入侵了。作為一個安全管理員,你必須在這場游戲中表現一直出色。但是,攻擊者則只需要一次就足夠。
然而,你需要做許多前期的准備工作。你應該有一個應急響應的策略。你必須有一張CD-ROM或者軟盤什麼的,來存儲檢查系統中需要的工具,而不是使用被入侵的系統中的工具。如果正使用軟盤,讓他們處於寫保護模式,你可以在取證[5]中獲得非常優秀的資源。
現在回到機器上。把事件響應的日期和時間都紀錄在記錄本上。並且紀錄采取的每一步的所有細節和時間。裝載CD-ROM或者軟盤,並且使用紀錄在這些介質上的軟件,緊記按照易失性的順序[6]保存相關的信息到安全的地方。
按照易失性順序的重要原因是因為入侵事件發生後與之相關信息的數量和自量都將隨時間增加而迅速減少。那些經驗豐富的攻擊者制造的事件則可能讓曲線更陡,下降速度更快。
了解自己
可能在入侵事件之前,你已經在系統上花費了大量時間。你了解這些系統的裡裡外外,進行了相當多的文檔工作,並且做了備份。在系統上,開啟了進程審計(或者*BSD的系統審計),進行了系統實時數據(sadc[8])來保存系統的性能數據。管理日志的時候,可能沒有足夠的空間來頻繁存儲這些數據,你可以發送syslog數據到安全的日志服務器上。
你接到webmaster的電話,他發現某個web服務器上CPU負載很高,而這個服務器每天的浏覽量僅僅幾千而已。webmaster確信服務器存在有什麼問題。
vmstat 和 mpstat (只在*BSD系統上) 表明CPU被用戶空間的一個或者多個進程消耗掉了,但是內存和I/O子系統還沒有大量使用。 iostat 也顯示出磁盤系統不正常。
$ vmstat 1 4
procs memory swap io system cpu
r b w swpd free buff cache si so bi bo in cs us sy id
1 0 0 376 7756 29772 570960 0 0 7 3 441 397 87 5 8
5 0 0 376 6728 29772 570960 0 0 0 0 498 1249 100 0 0
6 0 0 376 7240 29772 570960 0 0 0 0 652 1563 97 3 0
6 0 0 376 7604 29772 570960 0 0 0 0 536 1323 97 3 0
$ mpstat 1 4
20:51:21 CPU %user %nice %system %idle intr/s
20:51:22 all 100.00 0.00 0.00 0.00 479.00
20:51:23 all 100.00 0.00 0.00 0.00 496.00
20:51:24 all 100.00 0.00 0.00 0.00 499.00
20:51:25 all 97.00 0.00 3.00 0.00 481.00
Average: all 98.00 0.60 1.40 0.00 486.60
$ iostat -dk 1 4
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dev3-0 0.00 0.00 0.01 73 1296
dev3-0 0.00 0.00 0.00 0 0
dev3-0 0.00 0.00 0.00 0 0
dev3-0 0.00 0.00 0.00 0 0
sar (*BSD的sa) 顯示CPU從早些晚上 03:17 就開始被使用。 lastcomm 顯示FTP客戶端在03:17以root運行了幾次, last 這個命令顯示最近的登錄,沒有顯示出這個時間段有 root 從什麼地方登錄進來。另外,這個服務器又使用 sudo來管理root權限。這裡有兩個系統管理員賬號可以用 root登錄,但是他們並沒有登錄過,特別是在 AM 3這個時間附近。根據這一點,你決定使用CD上准備好的二進制工具。現在運行 top -d1,並且發現apache這個進程占用了100%的CPU。
現在用 grep 檢查apche的錯誤日志,這個GNU工具可以有更多有用的參數,-A, -B和-C 可以讓你指定想從哪一個匹配的行的開始,之前或者周圍看。 grep可以通過-E 來使用擴展的模式匹配表達式。可以檢查系統日志。但是並沒有在這些日志裡面檢查到什麼奇怪的地方。
現在繼續進行檢查。運行 ps -eflcyL (Solaris 9),ps -eflcym --headers (Deb3.0, RH8.0)或者 ps auwxhkwvl(OBSD 3.2)。找到進程 apache,而這一次發現有問題了。這裡只有一個apache進程和多個httpd進程。httpd實際上是Apache服務器,因為httpd是在apachectl文件執行的二進制,運行的apache是前派生的,因此,如果二進制文件被重命名為"apache",那麼也應該有多個進程存在。這就是問題所在。
使用 lsof -p [9] ,發現這個apache進程打開了一個叫 john.pot 的文件。立刻通過google,查詢這是一個叫“John the Ripper”的密碼破解工具,正是這個東西讓CPU滿負荷了。
現在來檢查這個所謂的apache程序。通過 file apache,表明這個文件是ELF可執行的。現在進行進一步的挖掘,執行 readelf -a apache,確信這是一個ELF可執行程序。 od -xc apache | less 現實ELF魔法數字(7f454c46),ldd顯示apache連接的共享對象庫比實際的httpd進程小一些,這裡面一定有文章:
$ ldd ./apache
$ ldd /usr/sbin/httpd
執行: strings | grep -i john,顯示如下:
$ strings apache | grep -i john
/usr/share/john/password.lst
/etc/john.ini
~/john.pot
/etc/john.ini
john
John the Ripper Version 1.6 Copyright (c) 1996-98 by Solar Designer
/etc/john.ini
/etc/john.ini
/etc/john.ini
用 strace -fp 'pgrep apache'(Deb3.0, RH8.0), truss -fp 'pgrep apache'(Sol9),或者 ktrace -dip (OBSD 3.2),來察看apache進程到底在做什麼。
# strace -fp `pgrep apache`
--- SIGALRM (Alarm clock) ---
sigreturn() = ? (mask now [])
--- SIGALRM (Alarm clock) ---
sigreturn() = ? (mask now [])
--- SIGALRM (Alarm clock) ---
sigreturn() = ? (mask now [])
_llseek(4, 65536, [65536], SEEK_SET) = 0
read(4, "\2YUz\0\2Z\0241\0\2ZA1dkmnr\0\2ZDa\0\2ZElnrd"..., 4096) = 4096
read(4, "\2\5Ma\0\2\5Te\0\2\6\n(\0\2\6>%\0\2\10\n&\0\2\10\0210\0"..., 4096) = 4096
read(4, "IPVm\0\2(%L\0\2((H\0\2(/CMRBNTUWcr\0\2(5"..., 4096) = 4096
read(4, "fgq\0\2BCh26o\0\2BDaikmoy\0\2BEanreltc"..., 4096) = 4096
read(4, "ag\0\2N\23l\0\2N\25j\0\2N\0269\0\2N\30f\0\2N!ds\0\2N)"..., 4096) = 4096
read(4, "\0\2_9LRMTes\0\2_:6Z\0\2_>&%\0\2_?)Cw\0\2_"..., 4096) = 4096
read(4, "%Antv\0\2%Cr\0\2%Dd\0\2%Gg\0\2%Ke\0\2%Lls\0"..., 4096) = 4096
read(4, "rtlpbdgiuv\0\2GBeam\0\2GDuy\0\2GEnert\0"..., 4096) = 4096
read(4, "We6hilw\0\2RYasdpcgilmno\0\2S\0205c\0\2S\21"..., 4096) = 4096
read(4, "68jDxMEBTIRNLAGSKCPOqVHFUZWJ$%#^"..., 4096) = 4096
read(4, "\0022In\0\0022Ke\0\0022LiEe\0\0022Ma\0\0022NEe\0\0022P"..., 4096) = 4096
read(4, "I5y\0\2I6e\0\2I7ae\0\2IAnmrs9t67dhlpuz"..., 4096) = 4096
read(4, "Eprylsenbu9ak013ft!Lcox\0\2SFi9aey"..., 4096) = 4096
read(4, "o149dlytwMbckr0u\0\2_Xixae01537926"..., 4096) = 4096
read(4, "2\0\2-!NCLS\0\2-%RS\0\2-)ETDNS\0\2--M\0\2-"..., 4096) = 4096
read(4, "!*bfgk\0\2GJu\0\2GLeiayYs\0\2GMaAoegu\0"..., 4096) = 4096
read(4, "Utsdbgmpy\0\2PWa\0\2PXy\0\2PY1!27sy.05"..., 4096) = 4096
read(4, "w!9bAjp5clgkr068EFSYf$.?CJKLW]n\0"..., 4096) = 4096
--- SIGALRM (Alarm clock) ---
sigreturn() = ? (mask now [])
用 grep -n 在John the Ripper的源代碼中找到在 crk_password_loop()函數中有一個叫 sig_timer_emu_tick()的函數,它在timer_emu_max到達之後產生 SIGALRM。這就是 strace 顯示的SIGALRM。通過 lsof -p 'pgrep apache'來檢查哪個文件同讀的文件描述符fd 4在讀取數據,以及fd 4相關聯的叫all.chr的文件。察看 john.ini 文件,找到所引用的 all.chr 文件。
所有跡象表明,這的確是一個密碼破解工具, John the Ripper。因此,無論是你還是其他的任何管理員安裝了這個工具,它運行起來的時候,就會好像web 服務器被入侵了。
結論
在下一篇文章中,我們會繼續進行研究在Webserver使用文件系統工具的時候到底發生了什麼事情。記住,面對任何威脅最好的准備是做好預防。當入侵真正發生的時候,你要做很多工作去了解你的系統,設置策略,和實施應急響應的技術,你的優勢越明顯,那麼控制和根除威脅就更能實現。
[下面參考中的連接請察看原文檔。]
References
[1] Acquiring/Installing software
? OpenBSD ports system
? FreeBSD ports system
? Freeware for Solaris
? HOWTO install packages on a Debian system
? Installing packages on a RedHat system
? GNU binutils (readelf)
? lsof
? top
? sudo
[2] Kernel Modules Countermeasures
? Dino Dai Zovi's paper on kernel rootkits
? Sealing the linux kernel
? gr-security linux kernel patch
? LIDS linux kernel patch
[3] CD-ROM and Floppy distributions
? F.I.R.E. (Forensic and Incident Response Environment) Bootable CD
? Knoppix Linux
? How to Make a Bootable, Full System OpenBSD CD-ROM
? LNX-BBC mini-linux distribution
? Google's Tiny Linux distributions list
[4] Incident Response Policy
? Handbook for Computer Security Incident Response Teams
? Expectations for Computer Security Incident Response
? Recommended Internet Service Provider Security Services and Procedures
? Recovering from an Incident (CERT)
? Security Practices and Implementations (CERT)
?
[5] Forensics
? Incident response and Forensics Resources
? Forensics resources maintained by Dan Farmer
? Computer Forensics Resource Center
?
[6] Order of Volatility
? Computer Forensics Analysis Class: Introduction, Pg. 14 (Dan Farmer & Wietse Venema)
[7] Process accounting
? Solaris 9 SysAdmin Guide: Resource Management and Network Services, Ch 7
? Enabling Process Accounting on Linux HOWTO
? OpenBSD sa(8) man page
[8] System Activity Data Collector (sadc)
? sadc(8) Linux man page
? Solaris 9 SysAdmin Guide: Monitoring System Performance (Tasks), Ch 24
[9] lsof alternatives
Don't have lsof? These techniques might help.
Solaris 9:
1. use psto find the pid of the process you're interested in.
2. run /usr/proc/bin/pfiles .
3. Look for the string 'ino:' in the output. The number that follows is the 'inode number'.
4. run find -inum
OpenBSD 3.2:
1. run fstat -v.
2. Look in the INUM column to find the the inode numbers that a particular process has open.
3. run find -inum
Poking around in /proc (Deb 3.0, RH 8.0):
1. ls -l /proc//fd
進一步研究
下面的命令沒有在本系列中列出來,它們在分析系統的時候也非常有幫助:nm, size, ar, objdump, what(OBSD3.2), ltrace(Deb3.0, RH8.0), /usr/procebin/*(Sol9), w, who, 和 fuser.


[樓 主] | Posted: 2005-04-23 10:22


ddt2000


級別: 總版主
精華: 1
發帖: 248
威望: 1485 點
金錢: 190 RMB
貢獻值: 0 點
注冊時間:2005-04-03
最後登錄:2006-07-25
第二部分 文件系統工具
原作者:Holt Sorenson
原文:《Incident Response Tools For Unix, Part Two: File-System Tools》
Last Updated: October 17, 2003
翻譯:Refdom
這是關於應急響應工具介紹的三個系列文章中的第二部分。第一部分聚焦在系統工具上,本部分將主要討論文件系統工具,下一部分則主要是網絡工具和其他工具。這三部分都是基於 OpenBSD 3.2, Debian GNU/Linux 3.0 (woody), RedHat 8.0 (psyche), and Solaris 9 (aka Solaris 2.9 or SunOS 5.9)的。這些工具都是系統中比較通用的工具,除了少部分外。如果某個工具在操作系統中不存在,那麼在文章的參考部分中應該可以找到相關信息。
文章中的這些工具都執行在用戶空間。如果攻擊者安裝一些核心模塊,或者root-kit來替換系統上的二進制文件,那麼這些工具就可能不會很准確。這就是將數據離線在安全的系統中分析的一個原因。除非這些數據能夠確認是可信的,否則絕對不能信任它們。介紹多個工具來做相類似的事情,可以在響應事件的時候有更多選擇。
必須強調的是,這些工具都應該僅僅在只讀介質中執行,或者一個安全的系統中用來作離線分析。使用只讀介質可以確認這些工具不能被更改。
在應對事件的時候,安全人員應該首先知道的是,他們優先捕獲紀錄的是哪些數據。這些數據是存在被更改的趨勢的。應急響應隊伍需要討論處理的優先級,是否需要讓機器離線,還是應該先作好系統的鏡像,或者捕獲那些活動數據,比如當前的進程、建立的網絡連接,內存分配和使用情況,用戶登錄情況。在事件發生後,系統在線的時間越長,那麼,從(遠程的、本地)攻擊者或者系統造成破壞的威脅就更大。
通過法律的介入可以來檢驗安全隊伍的事件處理過程是否符合必要的法律取證。類似HTCIA(US)和NHTCU(UK)這樣的組織能夠幫助處理技術專家同應對計算機犯罪進行取證的法律官員之間的聯系。
第一部分文章中最後找到了密碼破解工具,John the Ripper,在本文,我們將利用文件系統工具來繼續去挖掘信息來揭露這個是怎麼被入侵的。
Sum packages need to be checked
攻擊者是在03:17開始破解密碼的,現在從03:17開始進行搜索,但是這個時間並不是攻擊者闖入的時間。攻擊者通常使用一些自動化的程序來掃描和攻擊有漏洞的系統,這就意味著攻擊者使用的工具通常會在一些時間之前就留下了一些痕跡。
現在深入到一些可以幫助我們來檢測文件系統的改變的工具。一些工具在系統中默認存在的,而一些需要另外指定安裝或者是一些第三方的工具。
在Solaris和Linux上,有一些自身存在的命令來比較當前系統安裝的包。命令是: rpm -Vva(RH8.0),pkgchk -vn(Solaris 9),和debsums -ac(Deb3.0)。rpm和debian格式化都能用RFC2440 (OpenPGP)來根據簽名驗證這些包。也可以用MD5來作為校驗和。在Solaris系統上,pkgchk用SystemV(SYSV)算法來驗證二進制是否被篡改。SYSV運算法則可以檢測出只改變文件內容而不改變文件長度的變化。然而,不可能根據SYSV算法來進行完整性檢查。它只是更多地依賴於文件大小和時間戳。用慣了十六進制編輯器和touch命令的人都知道改變文件內容而不改變文件大小,以及改變文件的時間戳,這些操作是多麼的容易。在Debian GNU/Linux,可以指定一套包來進行對比檢查。如果在/mnt上裝載了一套只讀的包 ,可以通過這個命令來檢查包文件:debsums -cagp /mnt/* 。這相當於rpm命令:rpm -Vvp /mnt/Redhat/RPMS/*.rpm 。用rpm -Vva --dbpath 可以來驗證備用數據庫。在Debian系統上相似的命令是: debsums -cagd 。這些數據庫應該保存在只讀介質上並且來自可信系統。如果你想獲得rpm的詳細數量,可以加上參數-v。這些命令可以幫助檢查攻擊者做的一些改變。
package tools verifying current file system state against package metadata:
{redhat80} $ rpm -vVa
[ snip lots of output ]
..5....T /bin/ls
[ snip lots of output ]
{solaris9} $ pkgchk -vn
[ snip lots of output ]
ERROR: /usr/bin/ls
modtime <04/06/02 10:54:41 PM> expected <09/08/03 01:04:01 AM> actual
file cksum <63074> expected <63042> actual
/usr/bin/ls
[ snip lots of output ]
{debian30} $ debsums -ac
[ snip lots of output ]
bin/ls
[ snip lots of output ]
比較當前的系統上的安裝的包的數據庫有很多幫助,但是,如果系統被高度自定義過了,打包系統和當前的文件系統上的metadata可能是完全不同的。所以用包工具來比較當前文件系統狀態和程序包數據庫可能不會得到期望的結果。OpenBSD上有一個工具叫mtree,它可以用hash函數[5]來確信文件系統上的文件從上次數據庫更新起是否被改變過。如果攻擊者附加或者修改已經在mtree的數據庫中存儲了hash的文件,那麼這些改變就可以被mtree檢測出來。另外一些第三方的工具也有類似功能,比如:AIDE, integrit, Osiris和tripwire。另外一些工具,比如:changedfiles, dnotify, 和FAM用核心模塊,或者監控查詢文件系統來檢測文件改變,這些工具可以比文件系統完整性檢測工具更快地得到文件改變的通知。這是因為文件系統完整性檢查工具是通過周期性地用hash函數來檢測的。當然,所有這些工具都應該在被入侵之前先安裝配置好。
那些不是通過hash函數來進行校驗和的命令,則並不應該使用在應急響應中。比如命令chsum和sum。校驗和(checksum)算法(CRC*, BSD和SYSV)不能到達hash函數所能提供的斷言等級。事實上也是這樣,checksum算法根本不能在取證中值得信任。checksum算法主要用於檢測數據傳輸和存儲中是否發生錯誤,而不是用於保護和警報數據被惡意攻擊者修改。很容易可以找到多種數據的組合,而有相同的校驗和。即使先得到數據的checksum,並且把checksum和它們的數據都存儲在只讀介質中,可以確保這些數據不會被修改,而應對的策略則是可以創建另一些數據,並且有相同的checksum,這種應對辦法導致的結果就是這些數據會被懷疑,但是checksum並沒有提供足夠的斷言:這些數據是被篡改了。依賴checksum算法要匹配的復雜度是很小的,而基於MD5算法的復雜度是2^128,SHA1則是2^160。對於MD5和SHA1算法,是很難找到兩組數據能夠產生相同的hash值。checksum算法可以對付數據的意外干擾,而不是對付惡意攻擊的。這就是為什麼使用基於hash函數如MD5或SHA1的必須的。
Hash/Checksum tools in action:
{deb30} $ md5sum /bin/ls
a5c720b6776331b9695d9a1f4f5c2194 /bin/ls
{deb30} $ openssl dgst /bin/ls
MD5(/bin/ls)= a5c720b6776331b9695d9a1f4f5c2194
{deb30} $ shash /bin/ls
# MD5 HASH
a5c720b6776331b9695d9a1f4f5c2194 /bin/ls
{deb30} $ cksum /bin/ls
2890986056 43784 /bin/ls
{deb30} $ sum -r /bin/ls
56701 43
{deb30} $ sum -s /bin/ls
6968 86 /bin/ls
Hey MAC, what time ya got?
UNIX或者類UNIX文件系統存儲一套時間戳元數據,這些時間戳包括modify、access和change時間,即MAC時間。這些時間戳都保存在文件系統索引節點(inode)結構中。除了這些時間戳外,inode也包含其他的文件信息,比如:文件類型、許可、所屬、組、大小、硬連接數,以及文件占用的數據塊。目錄也有它們自己的inode,這包括目錄下的文件名,以及包含文件信息的inode數量。
mtime (modify time)反映的是文件數據最後被修改的時間,系統調用比如write, trucate, mknod 都會改變mtime。 ctime(change time)反映的是文件的inode結構最後被改變的時間,atime(access time)反映的是文件數據最後被訪問的時間。當系統調用execve, read, mknode, utime, pipe等都會修改atime。你可以在stat(2)的幫助中找到更多關於mtime, atime, ctime的細節。
要改變MAC時間有多種不同的命令和不同的方法。下面的表格現實了一些普通命令對MAC時間的作用。這些表是基於使用ext2文件系統的Debian3.0,其中包含加載在loopback設備上的flat file。如果在LINUX系統的loopback設備上加載許多鏡像,可以在引導程序中設置max_loop = 255,來在啟動前傳遞給系統核心。那麼就可以加載255個鏡像,而不是默認限制的8個。一旦文件系統加載到loopback設備上,就可以用debugfs檢查。建議在你自己的系統上對下面表格中的內容進行試驗[9]驗證。下面表中基本是可以通用的。
(譯注:因為文本的排版問題,可參考原文的表格)
How common commands change MACtimes for a directory (foo):
Action atime ctime mtime
creation (mkdir foo) X X X
directory move (mv foo bar) X X
file creation (touch foo/foo) X X
file creation (dd if=/dev/zero of=foo/foo count=1) X X
list directory (ls foo) X
change directory (cd foo)
file test (-f foo)
file move/rename (mv foo foo_mvd) X X
permissions change (chmod/chown foo) X
file copy (mv foo_mvd foo) X X
file edit (vim foo) X X
file edit (emacs foo) X X X
file edit (nvi/nano foo)
How common commands change MACtimes for a file (f1):
Action atime ctime mtime
creation (touch foo) X X X
creation (dd if=/dev/zero of=foo count=1) X X X
rename (mv foo bar)
permissions change (chmod foo) X
copy (cp foo bar) X
copy overwrite (cp bar foo) X X
append (cat >> foo) X X
overwrite (cat > foo) X X
truncate (cp /dev/null foo) X X
list file (ls foo)
edit (vim/emacs/xemacs/joe/jed foo) X X X
edit (ed/nvi/vi (sun)/vi (obsd)/nano/pico foo) X1 X1 X1
1 - all times changed, but atime is slightly older than mtime and ctime
ls命令可以用來現實文件的MAC時間,下表顯示的是多個ls命令,來按最後修改時間的排序列舉。
displaying MACtimes using ls:
Linux (ls from GNU fileutils) OpenBSD Solaris
mtime ls -latr --full-time ls -latTr ls -latr
atime ls -laur --full-time ls -lauTr ls -laur
ctime ls -lacr --full-time ls -lacTr ls -lacr
find命令也是非常有用的,可以用來查詢被修改了的文件,只需要使用-ctime, -atime, -mtime參數。當使用find命令的時候,注意,那些目錄下的文件的atime都會被改變。如果要更正規的使用find命令,那麼應該使用在只讀的鏡像中。
多數Linux都有find[10],GNU版的find有很強的功能,可以指定一個時間區域,這樣讓find來顯示這個區域的時間戳。如果你想查詢多個至少7天前被修改的文件,並現實它們的mtime,ctime,atime和inode,可以用下面的命令:
# find / \\( -mtime +2 -a -mtime -7 \\) -a -printf \"M:%t C:%c %i\\t%p\\n\"
如果使用Linux,但是沒有GNU的find,那麼可以用stat命令,如果沒有stat命令的權限,但可以用perl,那麼可以用perl來當作stat(2):
# find / \\( -mtime +2 -a -mtime -7 \\)|perl -ne
\'chomp;($i,$m,$c)=(stat)[1,9,10];printf\"M:%s\\t$i\\t$_\\n\",localtime($m).\" C:\".localtime($c)\'
攻擊者可能通過有問題的suid或sgid的二進制來提升權限。攻擊者有是也留下可以suid root 的shell,這樣讓他們更方便。find命令可以捕獲到這樣的文件。可以使用這樣的命令:
find / -perm -6000 -ls
下面是一些find命令的例子:
the find command in action:
##==
##== find all files which have had their status changed in
##== the last 24 hrs (display ctime, inode, and filename)
# find / -ctime -1 -printf \"%c %i\\t%p\\n\"
Fri Sep 7 11:55:14 2003 174945 /var/lib/rpm
Fri Sep 7 11:55:14 2003 174946 /var/lib/rpm/__db.001
Fri Sep 7 11:55:17 2003 174947 /var/lib/rpm/__db.002
Fri Sep 7 11:55:17 2003 174948 /var/lib/rpm/__db.003
Fri Sep 7 11:55:55 2003 160125 /var/lib/random-seed
Fri Sep 7 11:55:16 2003 222706 /var/log
Fri Sep 7 12:17:05 2003 224545 /var/log/messages
[ output deleted ]
##==
##== find all files which have had their status changed from
##== 5 to 30 (inclusive) days ago and display the ctime, inode, and filename
# find / -ctime +4 -ctime -31 -printf \"%c %i\\t%p\\n\"
Sat Aug 30 19:49:52 2003 414661 /boot/System.map-2.4.20-20.8bigmem
Sat Aug 30 19:49:52 2003 414662 /boot/config-2.4.20-20.8bigmem
Sat Aug 30 19:49:52 2003 414663 /boot/module-info-2.4.20-20.8bigmem
Sat Aug 30 19:49:53 2003 414664 /boot/vmlinux-2.4.20-20.8bigmem
Sat Aug 30 19:49:53 2003 414665 /boot/vmlinuz-2.4.20-20.8bigmem
[ output deleted ]
If I had a photograph of you... something to remind me...
在Linux和Unix上創建文件系統鏡像的最通常的命令是dd。 dd命令按位從輸入中讀取,並保存在輸出中。dd不顯示進度,因此如果是輸入的塊同輸出塊大小不相同的時候就會非常慢。比dd更友好的是sdd[11],它就沒有這些缺點。sdd可以顯示當前的統計,也可以顯示當前的進度。
在使用dd來制作文件系統鏡像之前,可以先用工具創建需要鏡像的文件系統的hash。假設在Linux平台上要創建/dev/hda的鏡像,可以運行md5sum /dev/hda,然後開始dd。 dd完成後,對保存的鏡像運行相同的工具。如果這些值不匹配,應該檢查為什麼出現了差異。在openBSD和Solaris上進行應急響應的時候,應該用raw device。
對於Linux,工具e2image可以用來創建ext2和ext3文件系統的鏡像。e2image只解釋需要被鏡像的文件系統,而不是保存原始bit。e2image就不能保存那種聰明的攻擊者存儲在磁盤上的文件系統結構之外的數據。 e2image可以創建“raw”和“nomal”鏡像,這兩種方法都可以節約空間。因此,用e2image創建的鏡像同硬盤上的文件系統有不同的hash,這很難讓你對捕獲的數據進行斷言。這導致e2image在取證上,依然是不能替代dd的。
另一個創建系統鏡像的工具是partimage[12],可以將鏡像文件通過ssl傳輸到一個partimage服務器上,當前可以支持ext2,ext3,ReiserFS,JFS,和XFS,也支持FAT16/32和HPFS(OS/2),並且正在逐步增加支持UFS(Solaris, *BSD), HFS(MaxOS)和NTFS。
partimage只能鏡像被使用的分區塊,因此跟e2image一樣,用partimage制作的鏡像並不能精確地反映鏡像制作的時候磁盤的真實狀態。這跟流行的PC產品ghost一樣可以創建鏡像,但是不適合於取證。在面對很嚴重的狀態下,在使用ghost之前,應該先閱讀手冊,確信是否適合你使用。
可能你要問,為什麼在這篇文章中介紹這些不適合於取證的工具。這是基於下面的原因:
當選擇工具[13]來創建取證鏡像的時候,所選用的工具必須能夠精確反映創建鏡像的時候磁盤的真實狀態。
當制作文件系統鏡像的時候,你需要理解工具作者是怎麼理解“image”的。可以用下面方法進行測試:
1,離線測試計算機的文件系統
2,對包含文件系統的設備,運行md5sum或者執行SHA1的工具
3,用工具制作鏡像
4,對鏡像執行md5sum或者SHA1的工具
如果指紋不匹配,那麼就不要在取證中用該工具。
Would you like some file system to go with that debugger?
類似ls, stat,和find這樣的命令,並不能對需要分析的文件系統提供足夠的可見度。也許你想處理用dd創建的文件系統鏡像,你可能擔心被安裝了rootkit,而ls可能已經被替換了,或者有些東西已經被刪除,但還可以恢復,或者在文件系統之外還有一些有用的數據。
這些系統都有文件系統調試器,在OpenBSD和Solaris上這個調試器就是fsdb。Solaris的調試器最復雜,需要花些時間去了解怎麼使用。OpenBSD上的fsdb和對ext2,ext3的debugfs,都可以通過help得到足夠的幫助。對於其他一些流行的Linux文件系統比如JFS,ReiserFS,還沒有交互的文件系統調試器。xfs_db可以支持XFS。但是本文不討論它,因為XFS還不是一個廣泛使用的文件系統。
Linux可以加載外來的文件系統,對於只讀取證非常有用。*BSD的ffs和Solaris的ufs可以用核心模塊的ufs來加載。Linux上的文件系統,如ext2,ext3, JFS, ReiserFS和XFS都可以加載,MSDOS(fat16), fat32和大多數的NTFS鏡像也支持。但是Linux沒有對這些外來文件系統的文件系統調試器。
可以知道下面的命令來找出正在運行的Linux支持的文件系統:find /lib/modules/`uname -r`/kernel/fs/* -type f|grep -v \'nls\\/\'。 要察看當前裝載了哪些文件系統,可以用:grep -v \'^nodev\' /proc/filesystems. 要了解更多信息,可以看mount(8)
要以只讀模式加載鏡像,可以使用:mount -t ext2 -o ro,loop=/dev/loop0 /var/tmp/2003_02_17_attack.bin /mnt. 現在可以用工具來檢查加載的文件系統了。在檢查鏡像的時候,你會改變那些正在操作的目錄或者文件的訪問時間。這些改變只在內存中。一定要記住,用-o以只讀屬性加載鏡像,這樣那些改變就不會直接影響到鏡像文件。而且,最好對鏡像的拷貝進行操作。可以用md5sum來確信拷貝和原始鏡像文件是一樣的。對拷貝進行操作能保證原始鏡像不會被修改。可以在mount(8)察看更多的關於loop 設備的信息。
mounting a file system image in Linux:
##==
##== mount the image read-only so that the image doesn\'t change on disk
# mount -o ro,loop=/dev/loop0 /var/space/images/2003_02_17_linux.bin /mnt
##==
##== list of files
# ls -la /mnt
total 146
drwxr-xr-x 19 root root 1024 Feb 17 2003 .
drwxr-xr-x 19 root root 4096 Sep 12 11:55 ..
-rw-r--r-- 1 root root 0 Sep 12 11:55 .autofsck
-rw------- 1 root root 186 Sep 6 19:58 .bash_history
drwxr-xr-x 2 root root 2048 Feb 8 2003 bin
drwxr-xr-x 3 root root 1024 Sep 6 19:59 boot
drwxr-xr-x 20 root root 116736 Feb 17 2003 dev
drwxr-xr-x 41 root root 3072 Sep 12 14:13 etc
[ output deleted ]
##==
##== unmount /mnt
# umount /mnt
可以用debugfs 來執行debugfs。如果不太了解,可以用help察看debugfs的幫助。如果還不夠,就用man debugfs。 debugfs以只讀模式開始,因此幾乎不會對鏡像文件有改變。但是,還是盡量對鏡像拷貝來操作,而把原始鏡像放安全點。下面是一個使用debugfs的實例:
using debugfs on an ext2 file system image in Linux:
##==
##==
# debugfs /var/space/images/2003_02_17_openbsd_attack.bin
debugfs 1.27 (8-Mar-2002)
##== show file system statistics
debugfs: stats
Filesystem volume name:
Last mounted on:
Filesystem UUID: 93bfa3ee-d684-4d07-a5d0-1654f488aabd
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: filetype sparse_super
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 65536
Block count: 262144
Reserved block count: 13107
Free blocks: 214567
Free inodes: 57335
First block: 1
Block size: 1024
Fragment size: 1024
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 2048
Inode blocks per group: 256
Last mount time: Fri Jan 9 14:13:42 2003
Last write time: Fri Feb 17 23:13:04 2003
Mount count: 1
Maximum mount count: 27
Last checked: Fri Jan 9 14:13:35 2003
Check interval: 15552000 (6 months)
Next check after: Wed Jul 9 14:13:35 2003
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 128
Group 0: block bitmap at 3, inode bitmap at 4, inode table at 5
7928 free blocks, 2033 free inodes, 3 used directories
[output deleted]
##== print the contents of the current inode in directory format
debugfs: ls -l
2 40755 (2) 0 0 1024 17-Feb-2003 23:13 .
2 40755 (2) 0 0 1024 17-Feb-2003 23:13 ..
4097 40700 (2) 0 0 1024 8-Feb-2003 15:17 lost+found
8193 40755 (2) 0 0 116736 17-Feb-2003 23:13 dev
57345 40755 (2) 0 0 1024 8-Feb-2003 16:20 var
43010 41755 (2) 0 0 1024 17-Feb-2003 23:13 tmp
47106 40755 (2) 0 0 3072 17-Feb-2003 11:55 etc
[ output deleted ]
##== show inode information for etc
debugfs: stat etc
Inode: 47106 Type: directory Mode: 0755 Flags: 0x0 Generation: 461325
User: 0 Group: 0 Size: 3072
File ACL: 0 Directory ACL: 0
Links: 41 Blockcount: 6
Fragment: Address: 0 Number: 0 Size: 0
ctime: 0x3f61d525 -- Fri Feb 17 14:16:05 2003
atime: 0x3f61d4ff -- Fri Feb 17 14:15:27 2003
mtime: 0x3f61d496 -- Fri Feb 17 14:13:42 2003
BLOCKS:
(0):188678, (1):189498, (2):189746
TOTAL: 3
##== chdir into directory inode etc
debugfs: cd etc
##== show inode information for passwd
debugfs: stat passwd
Inode: 47121 Type: regular Mode: 0644 Flags: 0x0 Generation: 461394
User: 0 Group: 0 Size: 1282
File ACL: 0 Directory ACL: 0
Links: 1 Blockcount: 4
Fragment: Address: 0 Number: 0 Size: 0
ctime: 0x3f61d505 -- Fri Feb 17 14:50:04 2003
atime: 0x3f61d4b2 -- Fri Feb 17 23:14:10 2003
mtime: 0x3e5e259c -- Thu Feb 17 14:50:04 2003
BLOCKS:
(0-1):188692-188693
TOTAL: 2
##== dump the contents of inode that corresponds to passwd
debugfs: cat passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
[ output deleted ]
debugfs: quit
在OpenBSD上會多些步驟,在加載之前,鏡像需要被配置在vnode磁盤設備上,下面是一個實例:
mounting a file system image in OpenBSD:
##==
##== associate the image with the vnode pseudo disk device
# vnconfig -v -c svnd0 /var/space/images/2003_02_17_openbsd_attack.bin
svnd0: 7277544448 bytes on /var/space/images/2003_02_17_openbsd_attack.bin
##==
##== mount the image read-only so that the image doesn\'t change on disk
# mount -o ro /dev/svnd0c /mnt
##==
##== mount the image read-only so that the image doesn\'t change on disk
# ls -la /mnt
total 9026
drwxr-xr-x 14 root wheel 512 Nov 4 2002 .
drwxr-xr-x 14 root wheel 512 Nov 4 2002 ..
-rw-r--r-- 2 root wheel 685 Nov 4 2002 .cshrc
-rw-r--r-- 2 root wheel 179 Nov 4 2002 .profile
drwxr-xr-x 2 root wheel 512 Oct 4 2002 altroot
drwxr-xr-x 2 root wheel 1024 Oct 4 2002 bin
-r-xr-xr-x 1 root wheel 53248 Nov 4 2002 boot
-rw-r--r-- 1 root wheel 4515116 Nov 4 2002 bsd
drwxr-xr-x 4 root wheel 19968 Sep 12 11:56 dev
drwxr-xr-x 19 root wheel 2048 Mar 28 12:44 etc
[ output deleted ]
##==
##== unmount the image
# umount /mnt
##==
##== dis-associate the image from the vnode pseudo disk device
# vnconfig -v -u svnd0
svnd0: cleared
fsdb是OpenBSD的FFS(fast file system)編輯器。 fsdb沒有只讀屬性,因此鏡像拷貝在這裡就更重要了。而且在fsdb中的cd命令也可能跟ci命令一樣有寫操作,這會改變[active]inode。
using fsdb on a file system image in OpenBSD:
##==
##== associate the image with the vnode pseudo disk device
# vnconfig -vc svnd0 /var/space/images/2003_02_17_openbsd_attack.bin
svnd0: 7277544448 bytes on /var/space/images/2003_02_17_openbsd_attack.bin
##==
##== start fsdb on /dev/svnd0c
# fsdb -f /dev/rsvnd0c
** /dev/rsvnd0c
** File system is already clean
Editing file system `/dev/rsvnd0c\'
Last Mounted on /mnt
current inode: directory
I=2 MODE=40755 SIZE=512
MTIME=Nov 4 19:49:30 2002 [0 nsec]
CTIME=Nov 4 19:49:30 2002 [0 nsec]
ATIME=Apr 11 14:06:57 2003 [0 nsec]
OWNER=root GRP=wheel LINKCNT=14 FLAGS=0 BLKCNT=2 GEN=e32f2a77
fsdb (inum: 2)> ls
slot 0 ino 2 reclen 12: directory, `.\'
slot 1 ino 2 reclen 12: directory, `..\'
slot 2 ino 0 reclen 16: regular, `boot\'
slot 3 ino 7488 reclen 16: directory, `altroot\'
slot 4 ino 33216 reclen 12: directory, `bin\'
slot 5 ino 14016 reclen 12: directory, `dev\'
slot 6 ino 42816 reclen 12: directory, `etc\'
slot 7 ino 42048 reclen 16: directory, `home\'
slot 8 ino 59904 reclen 12: directory, `mnt\'
slot 9 ino 6528 reclen 16: directory, `root\'
slot 10 ino 5568 reclen 16: directory, `sbin\'
slot 11 ino 45888 reclen 16: directory, `stand\'
slot 12 ino 27072 reclen 12: directory, `tmp\'
slot 13 ino 41472 reclen 12: directory, `usr\'
slot 14 ino 6336 reclen 12: directory, `var\'
slot 15 ino 6529 reclen 16: regular, `.cshrc\'
slot 16 ino 6532 reclen 20: regular, `.profile\'
slot 17 ino 4 reclen 12: symlink, `sys\'
slot 18 ino 0 reclen 260: regular, `bsd\'
fsdb (inum: 2)> cd etc/passwd
component `passwd\': current inode: regular file
I=42860 MODE=100644 SIZE=1033
MTIME=Feb 27 21:38:23 2003 [0 nsec]
CTIME=Feb 27 21:38:23 2003 [0 nsec]
ATIME=Apr 11 13:49:57 2003 [0 nsec]
OWNER=root GRP=wheel LINKCNT=1 FLAGS=0 BLKCNT=4 GEN=4bf628a5
fsdb (inum: 42860)> quit
##==
##== dis-associate the image from the vnode pseudo disk device
# vnconfig -vu svnd0
svnd0: cleared
類似OpenBSD,在Solaris上處理鏡像也需要多點步驟。Solaris有一個被稱為lofi(即 loopback file)的驅動。在用lofiadm之前,核心不會表明lofi模塊被安裝了,啟用lofiadm後,應該找到加載到核心的lofi驅動。用modinfo命令來顯示當前加載的核心模塊。lofiadm命令包含在SUNWcsu包中,而不需要安裝任何其他的包或者工具。下面是一個實例:
mounting a file system image in Solaris:
##==
##== register the image available as a block device via the loopback driver:
# lofiadm -a /mnt/images/2003_02_17_attack.bin
/dev/lofi/1
##==
##== verify that the image is registered
# lofiadm
Block Device File
/dev/lofi/1 /var/space/images/2003_02_17_attack.bin
##==
##== mount the image read-only so that the image doesn\'t change on disk
# mount -o ro /dev/lofi/1 /mnt
##==
##== mount the image read-only so that the image doesn\'t change on disk
# ls -la /mnt
/mnt:
total 586
drwxr-xr-x 21 root root 512 Dec 3 04:10 .
drwxr-xr-x 21 root root 512 Dec 3 04:10 ..
-rw------- 1 root other 4432 Feb 17 04:25 .sh_history
lrwxrwxrwx 1 root root 9 Nov 28 06:07 bin -> ./usr/bin
drwxr-xr-x 2 root nobody 512 Nov 28 07:32 cdrom
drwxr-xr-x 15 root sys 4096 Feb 17 04:14 dev
drwxr-xr-x 4 root sys 512 Nov 28 06:29 devices
drwxr-xr-x 41 root sys 3584 Feb 16 17:00 etc
[ output deleted ]
##==
##== un-mount the image
# umount /mnt
##==
##== unregister the image from the loopback driver
# lofiadm -d /dev/lofi/1
fsdb是一個值得花時間的工具。如果你能夠掌握這個工具,那麼它的命令可能很復雜。最有用的文檔是OS提供的fsdb_ufs(1M) man手冊。
using fsdb on a file system image in Solaris:
##==
##== register the image available as a block device via the loopback driver:
# lofiadm -a /mnt/images/2003_02_17_attack.bin
/dev/lofi/1
##==
##== verify that the image is registered:
# lofiadm
Block Device File
/dev/lofi/1 /mnt/images/2003_02_17_attack.bin
##==
##== browse the image using fsdb:
# fsdb /dev/lofi/1
fsdb of /dev/lofi/1 (Read only) -- last mounted on /
fs_clean is currently set to FSCLEAN
fs_state consistent (fs_clean CAN be trusted)
##==
##== print the super block
/dev/lofi/1 > :sb
super block:
magic 11954 format dynamic time Mon Feb 17 18:36:05 2003
nbfree 605536 ndir 6363 nifree 889612 nffree 8252
ncg 290 ncyl 4631 size 8314960 blocks 8187339
bsize 8192 shift 13 mask 0xffffe000
fsize 1024 shift 10 mask 0xfffffc00
frag 8 shift 3 fsbtodb 1
cpg 16 bpg 3591 fpg 28728 ipg 3392
minfree 1% optim time maxcontig 16 maxbpg 2048
rotdelay 0ms fs_id[0] 0x0 fs_id[1] 0x0 rps 120
ntrak 27 nsect 133 npsect 133 spc 3591
trackskew 0 interleave 1
nindir 2048 inopb 64 nspf 2
sblkno 16 cblkno 24 iblkno 32 dblkno 456
sbsize 5120 cgsize 5120 cgoffset 72 cgmask 0xffffffe0
csaddr 456 cssize 5120 shift 9 mask 0xfffffe00
cgrotor 187 fmod 0 ronly 0
blocks available in each of 8 rotational positions
cylinder number 0:
[ output deleted ]
##==
##== show current entries in this directory:
/dev/lofi/1 > :ls -l
/:
i#: 2 ./
i#: 2 ../
i#: 2bc0 etc/
i#: 8c02 kernel/
i#: 3 lost+found/
i#: 8c0 usr/
[ output deleted ]
##==
##== set the current block to be examined to block 2bc0 (/etc) and display the
##== information in block 2bc0 as an inode:
##== note that :pwd will still show the current location as / because you\'re
##== examining data blocks on the file system. You haven\'t actually left /.
##== To navigate the directory hierarchy, you need to use :cd
/dev/lofi/1 > 2bc0:inode?i
i#: 2bc0 md: d---rwxr-xr-x uid: 0 gid: 3
ln: 29 bs: 8 sz : c_flags : 0 e00
db#0: 65a8
accessed: Tue May 27 04:38:06 2003
modified: Mon May 26 17:00:44 2003
created : Tue May 27 04:38:06 2003
/dev/lofi/1 > :ls -l
i#: 2c21 passwd
i#: 2c1e path_to_inst
i#: 2c3e pwck@
i#: 2bee rc0@
i#: 6042 rc0.d/
i#: 2bef rc1@
i#: 6901 rc1.d/
i#: 2bf0 rc2@
i#: 71c2 rc2.d/
i#: 2bf1 rc3@
i#: 7a82 rc3.d/
i#: 2bf2 rc5@
i#: 2bf3 rc6@
i#: 2bf4 rcS@
i#: 834e rcS.d/
i#: 2c2d shadow
[ output deleted ]
##==
##== set the current block to be examined to block 2c21 (/etc/passwd) and display the
##== information in block 2c21 as an inode:
/dev/lofi/1 > 2c21:inode?i
i#: 2c21 md: ----r--r--r-- uid: 0 gid: 3
ln: 1 bs: 2 sz : c_flags : 0 20f
db#0: 6554
accessed: Tue May 27 04:37:58 2003
modified: Thu Nov 28 08:18:06 2002
created : Tue May 27 04:37:58 2003
##==
##== display the information in current block as ASCII data:
##== you can display the block in hex using: 0:db:block,*/X
/dev/lofi/1 > 0:db:block,*/c
1955000: r o o t : x : 0 : 1 : S u p e r
1955010: - U s e r : / : / s b i n / s h
1955020: \\n d a e m o n : x : 1 : 1 : : /
1955030: : \\n b i n : x : 2 : 2 : : / u s
1955040: r / b i n : \\n s y s : x : 3 : 3
1955050: : : / : \\n a d m : x : 4 : 4 : A
1955060: d m i n : / v a r / a d m : \\n l
1955070: p : x : 7 1 : 8 : L i n e P r
1955080: i n t e r A d m i n : / u s r
1955090: / s p o o l / l p : \\n u u c p :
19550a0: x : 5 : 5 : u u c p A d m i n
19550b0: : / u s r / l i b / u u c p : \\n
19550c0: n u u c p : x : 9 : 9 : u u c p
19550d0: A d m i n : / v a r / s p o o
19550e0: l / u u c p p u b l i c : / u s
19550f0: r / l i b / u u c p / u u c i c
1955100: o \\n s m m s p : x : 2 5 : 2 5 :
1955110: S e n d M a i l M e s s a g e
1955120: S u b m i s s i o n P r o g
1955130: r a m : / : \\n l i s t e n : x :
1955140: 3 7 : 4 : N e t w o r k A d m
1955150: i n : / u s r / n e t / n l s :
1955160: \\n n o b o d y : x : 6 0 0 0 1 :
1955170: 6 0 0 0 1 : N o b o d y : / : \\n
1955180: n o a c c e s s : x : 6 0 0 0 2
1955190: : 6 0 0 0 2 : N o A c c e s s
19551a0: U s e r : / : \\n n o b o d y 4
19551b0: : x : 6 5 5 3 4 : 6 5 5 3 4 : S
19551c0: u n O S 4 . x N o b o d y :
19551d0: / : \\n k r h : x : 1 1 1 9 : 1 1
19551e0: 1 9 : K r 4 D H a X 0 R y o
19551f0: : / e x p o r t / h o m e / k r
1955200: h : / u s r / b i n / k s h \\n
[ output deleted ]
##==
##== unregister the image from the loopback driver:
# lofiadm -d /dev/lofi/1
有時也需要察看鏡像的原始信息,而不是經過文件系統調試器解釋過的。這裡有幾種這樣的工具來達到目的。
十六進制編輯器,如hexedit,這個工具作為了Redhat的一部分,也可以在OpenBasd中安裝(/usr/ports)[1]。如果沒有十六進制編輯器,也可以用emacs或者vim。用emacs 可以察看鏡像,使用\'Esc-x toggle-read-only\'以只讀模式使用。要改變到十六進制編輯器,則使用\'Esc-x hexl-mode\',要退出,則用\'Ctrl-x Ctrl-c\'. 要察看emacs的更多信息,可以用\'Ctrl-h t\'來察看emacs手冊。
vim的十六進制編輯支持能力相對emacs來說就差多了。以只讀模式而沒有交換文件啟動vim,可以用:vim -nRb 。然後輸入\'Esc:%!xxd\'轉換文件顯示為十六進制。退出則輸入\'esc:q!\'。可以用F1鍵察看vim的幫助。
因為RAM和swap是有限的,因此也限制了編輯器察看大文件。一旦系統開始交換swap,會話就會慢下來。可以用split和csplit將文件系統鏡像分成多個文件。你進行的改變越多(分文件,壓縮),那麼下結論就更需要小心。
如果emacs和vim不可用,那麼對於Solaris可以使用od,並跟上less,more來作頁顯示。OpenBSD,Redhat,Solaris都有pg.od 。od可以以多種格式導出數據。 od -vxca以十六進制導出數據,並以C類型顯示字符,和它們的ASCII字符。
Transferring data from the compromised host
如果需要在創建取證鏡像,從在線主機中傳輸出來,有一些問題需要考慮:
* 傳輸要盡可能小地保證文件系統不會被干擾
* 要通過安全的隧道傳輸到可信主機
* 不應該運行有問題主機的程序,而應該從CD中運行
* 如果調查需要法律介入,那麼就應該遵循法律調查員的步驟流程
* 如果在使用存儲數據主機的認證信任證書,那麼,有可能攻擊者也在用或者盜取你的信任書。
有多種辦法可以保存最重要的數據。可以用HUB或者交叉線傳輸,或者使用ssh或者用其他工具通過TLS/SSL傳輸。
將需要分析的被入侵的主機連接到保存取證數據的安全主機所在的私有網絡,這種辦法有一些缺陷:
* 一旦主機不再連,那麼其他遠程主機的連接也丟失了。
* 很難能再觀察攻擊者的行為
* 觀察攻擊者安裝的程序也會更困難。比如攻擊者安裝客戶端同遠程主機連接,當遠程主機無法通訊的時候,就很難檢查客戶端-服務器端之間的交互。
* 因為攻擊者無法再連接主機,要指出攻擊者怎麼連接主機也會更困難。
總之,在作出判斷之前,還需要有一些需要權衡考慮計劃的地方。
1、建立物理層。
* 用交叉線連接信息中心NIC
* 通過HUB連接兩個NIC
2、在受入侵主機的相同IP網絡架設取證數據存儲服務器
3、用netcat和dd傳輸取證數據到存儲服務器。
moving data with dd and netcat:
sechost# nc -lp 8091 >
##== use a tcp over ethernet friendly block size of 1460
hckdhost# dd if=/dev/hda bs=1460|nc -w10 8091
sechost# od -xvca |less
另外一個工具是socat[6],這個工具相對netcat來說功能更多,它可以用多種方式傳輸數據。注意:下面命令都使用了ignoreof選項。
moving data via socat:
##== use a tcp over ethernet friendly block size of 1460
sechost# /usr/local/socat/bin/socat -b 1460 -t5 OPEN:/dev/hda,ignoreeof,rdonly TCP4::8091
hckdhost# /usr/local/socat/bin/socat -b 1460 -t5 TCP4-LISTEN:8091 OPEN:>save_file<,create,excl,largefile,ignoreeof
sechost# od -xvca |less
如果不願意或者不能把主機離線,可以用ssh安全傳輸數據。下面的腳本將當前的網絡連接狀態,當前的進程列表,多個系統信息以及文件系統鏡像保存在遠程主機,
example script for moving data to a secure host via ssh:
#!/bin/bash
# This is a quick hack for demonstration purpose only. It needs
# to be adapted to your environment. This script works on Linux.
# YMMV elsewhere.
rem_host=\"192.168.27.23\"
ssh=\"ssh forensics@${rem_host}\"
# get uname -a, uptime, and Debian or RedHat version info
echo -e `uname -a` \"\\n\" `uptime` \"\\n\"
`[ -s /etc/debian_version ] &&
echo Debian $(cat /etc/debian_version) || cat /etc/redhat-release`
| ${ssh} \"dd of=/var/tmp/incidents/sysinfo\"
# save process information
ps auwwx | ${ssh} \"dd of=/var/tmp/incidents/processes_bsd\"
ps -eflyc | ${ssh} \"dd of=/var/tmp/incidents/processes_sysv\"
# save list of open files
lsof | ${ssh} \"dd of=/var/tmp/incidents/lsof\"
# save networking information
netstat -A INET -anv | ${ssh} \"dd of=/var/tmp/incidents/netstat_infos\"
lsof -Pni | ${ssh} \"dd of=/var/tmp/incidents/lsofnet_infos\"
# save loaded modules
# use modinfo on Solaris, modstat on OpenBSD
lsmod | ${ssh} \"dd of=/var/tmp/incidents/modules\"
# wtmp info from last
# snagging /var/log/[wu]tmp* might not be bad idea
last | ${ssh} \"dd of=/var/tmp/incidents/last\"
# info from process accounting
# snagging /var/account/* might not be a bad idea
# lastcomm is used here, dump-acct can work too
# system accounting (sar) if enable can be useful too. files are usually ing
# /var/log/sysstat
lastcomm | ${ssh} \"dd of=/var/tmp/incidents/last\"
# save /etc and logs
tar cvjf - /etc /var/log/* | ${ssh} \"dd of=/var/tmp/incidents/files_and_logs.tar.bz2\"
# use mount to determine currently mounted drives to image. This might need
# tweaking depending on your system, so that it only picks up the drives you want.
# Is compressing with bzip2 ok for forensics in your world? Since you\'re applying
# a transform before taking an md5sum, it\'s possible it could cause an issue. Consult
# LE or Legal.
#
# This doesn\'t handle swap if swap lives on a drive that isn\'t in the list that
# mount generates. Use \'swapon -s\'.
#
# bzip2 can run on whichever machine is faster, or it can be used before the
# data goes over the network. If your network is fast enough, bziping on the remote
# host is a good idea to conserve space. Software compression can take more time than
# it takes to move uncompressed data across a network, if the network is fast enough.
# In these situations compress only if you\'re worried about space, or compress after
# the transfer is done.
for drive in `mount |grep \'^\\/dev.* (rw\'|awk \'{print $1}\'|sed \'s/[0-9]\\+$//\'|sort|uniq`
do
drive_name=`basename ${drive}`
dd if=${drive} |${ssh} \"bzip2 -9c|dd of=/var/tmp/incidents/${drive_name}.raw.bz2\"
done
另一種安全傳輸信息的方法是使用socat[16]。socat目前不支持接受TLS/SSL連接,如果要用這種方式,可以使用stunnel[17]來代替。
下面的步驟表示怎麼用socat和stunnel來傳輸數據:
1、創建自簽名證書[18]
2、將diffe-hellman 參數附加到自簽名證書
3、用cert的hash創建到cert的symlink
4、編輯主機上的hosts.allow,以便合適的主機可以連接
5、啟動stunnel,並對每個接入的連接執行frecv.pl
6、用socat發送需要的文件。
moving data using socat and stunnel:
##== 1
sechost# openssl req -new -x509 -nodes -days 365 -out stunnel.pem -keyout stunnel.pem
##== 2
sechost# dd if=/dev/urandom count=8 |openssl dhparam 512 >> stunnel.pem
##== 3
sechost# ln -sf stunnel.pem `openssl x509 -noout -hash < stunnel.pem`.0
##== 4
sechost# vi /etc/hosts.allow
##== 5
sechost# stunnel -fd :9001 -l ./frecv.pl -p stunnel.pem -P none
##== use a tcp over ethernet friendly block size of 1460
##== 6
hckdhost# /usr/local/socat/bin/socat -b 1460 -t5 OPEN:/dev/hda,ignoreeof,rdonly OPENSSL::9001
sechost# od -xvca |less
在進一步研究和更多資源(Further Study and Resourses) 一節中,可以獲得更多的工具和資源。因為Infocus作者和其他的文章也進行了描述,所以這裡就不再挨個介紹了。
總結
本文覆蓋了一些在進行調查取證檢查文件系統的時候用到的工具。一定要使用多種工具來驗證某個工具的顯示結果。如果要用到ls,最好是先用find -ls來驗證一下。一定要使用強hash算法比如MD5或SHA1的工具。確認在不離線情況下移動數據的時候,要保證這些數據的安全。創建有效的事件響應處理流程更能幫助你規范地收集信息。保持技術和經驗領先趨勢,你的調查就更容易!
關於作者:
(譯注:作者的介紹就不翻譯完了,真對不住。下面的內容,因為文本COPY的原因,具體連接地址請參考原文)
References
[1] Acquiring/Installing software
OpenBSD ports system
FreeBSD ports system
Freeware for Solaris
HOWTO install packages on a Debian system
Installing packages on a RedHat system
GNU binutils (readelf)
lsof
top
sudo
[2] CD-ROM and Floppy distributions
F.I.R.E. (Forensic and Incident Response Environment) Bootable CD
Knoppix Linux
How to Make a Bootable, Full System OpenBSD CD-ROM
LNX-BBC mini-linux distribution
Google\'s Tiny Linux distributions list
[3] Package Formats
Debian Linux (deb) package format
RedHat Linux (RPM) package format
Solaris package format
packages on OpenBSD: [1], [2]
package format comparisons
[4] OpenBSD\'s mtree
mtree (OpenBSD 3.3)
[5] Hash functions
An Introduction to OpenSSL, Part One: Cryptographic Functions, 4th section
RSA Labs FAQ
Internet Encyclopedia - Hash functions
The MD5 hash function algorithm
The Secure Hash Standard: SHA1 and SHA-256...512,
[6] File-system integrity verification tools
AIDE
integrit
Osiris
tripwire (open source), tripwire (commercial)
[7] changedfiles, dnotify, and FAM
changedfiles
dnotify
FAM
[8] shash
shash
lib mhash (shash dependency)
[9] Creating file systems for experimentation
Linux
create a file that is about the size of a file system that you\'d like to test:
dd if=/dev/zero of=/var/tmp/testfs bs=1048576 count=
create the file system: mke2fs -m0 /var/tmp/testfs
turn off forced fsck: tune2fs -c 0 /var/tmp/testfs
mount the file system or use debugfs:
mount -o loop=/dev/loop0 /var/tmp/testfs /mnt
debugfs /var/tmp/testfs
unmount the file system if necessary: umount /mnt
OpenBSD
create a file that is about the size of a file system that you\'d like to test using:
dd if=/dev/zero of=/var/tmp/testfs bs=1048576 count=
configure the pseudo file system as vnode disk device: vnconfig -v -c svnd0 /var/tmp/testfs
create the file system: newfs /dev/rsvnd0c
mount the pseudo file system or use fsdb:
mount /dev/svnd0c /mnt
fsdb -f /dev/rsvnd0c
unmount the file system if necessary: umount /mnt
unconfigure the vnode disk device: vnconfig -v -u svnd0
Solaris
create a file that is about the size of a file system that you\'d like to test:
dd if=/dev/zero of=/var/tmp/testfs bs=1048576 count=
register the file system with the loopback device driver: lofiadm -a /var/tmp/testfs
create the file system: newfs /dev/lofi/1
mount the file system or use fsdb:
mount /dev/lofi/1 /mnt
fsdb /dev/lofi/1
unregister the file system from the loopback device driver: lofiadm -d /dev/lofi/1
unmount the file system if necessary: umount /mnt
[10] GNU Coreutils
GNU file utilities
GNU core utilities
[11] Shily\'s dd
sdd (schily dd)
[12] Partition Image
partimage - Partition Image
[13] Forensics Tools
September 2000 Market Survey Computer Forensics
Open Source Digital Forensic Tools: The Legal Argument
Gatekeeping Out Of The Box: Open Source Software As A Mechanism To Assess Reliability For Digital Evidence
[14] Cross-over cables
Section 12.2 of the comp.dcom.cabling FAQ - 10/100 Ethernet Crossover cable
Gigabit Crossover cable map
Gigabit Ethernet RJ-45 Port Pinouts (Cisco)
[15] netcat
netcat
[16] socat
socat
[17] stunnel
stunnel
stunnel examples
stunnel FAQ
[18] OpenSSL
OpenSSL
An Introduction to OpenSSL, Part Three: PKI- Public Key Infrastructure
Further Study and Resources
Freeware Forensics Tools for Unix
An introduction to the The Coroner\'s Toolkit
Forensics resources (Dan Farmer), Forensics resources (Wietse Venema)
The Sleuth Kit
Dave Dittrich\'s Forensics Resources
fsend.pl and frecv.pl
Copyright © Linux教程網 All Rights Reserved