1、安装chkrootkit
# apt-get update # apt install chkrootkit # chkrootkit -V chkrootkit version 0.52
#脚本定时任务 出现命令修改时自动发送邮件
#!/bin/bash
#-------------------------------------------------------------------------
#application: 检查linux是否被cc的工具,监控命令是否被替换
#Filename: chkrootkit_everyday.sh
#Revision: 0.1
#Date: 2018/12/03
#Author: hanye
#Email: [email protected]
#Website: hz7726.com
#Description:Check whether the site is rootkit infection
#Notes:
#crontab: */5 * * * * chkrootkit_everyday.sh
#------------------------------------------------------------------------
#Copyright:201 (c) www.1fangxin.cn
#License:GPL
TIME="`date +%Y%m%d%H%M`"
/usr/sbin/chkrootkit -n > /data/sh/.chkrootkitLog/.chkrootkit_$TIME.log
if [ "`grep 'INFECTED' /data/sh/.chkrootkitLog/.chkrootkit_$TIME.log`" != "" ];then
echo "Dangerous"
EMAIL='/data/soft/sendEmail-v1.56/sendEmail'
FEMAIL="[email protected]" #发件邮箱
MAILP="PASSWD"
MAILSMTP="smtp.163.com" #发件邮箱的SMTP
MAILT="[email protected],.......,...." #收件邮箱
MAILmessage=" server command change ERROR"
$EMAIL -q -f $FEMAIL -t $MAILT -u "您服务器有人登录修改命令,请使用chkrootkit来检测" -m "$MAILmessage" -s $MAILSMTP -o message-charset=utf-8 -xu $FEMAIL -xp $MAILP -o tls=no
else
echo "OK"
fi
2、使用chkrootkit
安装完的chkrootkit程序位于/usr/local/chkrootkit目录下,执行如下命令即可显示chkrootkit的详细用法:
root@fangxin-test# chkrootkit -h
chkrootkit各个参数的含义如下所示。
参数含义
-h显示帮助信息
-v显示版本信息
-l显示测试内容
-ddebug模式,显示检测过程的相关指令程序
-q安静模式,只显示有问题的内容
-x高级模式,显示所有检测结果
-r dir设置指定的目录为根目录
-p dir1:dir2:dirN指定chkrootkit检测时使用系统命令的目录
-n跳过NFS连接的目录