最近朋友的一台服務器突然網絡異常,cpu占用率暴表,登錄上去一查,cpu占用300% 左右,流量異常,經過看查進程,獲取信息最終確認為中了dos木馬,經過幾天的研究,基本上已經清除,以下是清理記錄。
一、現象
1、CPU占用超高。
2、網絡流量異常。
3、對外ddos攻擊
4、服務器卡頓。
二、文件異常
1、系統主要命令文件被替換:
ps,netstat,lsof,ss命令被替換
chattr,lsattr文件被刪除。
1) top 可以看見一個隨機的文件名,占用資源較高
2) ps -ef 可以看見很多收集系統信息的命令,是木馬腳本自動執行的
3) 系統的chattr被刪除,無法修改文件的i屬性
1 ps 屬於 procps
2 ss 屬於 iproute
3 netstat 屬於 net-tools
4 使用yum重裝可恢復
5 yum -y reinstall procps lsof iproute net-tools
三、查殺過程
3.1 暫停木馬進程,主要不能kill掉
| 1 kill -9 木馬進程 |
不能殺完,殺掉以后自動生成,文件名隨機


3.2 刪除計划任務/etc/crontab下的異常計划任務
01 |
cat /etc/crontab |
02 |
SHELL=/bin/bash |
03 |
PATH=/sbin:/bin:/usr/sbin:/usr/bin |
04 |
MAILTO=root |
05 |
HOME=/ |
06 |
# run-parts |
07 |
01 * * * * root run-parts /etc/cron.hourly |
08 |
02 4 * * * root run-parts /etc/cron.daily |
09 |
22 4 * * 0 root run-parts /etc/cron.weekly |
10 |
42 4 1 * * root run-parts /etc/cron.monthly |
11 |
*/3 * * * * root /etc/cron.hourly/gcc4.sh #異常的 |
刪除/etc/crontab下面最后一行計划任務,然后再刪除/etc/cron.hourly下面的文件

gcc4.sh文件內容如上圖。
3.3 刪除如下目錄和文件
根據網上面的操作指引,刪除下面的文件,有些可能目錄不同。
01 |
rm -rf /usr/bin/dpkgd (ps netstat lsof ss) |
02 |
rm -rf /usr/bin/bsd-port (木馬程序) |
03 |
rm -f /usr/local/zabbix/sbin/zabbix_AgentD (木馬程序) |
04 |
rm -f /usr/local/zabbix/sbin/conf.n |
05 |
rm -f /usr/bin/.sshd |
06 |
rm -f /usr/bin/sshd |
07 |
rm -f /root/cmd.n |
08 |
rm -f /root/conf.n |
09 |
rm -f /root/IP |
10 |
rm -f /tmp/gates.lod |
11 |
rm -f /tmp/moni.lod |
12 |
rm -f /tmp/notify.file 程序 |
13 |
rm -f /tmp/gates.lock 進程號 |
14 |
rm -f /etc/rc.d/init.d/DbSecuritySpt(啟動上述描述的那些木馬變種程序) |
15 |
rm -f /etc/rc.d/rc1.d/S97DbSecuritySpt |
16 |
rm -f /etc/rc.d/rc2.d/S97DbSecuritySpt |
17 |
rm -f /etc/rc.d/rc3.d/S97DbSecuritySpt |
18 |
rm -f /etc/rc.d/rc4.d/S97DbSecuritySpt |
19 |
rm -f /etc/rc.d/rc5.d/S97DbSecuritySpt |
20 |
rm -f /etc/rc.d/init.d/selinux(默認是啟動/usr/bin/bsd-port/getty) |
21 |
rm -f /etc/rc.d/rc1.d/S99selinux |
22 |
rm -f /etc/rc.d/rc2.d/S99selinux |
23 |
rm -f /etc/rc.d/rc3.d/S99selinux |
24 |
rm -f /etc/rc.d/rc4.d/S99selinux |
25 |
rm -f /etc/rc.d/rc5.d/S99selinux |

如果無法刪除以上文件,可能是文件被附加了i屬性,使用chattr -i 去掉文件的i屬性,若chattr命令被木馬刪除,則從其他地方拷貝一個放在/usr/bin下。使用下面的命令也可以完成安裝。
1 |
yum install e2fsprogs #可以恢復chattr lsattr |
3.4 刪除服務里面的異常服務
1 |
chkconfig --list|grep :on |
2 |
chkconfig --del 異常服務名 |
3 |
cat /etc/rc.local #這里無異常 |

3.5 使用clamav進行病毒查殺
01 |
#安裝 |
02 |
yum install -y epel-release |
03 |
yum install -y clamav |
04 |
#更新病毒庫 |
05 |
freshclam |
06 |
#掃描方法 |
07 |
clamscan -r /etc --max-dir-recursion=5 -l /root/etcclamav.log |
08 |
clamscan -r /bin --max-dir-recursion=5 -l /root/binclamav.log |
09 |
clamscan -r /usr --max-dir-recursion=5 -l /root/usrclamav.log |
10 |
#掃描並殺毒 |
11 |
clamscan -r --remove /usr/bin/bsd-port |
12 |
clamscan -r --remove /usr/bin/ |
13 |
clamscan -r --remove /usr/local/zabbix/sbin |
14 |
#查看日志發現 |
15 |
cat /root/usrclamav.log |grep FOUND |
16 |
/usr/bin/ohhnzdjent: Unix.Trojan.DDoS_XOR-1 FOUND |
17 |
/usr/bin/oracle: Legacy.Trojan.Agent-1388639 FOUND |
18 |
/usr/bin/tgbtrjldlq: Unix.Trojan.DDoS_XOR-1 FOUND |
19 |
/usr/bin/wcwghpgruw: Unix.Trojan.DDoS_XOR-1 FOUND |

3.6 徹底查殺木馬
經過上面的查殺以后,基本上消滅了大部分的病毒文件,但是使用top,htop命令會發現,病毒會不斷的自動生成,相互守護,導致無法徹底殺完,經過多次的分析與嘗試,發現可能是/lib/libudev4.so文件導致的。
1) 嘗試破壞病毒文件
1 |
echo slkfhrl,kfhs > /lib/libudev4.so |
2 |
rm -f /lib/libudev4.so |
3 |
touch /lib/libudev4.so |
4 |
chattr +i /lib/libudev4.so |
2) 通過關聯文件清除服務里面的異常服務
1 |
grep -r scon.sh /etc/ |

寫一個腳本,批量清除異常服務
1 |
#! /bin/bash |
2 |
rm -f /etc/rc0.d/K90ohhnzdjent |
3 |
rm -f /etc/rc0.d/K90mpmhvgceym |
4 |
rm -f /etc/rc0.d/K90xcswyyarmo |
5 |
rm -f /etc/rc0.d/K90jjonjuuhvj |
6 |
rm -f /etc/rc0.d/K90smucwhghwq |
7 |
rm -f /etc/rc0.d/K90qfdmatbsmw |
8 |
rm -f /etc/rc0.d/K90vxlrotywez |
9 |
...... |
經過觀察,發現病毒進行已經成功清除。
參考URL:
http://www.freebuf.com/articles/system/119374.html
https://sebastianblade.com/linux-xorddos-trojan-removal/
http://www.2cto.com/article/201508/428264.html
http://www.myhack58.com/Article/48/66/2016/71075_2.htm
https://www.baidufe.com/item/e972015c88715fd8cd52.html
