linux服务器被入侵查询木马(清除方法)

linux服务器被入侵查询木马(清除方法)

2016年11月17日 15:52:33 UpUpUpUpUpUpUp 阅读数 3359

 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012599988/article/details/53201212

记录一次查询清除木马过程 
木马名称:

Linux.BackDoor.Gates.5 
链接:https://forum.antichat.ru/threads/413337/

前两天服务器被扫描后,出现莫名进程,清理后重启,也把原来的SSH密码登陆改为公钥,仅仅过去两天,一早登陆服务器发现一个进程直接懵了,清掉我ROOT所有文件。

这里写图片描述

这是/etc/profile文件,发现!!!

这是/etc/profile文件 
这明显是前天我没有清理干净,又被攻击了。

那就开始排查,战斗!

先清理可疑程序,如: 
这里写图片描述 
这里写图片描述

明显不认识呐,我的服务器跑了什么我还不知道?

干掉!咦,干掉自己起来。明显是自启!!!
查,/etc/rc.local
  • 1
  • 2

这里写图片描述

进程杀了又起来,文件删了又自动生成,无奈之下只好想了一个怪招,把/bin/bash重命名一下 
再查询基础命令是否被掉包:

这里写图片描述

对比下其他在正常服务器的显示如下:

这里写图片描述

怒了有没有!明显换了。换成程序大小为1.2M的了。

那就删掉被更改的,从其他同配置服务器拷贝一份。

记的拷贝过来要给予755 权限。
  • 1

这里写图片描述

分析了一下,这些木马程序名字变着花样来,但万变不离其宗,名字都写 
在/etc/rc.d/init.d/DbSecuritySpt和/etc/rc.d/init.d/selinux里面,而且名字和正常的服务很像。

这里写图片描述

注意rm命令也被掉包了,需要更换!

有:

/usr/bin/bsd-port/getty、/usr/bin/dpkgd/ps
/usr/bin/.sshd
  • 1
  • 2

哈哈,清理了这些服务器CPU立马从100%下来了。

简单判断有无木马

有无下列文件

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
删除如下目录及文件

rm -rf /usr/bin/dpkgd  (ps netstat lsof ss)
rm -rf /usr/bin/bsd-port  (木马程序)
rm -f  /usr/local/zabbix/sbin/zabbix_AgentD (木马程序)
rm -f  /usr/local/zabbix/sbin/conf.n
rm -f  /usr/bin/.sshd 
rm -f  /usr/bin/sshd 
rm -f  /root/cmd.n
rm -f  /root/conf.n
rm -f  /root/IP
rm -f  /tmp/gates.lod   
rm -f  /tmp/moni.lod
rm -f  /tmp/notify.file  程序
rm -f  /tmp/gates.lock   进程号
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

如: 
这里写图片描述

然后找出下列程序进程号并杀死:

/root/ps aux |grep -i jul29(主要是最近开启的进程)

/root/ps aux |grep -i jul30

/root/ps aux |grep -i jul31

/root/ps aux |grep sshd

/root/ps aux |grep ps

/root/ps aux |grep getty

/root/ps aux |grep netstat

/root/ps aux |grep lsof

/root/ps aux |grep ss

/root/ps aux |grep zabbix_Agetntd

/root/ps aux |grep .dbus

如: 
这里写图片描述

注意如果kill后删除后还会再出现就这样操作(破坏木马程序)

/usr/bin/dpkgd/ps && /root/chattr +i /usr/bin/dpkgd/ps

/usr/bin/bsd-port/getty && /root/chattr +i /usr/bin/bsd-port/getty

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

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

chattr && lsattr

yum -y reinstall e2fsprogs

ss

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

yum -y reinstall iproute

cp /root/ss /usr/sbin

修改下面两个程序的权限,这个是意外发现有的改了这两个程序的权限,让你发现了木马既不能下载正常程序也不能杀进程

/usr/bin/killall 
/usr/bin/wget
  • 1
  • 2

另外他们还修改了DNS怕我们识别不了有的域名吧,想得很周到。

cat /etc/resolv.conf

nameserver 8.8.8.8

nameserver 8.8.4.4

——————————————————————

工具扫描

安装杀毒工具

安装

yum -y install clamav*

启动

service clamd restart

更新病毒库

freshclam

扫描方法

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 /bin/

clamscan -r –remove /usr/bin/

查看日志发现

/bin/netstat: Linux.Trojan.Agent FOUND为病毒

grep FOUND /root/usrclamav.log

/usr/bin/.sshd: Linux.Trojan.Agent FOUND

/usr/sbin/ss: Linux.Trojan.Agent FOUND

/usr/sbin/lsof: Linux.Trojan.Agent FOUND 如: “`

这里写图片描述

这里写图片描述

加强自身安全

但是此时还不知道系统入侵的原因,只能从两个方面考虑:暴力破解和系统及服务漏洞

a、yum update 更新系统(特别是bash、openssh和openssl)

b、关闭一些不必要的服务

c、设置ssh普通用户登陆并用hosts.all、hosts.deny限制登陆的网段

d、记录登陆系统后操作的命令


在日常运维中,我们需要清楚服务器上每个用户登录后都做了哪些操作,我们需要记录下每个用户的操作命令。 
下面的内容设置可以实现在Linux下所有用户,不管是远程还是本地登陆,在本机的所有操作都会记录下来,并生成包含“用户/IP/时间”的文件存放在指定位置。

export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S]"
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
HISTDIR=/var/log/.hist
if [ -z $USER_IP  ]
then
  USER_IP=`hostname`
fi
if [ ! -d $HISTDIR ]
then
   mkdir -p $HISTDIR
   chmod 777 $HISTDIR
fi
if [ ! -d $HISTDIR/${LOGNAME} ]
then
    mkdir -p $HISTDIR/${LOGNAME}
    chmod 300 $HISTDIR/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date +%Y%m%d_%H%M%S`
export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.hist.$DT"
chmod 600 $HISTDIR/${LOGNAME}/*.hist* 2>/dev/null
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

得到的结果,永久保存,每个用户的命令记录分目录保存

ls -l /var/log/.hist/root/ 
-rw——- 1 root root 546 2006-05-26 10:00 218.82.245.54.hist.20060526_092458 
-rw——- 1 root root 243 2006-05-28 13:28 218.82.245.54.hist.20060528_114822 
-rw——- 1 root root 10 2006-05-28 12:18 218.82.245.54.hist.20060528_121605

查看命令记录 
export HISTFILE=/var/log/.hist/root/xx04.hist.208_152551

[root@demoredis_171 root]# history 
1 2016-11-17 15:41:40 ll 
2 2016-11-17 15:41:42 cd /data/ 
3 2016-11-17 15:41:42 ll 
4 2016-11-17 15:41:47 cd /var/log/.hist/ 
5 2016-11-17 15:41:47 ll 
6 2016-11-17 15:41:48 cd root/ 
7 2016-11-17 15:41:48 ll 
10 2016-11-17 15:42:18 export HISTFILE=18—.hist.20161117_154054 11 2016-11-17 
15:42:21 history

转载于:https://my.oschina.net/u/3367404/blog/3063232

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值