第一次遇到如此难搞的病毒木马-bash。

# cat /etc/redhat-release 
CentOS release 6.7 (Final)
# ssh -V
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013

进程和文件清除后,总是会自动起来,然后占用50%的CPU

netstat-ano|more

 

处理思路:

* top查看cpu进程最高的
* 然后lsof -p 进程号,确认是否有可疑关联请求
* 检查crontab
-l确认是否有异常定时任务,并进入/var/spool/cron下确认查看,同时查看/var/log/cron日志,检查所有/etc/cron*的任务
* 检查密码文件/etc/passwd查看是否有异常用户和组
* 检查网络ip是否有异常连接netstat -ano|more
用到的命令:

netstat -ano

find / -name bash

sar 1 10

top

ps -ef|grep curl

lsof -p 进程号 ,可以看关联了哪些进程及和那里通信,这里看到会去请求这个外部地址:

vps-57ca5d6a.vps.ovh.net

 

查看crontab –l没有发现任何脚本。尝试进入cron目录:

发现存在/var/spool/cron/x这个名字的任务,

# find / -name *.x86_64*
/sbin/.x86_64
/sbin/.ssh/.x86_64

[root@test bin]# rm -f crondr
rm: 无法删除"crondr": 不允许的操作
[root@test bin]# chattr -sia /bin/crondr
[root@test bin]# chattr -sia /bin/bprofr
[root@test bin]# rm -f /bin/crondr
[root@test bin]# rm -f /bin/bprofr
[root@test bin]# pwd
/bin
[root@test bin]# cd /sbin
[root@test sbin]# ls -lt|head
总用量 21252
-rwxr-xr-x. 1 root root  188636 5月  10 02:41 binitd
-rwxr-xr-x. 1 root root  188636 5月  10 02:41 bcrond
-rwxr-xr-x. 1 root root 2556332 5月  10 02:39 minitd
-rwxr-xr-x. 1 root root 2556332 5月  10 02:39 mcrond
lrwxrwxrwx. 1 root root       7 12月  7 2018 quotaoff -> quotaon
lrwxrwxrwx. 1 root root       3 12月  7 2018 vgscan -> lvm
lrwxrwxrwx. 1 root root       3 12月  7 2018 vgsplit -> lvm
lrwxrwxrwx. 1 root root       3 12月  7 2018 vgmerge -> lvm
lrwxrwxrwx. 1 root root       3 12月  7 2018 vgmknodes -> lvm
[root@test sbin]# chattr -sia /bin/binitd
chattr: 没有那个文件或目录 当尝试对/bin/binitd进行stat调用时
[root@test sbin]# ls -lt|head
总用量 21252
-rwxr-xr-x. 1 root root  188636 5月  10 02:41 binitd
-rwxr-xr-x. 1 root root  188636 5月  10 02:41 bcrond
-rwxr-xr-x. 1 root root 2556332 5月  10 02:39 minitd
-rwxr-xr-x. 1 root root 2556332 5月  10 02:39 mcrond
lrwxrwxrwx. 1 root root       7 12月  7 2018 quotaoff -> quotaon
lrwxrwxrwx. 1 root root       3 12月  7 2018 vgscan -> lvm
lrwxrwxrwx. 1 root root       3 12月  7 2018 vgsplit -> lvm
lrwxrwxrwx. 1 root root       3 12月  7 2018 vgmerge -> lvm
lrwxrwxrwx. 1 root root       3 12月  7 2018 vgmknodes -> lvm
[root@test sbin]# rm -f binitd
rm: 无法删除"binitd": 不允许的操作
[root@test sbin]# chattr -sia /sbin/binitd
[root@test sbin]# chattr -sia /sbin/bcrond
[root@test sbin]# chattr -sia /sbin/minitd
[root@test sbin]# chattr -sia /sbin/mcrond
[root@test sbin]# rm -f binitd
[root@test sbin]# rm -f bcrond
[root@test sbin]# rm -f minitd
[root@test sbin]# rm -f mcrond
[root@test sbin]# ls -lt|head

竟然在crontab看不到,被隐藏了。

根据x中内容再去查看关联了哪些目录和文件,深入查看。最后逐个删除掉。

 

需要删掉用户x/组/家目录/x

/var/tmp下的文件

/tmp下的文件

想办法彻底清除。

但由于/var/tmp

/tmp

/etc下很多文件无法删除,导致木马进程总是会被唤起,去连接外部网络。

rm -rf报错如下:

mv curl curl.bak去掉这个下载的命令

所以尝试添加/etc/hosts如下内容,骗过木马。

127.0.0.1       pw.pwndns.pw           

127.0.0.1       vps-57ca5d6a.vps.ovh.net

加上上述内容后,kill进程,-bash没再起来,cpu一直保存正常。

另外也可以考虑在防火墙禁止源地址请求上述ip。后续需升级加固openssh以及不暴露在公网。

iptables -I INPUT -s 185.45.192.135 -j DROP
iptables -I INPUT -s 208.95.112.1 -j DROP
iptables -I INPUT -s 66.171.248.178 -j DROP
iptables -I INPUT -s 172.67.153.85 -j DROP
iptables -I INPUT -s 104.27.149.211 -j DROP
iptables -I INPUT -s 104.27.148.211 -j DROP
iptables -I INPUT -s 51.210.15.231 -j DROP

/etc/rc.d/init.d/iptables save 

 

每分钟删除可能启动的木马:木马-bash的父进程ID总是1 

[root@test ~]# crontab -l
* * * * * /root/k.sh #彻底清除后可以取消这个任务
[root@test ~]# cat /root/k.sh
ps -ef|grep bash|grep "   1"|grep -v grep|awk '{print $2}'|xargs kill -9

目前做过的操作:
1.防火墙阻止已知所有木马IP
2.删除所有木马文件
3.删除木马用户和定时任务
4.清除木马进程
5.取消该主机的dns解析(这个后续看情况可打开)

加固建议:
1.外网远程22连接使用白名单或关闭外网直接连接22(只允许vpn/内网连接)
2.升级openssh
3.其它

遗留小问题,那些改不了权限的文件和目录只能在单用户下试试能不能删除之类???还得研究下....

这种dr--r--r--的权限怎么搞???root无权限删除和修改操作。

cd /tmp/

cd /var/tmp

技术
今日推荐
PPT
阅读数 121
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信