1、rootkit簡介php
rootkit是Linux平臺下最多見的一種***後門工具,它主要經過替換系統文件來達到***和和隱蔽的目的,這種***比普通***後門更加危險和隱蔽,普通的檢測工具和檢查手段很難發現這種***。rootkit***能力極強,對系統的危害很大,它經過一套工具來創建後門和隱藏行跡,從而讓***者保住權限,以使它在任什麼時候候均可以使用root權限登陸到系統。html
rootkit主要有兩種類型:文件級別和內核級別,下面分別進行簡單介紹。c++
一、文件級別rootkit安全
文件級別的rootkit通常是經過程序漏洞或者系統漏洞進入系統後,經過修改系統的重要文件來達到隱藏本身的目的。在系統遭受rootkit***後,合法的文件被***程序替代,變成了外殼程序,而其內部是隱藏着的後門程序。一般容易被rootkit替換的系統程序有login、ls、ps、ifconfig、du、find、netstat等,其中login程序是最常常被替換的,由於當訪問Linux時,不管是經過本地登陸仍是遠程登陸,/bin/login程序都會運行,系統將經過/bin/login來收集並覈對用戶的帳號和密碼,而rootkit就是利用這個程序的特色,使用一個帶有根權限後門密碼的/bin/login來替換系統的/bin/login,這樣***者經過輸入設定好的密碼就能輕鬆進入系統。此時,即便系統管理員修改root密碼或者清除root密碼,***者仍是同樣能經過root用戶登陸系統。***者一般在進入Linux系統後,會進行一系列的***動做,最多見的是安裝嗅探器收集本機或者網絡中其餘服務器的重要數據。在默認狀況下,Linux中也有一些系統文件會監控這些工具動做,例如ifconfig命令,因此,***者爲了不被發現,會千方百計替換其餘系統文件,常見的就是ls、ps、ifconfig、du、find、netstat等。若是這些文件都被替換,那麼在系統層面就很難發現rootkit已經在系統中運行了。bash
這就是文件級別的rootkit,對系統維護很大,目前最有效的防護方法是按期對系統重要文件的完整性進行檢查,若是發現文件被修改或者被替換,那麼極可能系統已經遭受了rootkit***。檢查件完整性的工具不少,常見的有Tripwire、 aide等,能夠經過這些工具按期檢查文件系統的完整性,以檢測系統是否被rootkit***。服務器
二、內核級別的rootkit網絡
內核級rootkit是比文件級rootkit更高級的一種***方式,它可使***者得到對系統底層的徹底控制權,此時***者能夠修改系統內核,進而截獲運行程序向內核提交的命令,並將其重定向到***者所選擇的程序並運行此程序,也就是說,當用戶要運行程序A時,被***者修改過的內核會僞裝執行A程序,而實際上卻執行了程序B。app
內核級rootkit主要依附在內核上,它並不對系統文件作任何修改,所以通常的檢測工具很難檢測到它的存在,這樣一旦系統內核被植入rootkit,***者就能夠對系統隨心所欲而不被發現。目前對於內核級的rootkit尚未很好的防護工具,所以,作好系統安全防範就很是重要,將系統維持在最小權限內工做,只要***者不能獲取root權限,就沒法在內核中植入rootkit。less
2、rootkit後門檢測工具chkrootkitssh
chkrootkit是一個Linux系統下查找並檢測rootkit後門的工具,它的官方址: http://www.chkrootkit.org/。 chkrootkit沒有包含在官方的CentOS源中,所以要採起手動編譯的方法來安裝,不過這種安裝方法也更加安全。下面簡單介紹下chkrootkit的安裝過程。
1.準備gcc編譯環境
對於CentOS系統,須要安裝gcc編譯環境,執行下述三條命令: [root@server ~]# yum -y install gcc [root@server ~]# yum -y install gcc-c++ [root@server ~]# yum -y install make
二、安裝chkrootkit
爲了安全起見,建議直接從官方網站下載chkrootkit源碼,而後進行安裝,操做以下: [root@server ~]# tar zxvf chkrootkit.tar.gz [root@server ~]# cd chkrootkit-* [root@server ~]# make sense # 注意,上面的編譯命令爲make sense [root@server ~]# cd .. [root@server ~]# cp -r chkrootkit-* /usr/local/chkrootkit [root@server ~]# rm -rf chkrootkit-*
三、使用chkrootkit
安裝完的chkrootkit程序位於/usr/local/chkrootkit目錄下,執行以下命令便可顯示chkrootkit的詳細用法:
[root@server chkrootkit]# /usr/local/chkrootkit/chkrootkit -h Usage: /usr/lib64/chkrootkit-0.49/chkrootkit [options] [test ...] Options: -h show this help and exit -V show version information and exit -l show available tests and exit -d debug -q quiet mode -x expert mode -r dir use dir as the root directory -p dir1:dir2:dirN path for the external commands used by chkrootkit -n skip NFS mounted dirs
chkrootkit各個參數的含義以下所示。
-h:顯示幫助信息 -v:顯示版本信息 -l:顯示測試內容 -d:debug模式,顯示檢測過程的相關指令程序 -q:安靜模式,只顯示有問題的內容 -x:高級模式,顯示全部檢測結果 -r:dir設置指定的目錄爲根目錄 -p:dir1:dir2:dirN指定chkrootkit檢測時使用系統命令的目錄 -n:跳過NFS鏈接的目錄
chkrootkit的使用比較簡單,直接執行chkrootkit命令便可自動開始檢測系統。下面是某個系統的檢測結果:
[root@server chkrootkit]# /usr/local/chkrootkit/chkrootkit Checking `ifconfig'... INFECTED Checking `ls'... INFECTED Checking `login'... INFECTED Checking `netstat'... INFECTED Checking `ps'... INFECTED Checking `top'... INFECTED Checking `sshd'... not infected Checking `syslogd'... not tested Checking `tar'... not infected Checking `tcpd'... not infected Checking `tcpdump'... not infected Checking `telnetd'... not found
從輸出能夠看出,此係統的ifconfig、ls、login、netstat、ps和top命令已經被感染。針對被感染rootkit的系統,最安全而有效的方法就是備份數據從新安裝系統。
四、chkrootkit的缺點
chkrootkit在檢查rootkit的過程當中使用了部分系統命令,所以,若是服務器被******,那麼依賴的系統命令可能也已經被***者替換,此時chkrootkit的檢測結果將變得徹底不可信。爲了不chkrootkit的這個問題,能夠在服務器對外開放前,事先將chkrootkit使用的系統命令進行備份,在須要的時候使用備份的原始系統命令讓chkrootkit對rootkit進行檢測。這個過程能夠經過下面的操做實現:
[root@server ~]# mkdir /usr/share/.commands [root@server ~]# cp `which --skip-alias awk cut echo find egrep id head ls netstat ps strings sed uname` /usr/share/.commands [root@server ~]# /usr/local/chkrootkit/chkrootkit -p /usr/share/.commands/ [root@server share]# cd /usr/share/ [root@server share]# tar zcvf commands.tar.gz .commands [root@server share]# rm -rf commands.tar.gz
上面這段操做是在/usr/share/下創建了一個.commands隱藏文件,而後將chkrootkit使用的系統命令進行備份到這個目錄下。爲了安全起見,能夠將.commands目錄壓縮打包,而後下載到一個安全的地方進行備份,之後若是服務器遭受***,就能夠將這個備份上傳到服務器任意路徑下,而後經過chkrootkit命令的「-p」參數指定這個路徑進行檢測便可。
3、rootkit後門檢測工具RKHunter
RKHunter是一款專業的檢測系統是否感染rootkit的工具,它經過執行一系列的腳原本確認服務器是否已經感染rootkit。在官方的資料中,RKHunter能夠做的事情有: 1.MD5校驗測試,檢測文件是否有改動 2.檢測rootkit使用的二進制和系統工具文件 3.檢測特洛伊***程序的特徵碼 4.檢測經常使用程序的文件屬性是否異常 5.檢測系統相關的測試 6.檢測隱藏文件 7.檢測可疑的核心模塊LKM 8.檢測系統已啓動的監聽端口
下面詳細講述下RKHunter的安裝與使用。
一、安裝RKHunter
RKHunter的官方網頁地址爲:http://www.rootkit.nl/projects/rootkit_hunter.html,建議從這個網站下載RKHunter,這裏下載的版本是rkhunter-1.4.0.tar.gz。RKHunter的安裝很是簡單,過程以下:
[root@server ~]# tar -zxvf rkhunter-1.4.0.tar.gz [root@server ~]# cd rkhunter-1.4.0 [root@server rkhunter-1.4.0]# ./installer.sh --layout default --install 這裏採用RKHunter的默認安裝方式,rkhunter命令被安裝到了/usr/local/bin目錄下。
二、使用rkhunter指令
rkhunter命令的參數較多,可是使用很是簡單,直接運行rkhunter便可顯示此命令的用法。下面簡單介紹下rkhunter經常使用的幾個參數選項。
[root@server ~]#/usr/local/bin/rkhunter --help Usage: rkhunter {--check | --unlock | --update | --versioncheck | --propupd [{filename | directory | package name},...] | --list [{tests | {lang | languages} | rootkits | perl | propfiles}] | --config-check | --version | --help} [options] Current options are: --append-log Append to the logfile, do not overwrite --bindir <directory>... Use the specified command directories -c, --check Check the local system -C, --config-check Check the configuration file(s), then exit --cs2, --color-set2 Use the second color set for output --configfile <file> Use the specified configuration file --cronjob Run as a cron job (implies -c, --sk and --nocolors options) --dbdir <directory> Use the specified database directory --debug Debug mode (Do not use unless asked to do so) --disable <test>[,<test>...] Disable specific tests (Default is to disable no tests) --display-logfile Display the logfile at the end --enable <test>[,<test>...] Enable specific tests (Default is to enable all tests) --hash {MD5 | SHA1 | SHA224 | SHA256 | SHA384 | SHA512 | NONE | <command>} Use the specified file hash function (Default is SHA1, then MD5) -h, --help Display this help menu, then exit --lang, --language <language> Specify the language to use (Default is English) --list [tests | languages | List the available test names, languages, rootkits | perl | rootkit names, perl module status propfiles] or file properties database, then exit -l, --logfile [file] Write to a logfile (Default is /var/log/rkhunter.log) --noappend-log Do not append to the logfile, overwrite it --nocf Do not use the configuration file entries for disabled tests (only valid with --disable) --nocolors Use black and white output --nolog Do not write to a logfile --nomow, --no-mail-on-warning Do not send a message if warnings occur --ns, --nosummary Do not show the summary of check results --novl, --no-verbose-logging No verbose logging --pkgmgr {RPM | DPKG | BSD | Use the specified package manager to obtain or SOLARIS | NONE} verify file property values. (Default is NONE) --propupd [file | directory | Update the entire file properties database, package]... or just for the specified entries -q, --quiet Quiet mode (no output at all) --rwo, --report-warnings-only Show only warning messages --sk, --skip-keypress Don't wait for a keypress after each test --summary Show the summary of system check results (This is the default) --syslog [facility.priority] Log the check start and finish times to syslog (Default level is authpriv.notice) --tmpdir <directory> Use the specified temporary directory --unlock Unlock (remove) the lock file --update Check for updates to database files --vl, --verbose-logging Use verbose logging (on by default) -V, --version Display the version number, then exit --versioncheck Check for latest version of program -x, --autox Automatically detect if X is in use -X, --no-autox Do not automatically detect if X is in use
Rkhunter經常使用參數以及含義以下所示。
-c, –check必選參數,表示檢測當前系統 –configfile <file>使用特定的配置文件 –cronjob做爲cron任務按期運行 –sk, –skip-keypress自動完成全部檢測,跳過鍵盤輸入 –summary顯示檢測結果的統計信息 –update檢測更新內容 -V, –version顯示版本信息 –versioncheck檢測最新版本
3.下面是經過rkhunter對某個系統的檢測示例:
[root@server rkhunter-1.4.0]# /usr/local/bin/rkhunter -c [ Rootkit Hunter version 1.4.0 ] #下面是第一部分,先進行系統命令的檢查,主要是檢測系統的二進制文件,由於這些文件最容易被rootkit***。顯示OK字樣表示正常,顯示Warning表示有異常,須要引發注意,而顯示「Not found」字樣,通常無需理會 Checking system commands... Performing 'strings' command checks Checking 'strings' command [ OK ] Performing 'shared libraries' checks Checking for preloading variables [ None found ] Checking for preloaded libraries [ None found ] Checking LD_LIBRARY_PATH variable [ Not found ] Performing file properties checks Checking for prerequisites [ Warning ] /usr/local/bin/rkhunter [ OK ] /sbin/chkconfig [ OK ] ....(略).... [Press <ENTER> to continue] #下面是第二部分,主要檢測常見的rootkit程序,顯示「Not found」表示系統未感染此rootkit Checking for rootkits... Performing check of known rootkit files and directories 55808 Trojan - Variant A [ Not found ] ADM Worm [ Not found ] AjaKit Rootkit [ Not found ] Adore Rootkit [ Not found ] aPa Kit [ Not found ] Apache Worm [ Not found ] Ambient (ark) Rootkit [ Not found ] Balaur Rootkit [ Not found ] BeastKit Rootkit [ Not found ] beX2 Rootkit [ Not found ] BOBKit Rootkit [ Not found ] ....(略).... [Press <ENTER> to continue] #下面是第三部分,主要是一些特殊或附加的檢測,例如對rootkit文件或目錄檢測、對惡意軟件檢測以及對指定的內核模塊檢測 Performing additional rootkit checks Suckit Rookit additional checks [ OK ] Checking for possible rootkit files and directories [ None found ] Checking for possible rootkit strings [ None found ] Performing malware checks Checking running processes for suspicious files [ None found ] Checking for login backdoors [ None found ] Checking for suspicious directories [ None found ] Checking for sniffer log files [ None found ] Performing Linux specific checks Checking loaded kernel modules [ OK ] Checking kernel module names [ OK ] [Press <ENTER> to continue] #下面是第四部分,主要對網絡、系統端口、系統啓動文件、系統用戶和組配置、SSH配置、文件系統等進行檢測 Checking the network... Performing checks on the network ports Checking for backdoor ports [ None found ] Performing checks on the network interfaces Checking for promiscuous interfaces [ None found ] Checking the local host... Performing system boot checks Checking for local host name [ Found ] Checking for system startup files [ Found ] Checking system startup files for malware [ None found ] Performing group and account checks Checking for passwd file [ Found ] Checking for root equivalent (UID 0) accounts [ None found ] Checking for passwordless accounts [ None found ] ....(略).... [Press <ENTER> to continue] #下面是第五部分,主要是對應用程序版本進行檢測 Checking application versions... Checking version of GnuPG[ OK ] Checking version of OpenSSL [ Warning ] Checking version of OpenSSH [ OK ] #下面是最後一部分,這個部分實際上是上面輸出的一個總結,經過這個總結,能夠大概瞭解服務器目錄的安全狀態。 System checks summary ===================== File properties checks... Required commands check failed Files checked: 137 Suspect files: 4 Rootkit checks... Rootkits checked : 311 Possible rootkits: 0 Applications checks... Applications checked: 3 Suspect applications: 1 The system checks took: 6 minutes and 41 seconds
在Linux終端使用rkhunter來檢測,最大的好處在於每項的檢測結果都有不一樣的顏色顯示,若是是綠色的表示沒有問題,若是是紅色的,那就要引發關注了。另外,在上面執行檢測的過程當中,在每一個部分檢測完成後,須要以Enter鍵來繼續。若是要讓程序自動運行,能夠執行以下命令:
[root@server ~]# /usr/local/bin/rkhunter –check –skip-keypress
同時,若是想讓檢測程序天天定時運行,那麼能夠在/etc/crontab中加入以下內容:
30 09 * * * root /usr/local/bin/rkhunter –check –cronjob
這樣,rkhunter檢測程序就會在天天的9:30分運行一次。
4.安全更新:
今天剛剛爆出Bash安全漏洞,SSH bash緊急安全補丁!重要!
測試是否存在漏洞,執行如下命令: $ env x='() { :;}; echo vulnerable' bash -c "echo this is a test" vulnerable this is a test 若是顯示如上,那麼,很遺憾,必須當即打上安全補丁修復,
臨時解決辦法爲:
yum -y update bash 升級bash後,執行測試: $ env x='() { :;}; echo vulnerable' bash -c "echo this is a test" bash: warning: x: ignoring function definition attempt bash: error importing function definition for `x' this is a test 若是顯示如上,表示已經修補了漏洞。
5.解決思路:
若是您的系統通過 rkhunter 的檢測以後,卻發現不少的『紅字』時,該怎麼辦?很簡單, 能夠參考這個網頁提供的方法:
http://www.rootkit.nl/articles/rootkit_hunter_faq.html
基本上,官方網站與通常網管老手的建議都同樣,若是被 rootkit 之類的程序包***後 ( 也就是上一節的檢測表中的第二部分所***時 ),那麼最好最好直接從新安裝系統, 不要存在說能夠移除 rootkit 或者***程序的幻想,由於,『隱藏』原本就是 rootkit 與***程序的拿手好戲! 咱們不知道到底這個 rootkit 或者***程序有多剽悍,爲了保險起見,仍是重灌系統吧!如何重灌?簡單的說:
1.將原主機的網絡線拔除; 2.備份您的數據,最好備份成兩部分,一部份是所有的系統內容,越詳盡越好,包括 binary files 與 logfile 等等, 至於另外一部份則能夠考慮僅備份重要的數據文件便可! 3.將上個步驟的數據備份(僅重要數據部分!)進行總體的檢查,察看是否有怪異的數據存在(這部分可能會花去很多時間!) 4.從新安裝一部完整的系統,這包括: o僅安裝須要的套件在服務器上面; o先進行 簡單的防火牆 設定後才進行聯機; o以 APT/YUM 之類的工具進行在線更新; o執行相似 rkhunter/nessus 之類的軟件,檢驗系統是否處在較爲安全的狀態 5.將本來的重要數據移動至上個步驟安裝好的系統當中,並啓動本來服務器上面的各項服務; 6.以 rkhunter/nessus 之類的軟件檢驗系統是否處在較爲安全的環境,而且增強防火牆的機制! 7.最後,將本來完整備份的數據拿出來進行分析,尤爲是 logfile 部分,試圖找出 cracker 是藉由那個服務?那個時間點? 以那個遠程 IP 聯機進入本機等等的信息,並針對該信息研擬預防的方法,並應用在已經運做的機器上。 參考文章:http://blog.jobbole.com/77663/ http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=21868571&id=159026