有一台vps被弱口令上马了
翻来翻去
找到个二进制文件如下
前言
[img=720,104.23777564717162]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202401251032810.png[/img]
搜main函数关键字可以判断是用shc加密shell脚本生成的二进制文件
[img=720,327.48201438848923]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202401251032812.png[/img]
[img=720,410.77720207253884]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202401251032813.png[/img]
在0000000000400F7E位置函数,找到了加载shell命令的位置
[img=720,748.907063197026]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202401251032814.png[/img]
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会记录当前进程是否为父进程,
调试发现如果为父进程,则执行的命令是那么相当于把代码在子进程里面又跑了一遍
这个时候ret就是1了,加载的也会是text里面真正的代码段
[img=720,623.688]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202401251032815.png[/img]
思路
程序把shell命令用rc4加密在了硬编码里面,回到样本,只要更改ret的值然后调到execvp 然后print mem就能得到shell脚本了。
【----帮助网安学习,以下所有学习资料免费领!加vx:dctintin,备注 “博客园” 获取!】
① 网安学习成长路径思维导图
② 60+网安经典常用工具包
③ 100+SRC漏洞分析报告
④ 150+网安攻防实战技术电子书
⑤ 最权威CISSP 认证考试指南+题库
⑥ 超1800页CTF实战技巧手册
⑦ 最新网安大厂面试题合集(含答案)
⑧ APP客户端安全检测指南(安卓+IOS)
patch && dump mem
修改ret值
[img=720,342.10268948655255]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202401251032816.png[/img]
在memcpy下断
[img=720,395.00294637595755]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202401251032817.png[/img]
[img=720,321.6462620474082]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202401251032818.png[/img]
祖传字符串脚本- 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=[]
复制代码 [img=720,246.10033444816054]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202401251032819.png[/img]- shlll = b''
-
- with open("sh.tmp", "w") as f:
- print(shlll.decode(),file=f)
复制代码 暂且写个脚本存一下
shell分析
到这一步就比较明了了
shell脚本里面存的命令全是用明文显示的
[img=720,618.0530973451328]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202401251032820.png[/img]
首先是删除日志和竞品矿机,然后设置iptable
释放iptable_reject
然后从远程服务器下载矿机
[img=720,521.6615653694797]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202401251032821.png[/img]
其中一个ip是172.104.170.240
上网搜一下ip是一个矿池
[img=720,220.48524590163933]https://m-1254331109.cos.ap-guangzhou.myqcloud.com/202401251032822.png[/img]
搜索矿池ip发现样本行为和安天于今年5月发布的yayayaminer有一定相似之处,在初期的排查阶段借鉴了其思路。
更多网安技能的在线实操练习,请点击这里>>
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |