天天看点

记一次入侵Linux服务器和删除木马程序的经历(Linux.BackDoor.Gates.5)

一、背景

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

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

二、发现并追踪处理

1、查看流量图发现问题

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

记一次入侵Linux服务器和删除木马程序的经历(Linux.BackDoor.Gates.5)

2、top动态查看进程

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

记一次入侵Linux服务器和删除木马程序的经历(Linux.BackDoor.Gates.5)

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

killall -9 nginx1
rm -f /etc/nginx1
           

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

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

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

记一次入侵Linux服务器和删除木马程序的经历(Linux.BackDoor.Gates.5)

7、更多异常文件的发现

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

记一次入侵Linux服务器和删除木马程序的经历(Linux.BackDoor.Gates.5)

想到这里,替换的命令应该很多,单靠我们去找肯定是解决不了的,我的建议最好是重装操作系统,并做好安全策略,如果不重装,我下面给一下我的方法,具体行不行有待验证。

三、木马手动清除

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

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、找出异常程序并杀死

记一次入侵Linux服务器和删除木马程序的经历(Linux.BackDoor.Gates.5)

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
           

四、杀毒工具扫描

1、安装杀毒工具clamav

yum -y install clamav clamav-milter
           

2、启动服务

service clamd restart
           

3、更新病毒库

由于ClamAV不是最新版本,所以有告警信息。可以忽略或升级最新版本。

[[email protected] ~]# freshclam 
ClamAV update process started at Sun Jan 31 03:15:52 2016
WARNING: Can't query current.cvd.clamav.net
WARNING: Invalid DNS reply. Falling back to HTTP mode.
Reading CVD header (main.cvd): WARNING: main.cvd not found on remote server
WARNING: Can't read main.cvd header from db.cn.clamav.net (IP: 185.100.64.62)
Trying again in 5 secs...
ClamAV update process started at Sun Jan 31 03:16:25 2016
WARNING: Can't query current.cvd.clamav.net
WARNING: Invalid DNS reply. Falling back to HTTP mode.
Reading CVD header (main.cvd): Trying host db.cn.clamav.net (200.236.31.1)...
OK
main.cvd is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo)
Reading CVD header (daily.cvd): OK (IMS)
daily.cvd is up to date (version: 21325, sigs: 1824133, f-level: 63, builder: neo)
Reading CVD header (bytecode.cvd): OK (IMS)
bytecode.cvd is up to date (version: 271, sigs: 47, f-level: 63, builder: anvilleg)
           

4、扫描方法

可以使用clamscan -h查看相应的帮助信息

clamscan -r /etc --max-dir-recursion=5 -l /root/etcclamav.log
clamscan -r /bin --max-dir-recursion=5 -l /root/binclamav.log
clamscan -r /usr --max-dir-recursion=5 -l /root/usrclamav.log
clamscan -r --remove /usr/bin/bsd-port
clamscan -r --remove /usr/bin/
           

5、查看日志发现

把发现的命令删掉替换正常的

记一次入侵Linux服务器和删除木马程序的经历(Linux.BackDoor.Gates.5)

继续阅读