记一次挖矿木马样本分析

本文详细描述了一台VPS遭遇弱口令攻击后的分析过程,涉及shc加密的二进制文件解密,通过查找main函数和RC4算法定位shell命令,以及对shell脚本内容的揭示,包括删除日志和矿机操作。作者还提到了与安天发布的yayayaminer样本的关联性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有一台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脚本了。

帮助网安学习,全套资料S信免费领取:
① 网安学习成长路径思维导图
② 60+网安经典常用工具包
③ 100+SRC分析报告
④ 150+网安攻防实战技术电子书
⑤ 最权威CISSP 认证考试指南+题库
⑥ 超1800页CTF实战技巧手册
⑦ 最新网安大厂面试题合集(含答案)
⑧ APP客户端安全检测指南(安卓+IOS)

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有一定相似之处,在初期的排查阶段借鉴了其思路。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值