Linux后门入侵检测

rootkit

简介

  • Linux平台下的最常见的木马后门工具
  • 主要行为:替换系统文件,比如替换常用命令ls,一旦执行就等于在运行木马
  • 种类:文件级别、内核级别

文件级别

  • 通过修改或者替换系统的重要文件来隐藏自己
  • 合法文件被木马程序替代,变成了外壳程序,内部隐藏了后门程序
  • 通常易被替换的系统程序:login、ls、ps、ifconifg、du、find、netstat、cd

内核级别

  • 攻击者可以获得对系统底层的完全控制权
  • 攻击者可以修改系统内核,进而截获运行程序向内核提交的命令,并将其重定向到入侵者所选定的程序运行此程序
  • 主要依附于内核上,一般不对系统文件做修改

防范

  • 只从官网下载软件
  • 不信任网络共享文件
  • 程序运行在最小权限下
  • 定期使用工具检测

检测工具

  • chkrootkit
  • RKHunter

chkrootkit

编译环境

sudo yum install gcc gcc-c++ make glibc-static -y

安装chkrootkit

git clone https://github.com/Magentron/chkrootkit.git
cd chkrootkit
make sense

使用chkrootkit

[root@vm chkrootkit]# ./chkrootkit -h
Usage: ./chkrootkit [options] [test ...]
Options:
        -h                显示帮助信息
        -V                显示版本
        -l                显示测试内容
        -d                debug模式
        -q                静默模式,只显示有问题内容
        -x                高级模式,显示所有检测结果
        -r dir            设置制定目录为根目录
        -p dir1:dir2:dirN 指定检测时使用系统命令的目录
        -n                跳过NFS连接的目录
        
[root@vm chkrootkit]# ./chkrootkit  -q
# 带有INFECTED标识的为已感染项
# 也可以通过grep过滤感染项
[root@vm chkrootkit]# ./chkrootkit | grep INFECTED

chkrootkit不足

  • chkrootkit检查时使用了部分系统命令,如果依赖的部分命令已经被替换,那么检测出的结果就不可信
  • 需要在安装完系统初始,备份chkrootkit依赖的系统命令文件
[root@vm chkrootkit]# mkdir .commands
# 拷贝依赖的系统命令文件到.commands
[root@vm chkrootkit]# cp `which --skip-alias awk cut echo find egrep id head ls netstat ps strings sed uname` .commands/
[root@vm chkrootkit]# ls .commands/
awk  cut  echo  egrep  find  head  id  ls  netstat  ps  sed  strings  uname
# 打包系统文件,备份到安全的地方
[root@vm chkrootkit]# tar zcvf commands.tar.gz .commands/
.commands/
.commands/awk
.commands/cut
.commands/echo
.commands/find
.commands/egrep
.commands/id
.commands/head
.commands/ls
.commands/netstat
.commands/ps
.commands/strings
.commands/sed
.commands/uname

# 使用备份命令检测
[root@vm chkrootkit]# ./chkrootkit -p ./.commands/

RKHunter

简介

  • RKHunter是专业检测系统rootkit的工具
  • MD5校验测试
  • 检测rootkit使用的二进制核系统工具文件
  • 检测特洛伊木马程序的特征码
  • 检测常用程序的文件属性是否异常
  • 检测系统相关的测试
  • 检测隐藏文件
  • 检测可疑的核心模块LKM
  • 检测系统已启用的监听端口

安装

# 下载安装包
[root@vm ~] wget https://jaist.dl.sourceforge.net/project/rkhunter/rkhunter/1.4.6/rkhunter-1.4.6.tar.gz
# 解压
[root@vm ~] tar xvf rkhunter-1.4.6.tar.gz
# 安装
[root@vm rkhunter-1.4.6] cd rkhunter-1.4.6/
[root@vm rkhunter-1.4.6] ./installer.sh --install
Checking system for:
 Rootkit Hunter installer files: found
 A web file download command: wget found
Starting installation:
 Checking installation directory "/usr/local": it exists and is writable.
 Checking installation directories:
  Directory /usr/local/share/doc/rkhunter-1.4.6: creating: OK
  Directory /usr/local/share/man/man8: exists and is writable.
  Directory /etc: exists and is writable.
  Directory /usr/local/bin: exists and is writable.
  Directory /usr/local/lib64: exists and is writable.
  Directory /var/lib: exists and is writable.
  Directory /usr/local/lib64/rkhunter/scripts: creating: OK
  Directory /var/lib/rkhunter/db: creating: OK
  Directory /var/lib/rkhunter/tmp: creating: OK
  Directory /var/lib/rkhunter/db/i18n: creating: OK
  Directory /var/lib/rkhunter/db/signatures: creating: OK
 Installing check_modules.pl: OK
 Installing filehashsha.pl: OK
 Installing stat.pl: OK
 Installing readlink.sh: OK
 Installing backdoorports.dat: OK
 Installing mirrors.dat: OK
 Installing programs_bad.dat: OK
 Installing suspscan.dat: OK
 Installing rkhunter.8: OK
 Installing ACKNOWLEDGMENTS: OK
 Installing CHANGELOG: OK
 Installing FAQ: OK
 Installing LICENSE: OK
 Installing README: OK
 Installing language support files: OK
 Installing ClamAV signatures: OK
 Installing rkhunter: OK
 Installing rkhunter.conf: OK
Installation complete
# 默认安装到/usr/local/bin下
[root@vm ~]# which rkhunter
/usr/local/bin/rkhunter

使用

# 常用命令含义
-c		检测当前系统
--configfile		使用特定的配置文件
--cronjob		作为cron任务定期运行
--sk		自动完成所有检测,跳过键盘输入
--summary		显示检测结果的统计信息
--update		检测更新的内容
-V		显示版本信息
--versioncheck		检测最新版本

# 全面检查
[root@vm ~]# rkhunter --checkall --sk

posted @ 2022-03-02 20:43  longtds  阅读(263)  评论(0编辑  收藏  举报