前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >linux服务器被入侵查询木马

linux服务器被入侵查询木马

作者头像
拓荒者
发布2019-06-20 20:40:04
5.4K0
发布2019-06-20 20:40:04
举报
文章被收录于专栏:运维经验分享运维经验分享

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

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

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

这里写图片描述
这里写图片描述

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

这是/etc/profile文件
这是/etc/profile文件

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

那就开始排查,战斗!

先清理可疑程序,如: 

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

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

代码语言:javascript
复制
干掉!咦,干掉自己起来。明显是自启!!!
查,/etc/rc.local
  • 1
  • 2
这里写图片描述
这里写图片描述

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

这里写图片描述
这里写图片描述

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

这里写图片描述
这里写图片描述

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

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

代码语言:javascript
复制
记的拷贝过来要给予755 权限。
  • 1
这里写图片描述
这里写图片描述

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

这里写图片描述
这里写图片描述

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

有:

代码语言:javascript
复制
/usr/bin/bsd-port/getty、/usr/bin/dpkgd/ps
/usr/bin/.sshd
  • 1
  • 2

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

代码语言:javascript
复制
简单判断有无木马

有无下列文件

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
代码语言:javascript
复制
删除如下目录及文件

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

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

代码语言:javascript
复制
/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/时间”的文件存放在指定位置。

代码语言:javascript
复制
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

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档