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