当前位置: 首页 > 技术干货 > 记一次挖矿木马样本分析

记一次挖矿木马样本分析

发表于:2024-01-25 11:01 作者: 培根 阅读数(2521人)

有一台vps被弱口令上马了

翻来翻去

找到个二进制文件如下

前言

Untitled

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

Untitled

Untitled

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

image-20240108211127374

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: allen@gateway.grumman.com (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
*/

static const char my_name[] = "shc";
static const char version[] = "Version 4.0.3";
static const char subject[] = "Generic Shell Script Compiler";
static const char cpright[] = "GNU GPL Version 3";
static const struct { const char * f, * s, * e; }
provider = { "Md Jahidul", "Hamid", "<jahidulhamid@yahoo.com>" };

尝试生成一个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 test.sh.x* 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里面真正的代码段

image-20240108211037704

思路

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

patch && dump mem

修改ret值

Untitled

在memcpy下断

image-20240108215950966

Untitled

祖传字符串脚本

base  =0x000000000602B83
end = 0x00000000006074F0

ans=[]

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

Untitled

shlll = b''

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

暂且写个脚本存一下

shell分析

到这一步就比较明了了

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

image-20240108220142481

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

释放iptable_reject

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

image-20240108220528535

其中一个ip是172.104.170.240

上网搜一下ip是一个矿池

Untitled

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