多语言展示
当前在线:826今日阅读:60今日分享:41

Linux 服务器中木马及清除木马

晚上看到有台服务器流量跑的很高,明显和平常不一样,流量达到了800Mbps,第一感觉应该是中木马了,被人当做肉鸡了,在大量发包。我们的服务器为了最好性能,防火墙(iptables)什么的都没有开启,但是服务器前面有物理防火墙,而且机器都是做的端口映射,也不是常见的端口,按理来说应该是满安全的,可能最近和木马有缘吧,老是让我遇到,也趁这次机会把发现过程记录一下。
方法/步骤
1

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

2

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

3

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

4

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

5

查看定时任务文件crontab并没有发现什么一次,然后查看系统启动文件rc.local,也没有什么异常,然后进入/etc/init.d目录查看,本文所有软件都可以在《Linux就该这么学》这本教材中找到对应的使用方法和技巧发现比较奇怪的脚本文件DbSecuritySpt、selinux。

6

现在综合总结了大概步骤如下:1、简单判断有无木马#有无下列文件cat /etc/rc.d/init.d/selinuxcat /etc/rc.d/init.d/DbSecuritySptls /usr/bin/bsd-portls /usr/bin/dpkgd#查看大小是否正常ls -lh /bin/netstatls -lh /bin/psls -lh /usr/sbin/lsofls -lh /usr/sbin/ss

7

上传如下命令到/root下ps netstat ss lsof

8

删除如下目录及文件rm -rf /usr/bin/dpkgd (ps netstat lsof ss)rm -rf /usr/bin/bsd-port #木马程序rm -f /usr/bin/.sshd #木马后门rm -f /tmp/gates.lodrm -f /tmp/moni.lodrm -f /etc/rc.d/init.d/DbSecuritySpt(启动上述描述的那些木马变种程序)rm -f /etc/rc.d/rc1.d/S97DbSecuritySptrm -f /etc/rc.d/rc2.d/S97DbSecuritySptrm -f /etc/rc.d/rc3.d/S97DbSecuritySptrm -f /etc/rc.d/rc4.d/S97DbSecuritySptrm -f /etc/rc.d/rc5.d/S97DbSecuritySptrm -f /etc/rc.d/init.d/selinux(默认是启动/usr/bin/bsd-port/getty)rm -f /etc/rc.d/rc1.d/S99selinuxrm -f /etc/rc.d/rc2.d/S99selinuxrm -f /etc/rc.d/rc3.d/S99selinuxrm -f /etc/rc.d/rc4.d/S99selinuxrm -f /etc/rc.d/rc5.d/S99selinux

9

找出异常程序并杀死

10

、删除含木马命令并重新安装(或者把上传的正常程序复制过去也行)我自己重新安装好像不行,我是找的正常的机器复制的命令。#ps/root/chattr -i -a /bin/ps && rm /bin/ps -fyum reinstall procps -y 或 cp /root/ps /bin#netstat/root/chattr -i -a /bin/netstat && rm /bin/netstat -fyum reinstall net-tools -y 或 cp /root/netstat /bin#lsof/root/chattr -i -a /bin/lsof && rm /usr/sbin/lsof -fyum reinstall lsof -y 或 cp /root/lsof /usr/sbin#ss/root/chattr -i -a /usr/sbin/ss && rm /usr/sbin/ss -fyum -y reinstall iproute 或 cp /root/ss /usr/sbin

推荐信息