linux如何清理病毒文件夹,Linux 服务器中木马病毒及清除过程

一、背景

晚上看到有台服务器流量跑的很高,明显和平常不一样,流量达到了800Mbps,第一感觉应该是中木马了,被人当做肉鸡了,在大量发包。

我们的服务器为了最好性能,防火墙(iptables)什么的都没有开启,但是服务器前面有物理防火墙,而且机器都是做的端口映射,也不是常见的端口,按理来说应该是满安全的,可能最近和木马有缘吧,老是让我遇到,也趁这次机会把发现过程记录一下。

二、发现并追踪处理

1、查看流量图发现问题

查看的时候网页非常卡,有的时候甚至没有响应

3ce9bc4d83f9c27a30d0526108894cf6.png

2、top动态查看进程

我马上远程登录出问题的服务器,远程操作很卡,网卡出去的流量非常大,通过top发现了一个异常的进程占用资源比较高,名字不仔细看还真以为是一个Web服务进程。

da8f765f28c9a9c988b8b89ae4ae7420.png

4、结束异常进程并继续追踪

killall -9 nginx1

rm -f /etc/nginx1

干掉进程之后,流量立刻下来了,远程也不卡顿了,难道删掉程序文件,干掉异常进程我们就认为处理完成了么?想想也肯定没那么简单的,这个是木马啊,肯定还会自己生成程序文件(果然不出我所料,在我没有搞清楚之前,后面确实又生成了)我们得继续追查。

5、查看登录记录及日志文件secure

通过命令last查看账户登录记录,一切正常。查看系统文件message并没有发现什么,但是当我查看secure文件的时候发现有些异常,反正是和认证有关的,应该是尝试连进来控制发包?

4bde5f10dd917f1aec6e39344a7d699c.png

7、更多异常文件的发现

查看定时任务文件crontab并没有发现什么一次,然后查看系统启动文件rc.local,也没有什么异常,然后进入/etc/init.d目录查看,发现比较奇怪的脚本文件DbSecuritySpt、selinux。

df5e156b75ce0a09b2bd9e008846f811.png

三、木马手动清除

现在综合总结了大概步骤如下:

1、简单判断有无木马

#有无下列文件

cat /etc/rc.d/init.d/selinux

cat /etc/rc.d/init.d/DbSecuritySpt

ls /usr/bin/bsd-port

ls /usr/bin/dpkgd

#查看大小是否正常

ls -lh /bin/netstat

ls -lh /bin/ps

ls -lh /usr/sbin/lsof

ls -lh /usr/sbin/ss

2、上传如下命令到/root下

ps netstat ss lsof

3、删除如下目录及文件

rm -rf /usr/bin/dpkgd (ps netstat lsof ss)

rm -rf /usr/bin/bsd-port #木马程序

rm -f /usr/bin/.sshd #木马后门

rm -f /tmp/gates.lod

rm -f /tmp/moni.lod

rm -f /etc/rc.d/init.d/DbSecuritySpt(启动上述描述的那些木马变种程序)

rm -f /etc/rc.d/rc1.d/S97DbSecuritySpt

rm -f /etc/rc.d/rc2.d/S97DbSecuritySpt

rm -f /etc/rc.d/rc3.d/S97DbSecuritySpt

rm -f /etc/rc.d/rc4.d/S97DbSecuritySpt

rm -f /etc/rc.d/rc5.d/S97DbSecuritySpt

rm -f /etc/rc.d/init.d/selinux(默认是启动/usr/bin/bsd-port/getty)

rm -f /etc/rc.d/rc1.d/S99selinux

rm -f /etc/rc.d/rc2.d/S99selinux

rm -f /etc/rc.d/rc3.d/S99selinux

rm -f /etc/rc.d/rc4.d/S99selinux

rm -f /etc/rc.d/rc5.d/S99selinux

4、找出异常程序并杀死

c07c4852c1b5317e154ffffb88055ca8.png

5、删除含木马命令并重新安装(或者把上传的正常程序复制过去也行)

我自己重新安装好像不行,我是找的正常的机器复制的命令。

#ps

/root/chattr -i -a /bin/ps && rm /bin/ps -f

yum reinstall procps -y 或 cp /root/ps /bin

#netstat

/root/chattr -i -a /bin/netstat && rm /bin/netstat -f

yum reinstall net-tools -y 或 cp /root/netstat /bin

#lsof

/root/chattr -i -a /bin/lsof && rm /usr/sbin/lsof -f

yum reinstall lsof -y 或 cp /root/lsof /usr/sbin

#ss

/root/chattr -i -a /usr/sbin/ss && rm /usr/sbin/ss -f

yum -y reinstall iproute 或 cp /root/ss /usr/sbin

原文地址:https://www.cnblogs.com/Su-per-man/p/15062481.html