记一次挖矿木马样本分析

admin 2026-06-24 05:21:31 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 文档记录了一次挖矿木马样本分析过程,发现VPS因弱口令被入侵后存在SHC加密的二进制文件。通过逆向分析发现样本使用RC4加密shell命令,经调试修改ret值后成功提取恶意脚本。脚本会删除系统日志、清除竞品矿机、配置iptables防火墙,并从矿池IP172.104.170.240下载门罗币挖矿程序,行为与已知yayayaminer恶意软件相似。建议加强口令安全并参考安天发布的威胁情报进行防护。 综合评分: 82 文章分类: 恶意软件,逆向分析,应急响应,漏洞分析,安全工具


cover_image

记一次挖矿木马样本分析

原创

培根 培根

蚁景网安

2026年6月23日 17:22 湖南

在小说阅读器读本章

去阅读

有一台vps被弱口令上马了

翻来翻去

找到个二进制文件如下

前言

搜main函数关键字可以判断是用shc加密shell脚本生成的二进制文件

在0000000000400F7E位置函数,找到了加载shell命令的位置

shc部分源码

/* shc.c */

/**
 * This software contains an ad hoc version of the 'Alleged RC4' algorithm,
 * which was anonymously posted on sci.crypt news by cypherpunks on Sep 1994.
 *
 * My implementation is a complete rewrite of the one found in
 * an unknown-copyright (283 characters) version picked up from:
 *    From: [email protected] (John L. Allen)
 *    Newsgroups: comp.lang.c
 *    Subject: Shrink this C code for fame and fun
 *    Date: 21 May 1996 10:49:37 -0400
 * And it is licensed also under GPL.
 *
 *That's where I got it, now I am going to do some work on it
 *It will reside here: http://github.com/neurobin/shc
 */

staticconstchar my_name[] = "shc";
staticconstchar version[] = "Version 4.0.3";
staticconstchar subject[] = "Generic Shell Script Compiler";
staticconstchar cpright[] = "GNU GPL Version 3";
staticconststruct {constchar * f, * s, * e; }
&nbsp; &nbsp; provider = {&nbsp;"Md Jahidul",&nbsp;"Hamid",&nbsp;"<[email protected]>"&nbsp;};

尝试生成一个echo “helloworld”,看看shc生成的文件是什么构造

shc

安装shc

sudo add-apt-repository ppa:neurobin/ppa
sudo apt-get update
sudo apt-get install shc

加密后会得到一份生成的c源码和可执行文件

[04:08:08] ctfshow@ubuntu /home/ctfshow/Desktop/test (0)
> shc -f ./test.sh
[04:08:11] ctfshow@ubuntu /home/ctfshow/Desktop/test (0)
> ls
test.sh &nbsp;test.sh.x* &nbsp;test.sh.x.c
[04:08:12] ctfshow@ubuntu /home/ctfshow/Desktop/test (0)
> ./test.sh.x
hello

会输出一个test.sh.c和编译好的test.sh.x


那么可以照着test.sh.c的源码来快速分析手上的二进制文件

调试发现ret会记录当前进程是否为父进程,

调试发现如果为父进程,则执行的命令是

exec bash ./<程序自己>

那么相当于把代码在子进程里面又跑了一遍

这个时候ret就是1了,加载的也会是text里面真正的代码段

思路

程序把shell命令用rc4加密在了硬编码里面,回到样本,只要更改ret的值然后调到execvp 然后print mem就能得到shell脚本了

patch && dump mem

修改ret值

在memcpy下断

祖传字符串脚本

base &nbsp;=0x000000000602B83
end =&nbsp;0x00000000006074F0

ans=[]

for&nbsp;i in range(base,end):
&nbsp; &nbsp; tmp = idc.get_wide_byte(i)
&nbsp; &nbsp; ans.append(tmp)
&nbsp; &nbsp;&nbsp;if(tmp ==&nbsp;0):
&nbsp; &nbsp; &nbsp; &nbsp; print(bytes(ans))
&nbsp; &nbsp; &nbsp; &nbsp; ans=[]

shlll = b''

with open("sh.tmp", "w") as f:
&nbsp; &nbsp; print(shlll.decode(),file=f)

暂且写个脚本存一下

shell分析

到这一步就比较明了了

shell脚本里面存的命令全是用明文显示的

首先是删除日志和竞品矿机,然后设置iptable

释放iptable_reject

然后从远程服务器下载矿机

其中一个ip是172.104.170.240

上网搜一下ip是一个矿池

搜索矿池ip发现样本行为和安天于今年5月发布的yayayaminer有一定相似之处,在初期的排查阶段借鉴了其思路

https://www.freebuf.com/articles/network/366444.html

学习网安实战技术,戳“阅读原文”


免责声明:

本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

本文转载自:蚁景网安 培根 培根《记一次挖矿木马样本分析》

评论:0   参与:  0