linux后门排查

配置文件排查:

  文件属性:stat /etc/rc.local

  文件配置:cat /etc/fstab

  文件内容:grep -V '#' /etc/bashrc | more

  文件目录:ls -last /etc/profile.d/

cron后门排查:

  配置文件目录:

    /etc/cron.d/

    /var/spool/cron/

  配置文件:

    /etc/crontab

    /etc/anacrontab

  win换行符:

    ^M = ctrl+v -> ctrl+m

    sed -i 's/^M//g' /var/spool/cron/root

setuid后门排查:

  根据文件权限来查找指定文件

    find / -perm -4000 2>/dev/null

    find / -perm -u=s -type f 2>/dev/null

    find / -perm -4000 -o -perm -2000 2>dev/null | xargs ls -lh

ssh后门排查

  rpm包完整性校验

    rpm -Vf 'type sshd' 'type ssh'

    S = 大小 / M = 权限 / 5=MD5 / T=时间 / L=链接

  获取sshd进程pid并跟踪系统调用

    strace -o out.txt -ff -p pid

  获取ssh进程pid传给strace进行监控

    ps -ef | grep -vE 'sshd|grep' | grep ssh | awk '{print $2}' |xargs

    strace -o out.txt -f -p 2>&1

  通过文件操作特征跟踪后门

    grep open out.txt* | grep -e APPEND

pam后门排查:

  pam配置文件检查

    stat /etc/pam.d/sshd

    cat /etc/pam.d/sshd

  so文件加载排查

    ps -ef |grep sshd |grep pts

    pmap pid |grep security

  sshd进程操作跟踪

    strace -o out -ff -p pid

    cat out* |grep APPEND

ssh公钥排查

  公钥文件配置

    grep AuthorizedKeysFile /etc/ssh/sshd_config

  公钥文件搜索

    find / -name authorized_keys

  文件属性及内容

    stat authorized_keys

预加载后门排查

  系统环境变量检查

    echo $LD_PRELOAD

    unset LD_PRELOAD

  绕过后门hook隐藏

    ./busybox cat /etc/ld.so.preload

  跟踪文件系统调用

    ./strace -f -e trace=file /bin/cat

    acess("/etc/ld.so.preload", R_OK)

  后门配置文件清理

    lsattr /etc/ld.so.preload

    echo > /etc/ld.so.preload  

strace后门排查

  系统进程筛查

    进程名称、命令参数

  strace跟踪

    strace -o out.txt -ff -p pid

    调用内核ptrace特性来实现功能

  alias命令排查

module后门排查

  中间件配置排查

    控制器及模块加载配置

  模块文件排查

    文件修改时间排序

    strings evil.so |grep -e exec

  已加载模块确认

    pamp -q pid |grep auth

内核后门排查

  驱动加载

    lsmod / modinfo / modprobe -l

    cat /proc/modules

  网络层排查

    正向: nmap -sV -PN -T4 -p-

    反向:tcpdump -i eth0 src host hostname -w send.cap

  系统文件排查

    linux PE / LiveCD (Porteus)

    fdisk -l /mount /dev/mapper/VolGroup

常见目录:

  驻留文件及目录

    /etc/crontab、/etc/init.d、/etc/rc.local

  隐藏文件及目录

    /tmp/.evil、/tmp/ ./

  可写可执行权限

    /tmp、/var/tmp、/dev/shm  

常用工具:

  Rookit检测

    chkrootkit、rkhunter

    基于特征检测的脚本文件

  静态编译工具

    busybox-i686

    busybox-x86_64

  LiveCD

    系统急救恢复、后门分析取证

  Tripwire

    监控和告警任意系统文件的更改(IDS)

排查工具使用

1.rkhunter

安装

wget http://nchc.dl.sourceforge.net/project/rkhunter/rkhunter/1.4.0/rkhunter-1.4.0.tar.gz

tar -zxvf rkhunter-1.4.0.tar.gz
cd rkhunter-1.4.0
./installer.sh --install

./rkhunter --update

成功安装后, 你可以通过运行下面命令来检测你的机器是否已感染rootkit(在这个目录运行 cd /usr/local/bin)

rkhunter -c 

或者

rkhunter -c --sk --rwo  --vl --verbose-logging

有问题会红色的Warning 提示。

rkhunter参数说明
#/usr/local/bin/rkhunter
Usage: rkhunter {--check | --update | --versioncheck |
                 --propupd [{filename | directory | package name},...] |
                 --list [{tests | {lang | languages} | rootkits},...] |
                 --version | --help} [options]

Current options are:
         --append-log                  在日志文件后追加日志,而不覆盖原有日志
         --bindir <directory>...       Use the specified command directories
     -c, --check                       检测当前系统
--cs2, --color-set2                  Use the second color set for output
         --configfile <file>           使用特定的配置文件
         --cronjob                     作为cron定期运行
                                       (包含参数 -c, --sk , --nocolors )
         --dbdir <directory>           Use the specified database directory
         --debug                       Debug模式(不要使用除非要求使用)
         --disable <test>[,<test>...] 跳过指定检查对象(默认为无)
         --display-logfile             在最后显示日志文件内容
         --enable <test>[,<test>...] 对指定检测对象进行检查(默认检测所有对象)
         --hash {MD5 | SHA1 | NONE |   使用指定的文件哈希函数
                 <command>}            (Default is SHA1)
     -h, --help                        显示帮助菜单
--lang, --language <language>         指定使用的语言(默认是英文)
         --list [tests | languages |   罗列测试对象明朝,使用语言,可检测的木马程序
                 rootkits]            
     -l, --logfile [file]              写到指定的日志文件名 (Default is /var/log/rkhunter.log)
         --noappend-log                不追加日志,直接覆盖日志文件
         --nocolors                    输出只显示黑白两色
         --nolog                       不写入日志文件
--nomow, --no-mail-on-warning          如果有警告信息,不发送邮件
   --ns, --nosummary                   不显示检查结果的统计数据
--novl, --no-verbose-logging          不显示详细记录
         --pkgmgr {RPM | DPKG | BSD | 使用特定的包管理用于文件的哈希值验证
                   NONE}               (Default is NONE)
         --propupd [file | directory | 更新整个文件属性数据库或仅仅更新指定条目
                    package]...       
     -q, --quiet                       安静模式(no output at all)
--rwo, --report-warnings-only        只显示警告信息
     -r, --rootdir <directory>         使用指定的root目录
   --sk, --skip-keypress               自动完成所有检测,跳过键盘输入
         --summary                     显示检测结果的统计信息 (This is the default)
         --syslog [facility.priority] 记录检测启动和结束时间到系统日志中 (Default level is authpriv.notice)
         --tmpdir <directory>          使用指定的临时目录
         --update                      检测更新内容
   --vl, --verbose-logging             使用详细日志记录 (on by default)
     -V, --version                     显示版本信息
         --versioncheck                检测最新版本
     -x, --autox                       当X在使用时,自动启动检测
     -X, --no-autox                    当X在使用时,不自启检测


2、chkrootkit

#wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz

#tar -zxvf chkrootkit.tar.gz

#cd chkrootkit-0.48

#make sense

#./chkrootkit -n -q

有问题会报INFECTED,没问题就是NOT INFECTED,呵呵~

chkrootkit参数说明

Usage: ./chkrootkit [options] [test ...]
Options:
        -h                 显示帮助信息
        -V                 显示版本信息
        -l                 显示测试内容
        -d                debug模式,显示检测过程的相关指令程序
        -q                 安静模式,只显示有问题部分,
        -x                 高级模式,显示所有检测结果
        -r dir             设定指定的目录为根目录
        -p dir1:dir2:dirN 检测指定目录
        -n                跳过NFS连接的目录

看图的话可以参考<简单chkrootkit使用>



posted @ 2022-01-14 22:50  Sakimir  阅读(634)  评论(0)    收藏  举报