zoukankan      html  css  js  c++  java
  • linux系统被黑客入侵排查思路

    root@linux-szge:/var/spool/cron # cd tabs/
    total 8
    -rw-r--r-- 1 root root 3467 Feb 16 11:39 root
    -rw-r--r-- 1 root root 3467 Jan 17 10:58 xiaofei

    所有用户的计划任务,都会在这个目录下产生对应的文件

    黑客:通过crontab , 篡改一个系统级别的计划任务

    root@linux-szge:/var/spool/cron/tabs # ls /etc/cron
    cron.d/       cron.daily/   cron.deny     cron.hourly/  cron.monthly/ cron.weekly/  crontab    
    

    注:

    cron.d  系统级别的定时任务

    cron.daily  系统每天要执行的计划任务

    cron.hourly 系统每小时要执行的计划任务

    cron.monthly 系统每月要执行的计划任务

    cron.weekly   系统每周要执行的计划任务

    测试:

    [root@linux-szge ~]# vim /etc/cron.daily/tmpwatch 
    #! /bin/sh
    flags=-umc
    /usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix 
            -x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix 
            -X '/tmp/hsperfdata_*' -X '/tmp/.hdb*lock' -X '/tmp/.sapstartsrv*.log' 
            -X '/tmp/pymp-*' 10d /tmp
    /usr/sbin/tmpwatch "$flags" 30d /var/tmp
    for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
        if [ -d "$d" ]; then
            /usr/sbin/tmpwatch "$flags" -f 30d "$d"
        fi
    done
    echo test  #添加一行
    [root@linux-szge ~]# /etc/cron.daily/tmpwatch 
    test

    注:说明添加木马成功了

    排查篡改木马的方式:

    使用md5值去排查  (通过对比md5值去判断文件是否修改)

                                     修改前    
    [root@linux-szge ~]# md5sum /etc/cron.daily/tmpwatch 
    5dcd732b139638ed23a0e6dd7ca7a784  /etc/cron.daily/tmpwatch            
                                      修改后
    [root@linux-szge ~]# md5sum /etc/cron.daily/tmpwatch 
    5acb09733d49c4befaf0b0ef382eed67  /etc/cron.daily/tmpwatch

    对/etc/cron*下所有文件都生成md5值,记录到/usr/share/file_md5.v1文件中,方便发现问题时去对比

    [root@linux-szge ~]# find /etc/cron* -type f -exec md5sum {} ; > /usr/share/file_md5.v1
    
    
    [root@linux-szge ~]# cat /usr/share/file_md5.v1
    367636170f3ac44df6a117e3cbf7e4ba  /etc/cron.d/raid-check
    4b98b6b029e76aa6e0fa3fde2ec5572a  /etc/cron.d/0hourly
    b904bdae184e1d37d52b04dd28bd4ea6  /etc/cron.d/sysstat
    5acb09733d49c4befaf0b0ef382eed67  /etc/cron.daily/tmpwatch
    723dc41aa3e09723762b7d6c5966414b  /etc/cron.daily/mlocate.cron
    55735e2ab5f2052f7e885bca1230332e  /etc/cron.daily/logrotate
    54d753840882c7ec71313fe6bfba1225  /etc/cron.daily/cups
    d05fe6bf89faa69ffc11a8aab2519f15  /etc/cron.daily/readahead.cron
    de7d9c2df94e20af5aa401e708c3119d  /etc/cron.daily/prelink
    79937e0e1cb83fad092c4f8252827225  /etc/cron.daily/makewhatis.cron
    d41d8cd98f00b204e9800998ecf8427e  /etc/cron.deny
    0033096afd5c735bc99821f847bd61a2  /etc/cron.hourly/0anacron
    2b843bf5238314a659b51ea6061ca611  /etc/cron.monthly/readahead-monthly.cron
    4f2aaa54c48dda350f75da151f79ae57  /etc/crontab
    

    对比方式(当感觉出现问题时,记录新的md5值到/usr/share/file_md5.v2文件中):

    #! /bin/sh
    flags=-umc
    /usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix 
            -x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix 
            -X '/tmp/hsperfdata_*' -X '/tmp/.hdb*lock' -X '/tmp/.sapstartsrv*.log' 
            -X '/tmp/pymp-*' 10d /tmp
    /usr/sbin/tmpwatch "$flags" 30d /var/tmp
    for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
        if [ -d "$d" ]; then
            /usr/sbin/tmpwatch "$flags" -f 30d "$d"
        fi
    done
    echo test
    echo test2  #再次修改文件,方便对比效果
    ~       
    [root@linux-szge ~]# /etc/cron.daily/tmpwatch                                              
    test
    test2
    [root@linux-szge ~]# md5sum /etc/cron.daily/tmpwatch                                       
    36abcd1a234e1c50185734627bd6e1b5  /etc/cron.daily/tmpwatch

    开始对比,可以发现md5值发生变化

    [root@linux-szge ~]# find /etc/cron* -type f -exec md5sum {} ; > /usr/share/file_md5.v2  #新的md5记录到文件
    [root@linux-szge ~]# diff /usr/share/file_md5.v1 /usr/share/file_md5.v2
    4c4
    < 5acb09733d49c4befaf0b0ef382eed67  /etc/cron.daily/tmpwatch
    ---
    > 36abcd1a234e1c50185734627bd6e1b5  /etc/cron.daily/tmpwatch

    查看开机启动进程:

    /etc/rc.local  这个是开机启动脚本

    [root@linux-szge ~]# vim /etc/rc.local 
    
    
    #!/bin/sh
    #
    # This script will be executed *after* all the other init scripts.
    # You can put your own initialization stuff in here if you don't
    # want to do the full Sys V style init stuff.
    
    touch /var/lock/subsys/local
    echo tt   #插入这个内容

    排查方式:(有些黑客会在文件中打出很多空行以至于你看不出来黑客所添加的内容)

    那么我们怎么去排查呢?(使用grep)

    [root@linux-szge ~]# grep -v ^$ /etc/rc.local 
    #!/bin/sh
    #
    # This script will be executed *after* all the other init scripts.
    # You can put your own initialization stuff in here if you don't
    # want to do the full Sys V style init stuff.
    touch /var/lock/subsys/local
    echo tt

    利用开机启动的服务器脚本来加载木马程序,把木马程序脚本写到已经存在的开机启动服务中。例如:http(apache web 服务器启动脚本等)

    [root@linux-szge ~]# cp /etc/init.d/network /etc/init.d/test
    [root@linux-szge ~]# vim !$
    #! /bin/bash
    #
    # network       Bring up/down networking
    #
    # chkconfig: 2345 10 90
    # description: Activates/Deactivates all network interfaces configured to 
    #              start at boot time.
    #
    ### BEGIN INIT INFO
    # Provides: $network
    # Should-Start: iptables ip6tables
    # Short-Description: Bring up/down networking
    # Description: Bring up/down networking
    ### END INIT INFO
    # Source function library.
    
    touch /tmp/txt   #删除原来脚本内容,写成自己的木马程序

    排查方法

    方法1:对比其他服务器的配置文件,利用MD5值进行对比

    方法2:查看被黑当天生成或修改的文件

    查看被前一天到现在修改的文件
    [root@linux-szge ~]# find /etc/cron.daily/* -mtime -1
    /etc/cron.daily/tmpwatch

    方法3:使用rpm检查文件完整性

    语法:rpm -V 软件包的名字 #使用rpm检查这个软件包所生成的文件的完整性

    语法:rpm -Vf 命令的绝对路径 #使用rpm检查命令的完整性

  • 相关阅读:
    npm install 卡住的时候的处理
    建立ionic3的环境
    [转] PuTTY + Xming 远程使用 Linux GUI
    Oracle 11g 记录DML错误数据
    [转] 深入浅出 妙用Javascript中apply、call、bind
    [转] Java运行时动态生成class的方法
    获取Java class或者jar文件的本地路径
    AngularJS 中ng-model通过$watch动态取值
    [转] Everything about custom filters in AngularJS
    [转] 利用js实现 禁用浏览器后退
  • 原文地址:https://www.cnblogs.com/shenjianyu/p/6409316.html
Copyright © 2011-2022 走看看