1、rootkit簡介html
rootkit是Linux平臺下最多見的一種木馬後門工具,它主要經過替換系統文件來達到入侵和和隱蔽的目的,這種木馬比普通木馬後門更加危險和隱蔽,普通的檢測工具和檢查手段很難發現這種木馬。rootkit攻擊能力極強,對系統的危害很大,它經過一套工具來創建後門和隱藏行跡,從而讓攻擊者保住權限,以使它在任什麼時候候均可以使用root權限登陸到系統。c++
rootkit主要有兩種類型:文件級別和內核級別,下面分別進行簡單介紹。安全
一、文件級別rootkitbash
文件級別的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已經在系統中運行了。服務器
這就是文件級別的rootkit,對系統維護很大,目前最有效的防護方法是按期對系統重要文件的完整性進行檢查,若是發現文件被修改或者被替換,那麼極可能系統已經遭受了rootkit入侵。檢查件完整性的工具不少,常見的有Tripwire、 aide等,能夠經過這些工具按期檢查文件系統的完整性,以檢測系統是否被rootkit入侵。網絡
二、內核級別的rootkitapp
內核級rootkit是比文件級rootkit更高級的一種入侵方式,它可使攻擊者得到對系統底層的徹底控制權,此時攻擊者能夠修改系統內核,進而截獲運行程序向內核提交的命令,並將其重定向到入侵者所選擇的程序並運行此程序,也就是說,當用戶要運行程序A時,被入侵者修改過的內核會僞裝執行A程序,而實際上卻執行了程序B。less
內核級rootkit主要依附在內核上,它並不對系統文件作任何修改,所以通常的檢測工具很難檢測到它的存在,這樣一旦系統內核被植入rootkit,攻擊者就能夠對系統隨心所欲而不被發現。目前對於內核級的rootkit尚未很好的防護工具,所以,作好系統安全防範就很是重要,將系統維持在最小權限內工做,只要攻擊者不能獲取root權限,就沒法在內核中植入rootkit。ssh
2、rootkit後門檢測工具chkrootkittcp
chkrootkit是一個Linux系統下查找並檢測rootkit後門的工具,它的官方址: http://www.chkrootkit.org/。 chkrootkit沒有包含在官方的CentOS源中,所以要採起手動編譯的方法來安裝,不過這種安裝方法也更加安全。下面簡單介紹下chkrootkit的安裝過程。
1.準備gcc編譯環境
對於CentOS系統,須要安裝gcc編譯環境,執行下述三條命令:
1
2
3
|
[root@server ~]# yum -y install gcc
[root@server ~]# yum -y install gcc-c++
[root@server ~]# yum -y install make
|
二、安裝chkrootkit
爲了安全起見,建議直接從官方網站下載chkrootkit源碼,而後進行安裝,操做以下:
1
2
3
|
[root@server ~]# tar zxvf chkrootkit.tar.gz
[root@server ~]# cd chkrootkit-*
[root@server ~]# make sense
|
# 注意,上面的編譯命令爲make sense
1
2
3
|
[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
chkrootkit各個參數的含義以下所示。
參數含義
-h顯示幫助信息
-v顯示版本信息
-l顯示測試內容
-ddebug模式,顯示檢測過程的相關指令程序
-q安靜模式,只顯示有問題的內容
-x高級模式,顯示全部檢測結果
-r dir設置指定的目錄爲根目錄
-p dir1:dir2:dirN指定chkrootkit檢測時使用系統命令的目錄
-n跳過NFS鏈接的目錄
chkrootkit的使用比較簡單,直接執行chkrootkit命令便可自動開始檢測系統。下面是某個系統的檢測結果:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[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進行檢測。這個過程能夠經過下面的操做實現:
1
2
3
4
5
6
|
[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能夠做的事情有:
MD5校驗測試,檢測文件是否有改動
檢測rootkit使用的二進制和系統工具文件
檢測特洛伊木馬程序的特徵碼
檢測經常使用程序的文件屬性是否異常
檢測系統相關的測試
檢測隱藏文件
檢測可疑的核心模塊LKM
檢測系統已啓動的監聽端口
下面詳細講述下RKHunter的安裝與使用。
一、安裝RKHunter (也能夠經過epel源,使用yum install rkhunter -y 進行安裝)
RKHunter的官方網頁地址爲:http://www.rootkit.nl/projects/rootkit_hunter.html,建議從這個網站下載RKHunter,這裏下載的版本是rkhunter-1.4.0.tar.gz。RKHunter的安裝很是簡單,過程以下:
1
2
3
4
5
6
7
|
[root@server ~]# ls
rkhunter-
1.4
.
0
.tar.gz
[root@server ~]# pwd
/root
[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
Rkhunter經常使用參數以及含義以下所示。
參數 含義
-c, –check必選參數,表示檢測當前系統
–configfile <file>使用特定的配置文件
–cronjob做爲cron任務按期運行
–sk, –skip-keypress自動完成全部檢測,跳過鍵盤輸入
–summary顯示檢測結果的統計信息
–update檢測更新內容
-V, –version顯示版本信息
–versioncheck檢測最新版本
下面是經過rkhunter對某個系統的檢測示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
[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
var
iables [ None found ]
Checking
for
preloaded libraries [ None found ]
Checking LD_LIBRARY_PATH
var
iable [ 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中加入以下內容:
08 3 * * * root /usr/local/bin/rkhunter --check –-cronjob
這樣,rkhunter檢測程序就會在天天的3:08分運行一次。
安全更新:
最近爆出Bash安全漏洞,SSH bash緊急安全補丁!重要!
測試是否存在漏洞,執行如下命令:
1
2
3
|
$ env x=
'() { :;}; echo vulnerable'
bash -c
"echo this is a test"
vulnerable
this
is
a test
|
若是顯示如上,那麼,很遺憾,必須當即打上安全補丁修復,
臨時解決辦法爲:
1
|
yum -y update bash
|
升級bash後,執行測試:
1
2
3
4
|
$ 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
|
若是顯示如上,表示已經修補了漏洞。