转载注明出处:https://www.cdsy.xyz/computer/soft/analysis/230501/cd43355.html
APP 加固发展到现在已经好几代了,从整体加固到代码抽取到虚拟机保护,加固和脱壳的方案也逐渐趋于稳定。随着保护越来越强,脱壳机们也变得越来越费劲,繁琐。但是毕竟道高一尺,魔高一丈,市面上有很多手段可以进行脱壳操作今天介绍的是使用Frida的一个脚本来dump apk的Dex。
得益于FRIDA, 在 PC上面进行内存搜索、转储都变得十分方便,再也不需要考虑什么Xposed、什么Android开发、什么代码注入,只需要关注如何去搜索想要的东西,于是依赖一个几十行代码的小脚本,就可以将大部分内存中的 dex 脱下来。对于完整的 dex,采用暴力搜索dex035即可找到。而对于抹头的dex,通过匹配一些特征来找到。
非常感谢葫芦娃大佬的开源工具,使用起来很方便,。
项目地址:https://github.com/hluwa/FRIDA-DEXDump
先把这个开源项目下载到本地,如图,这里是mac的目录:
然后用一些查壳工具,看看该apk到底使用了什么加固。
缺图先欠着pass
之后需要开启我们手机的frida服务
再之后把目录切换到frida_dexdump所在的路径,同时把待脱壳的apk打开,也是就是变成主activity,最后直接运行python3 main.py。
倒数三秒钟就把壳脱下来了,可以看到一个个dex文件,就是我们想要的。
最最后,就是把脱下来的许许多多的dex重新合并打包,这里推荐一个很好用的合并工具,感谢qinless大佬提供的。
代码如下,需要自取。
- import os
- import zipfile
- import argparse
-
- def rename_class(path):
- files = os.listdir(path)
- dex_index = 0
- if path.endswith('/'):
- path = path[:-1]
- print(path)
- for i in range(len(files)):
- if files[i].endswith('.dex'):
- old_name = path + '/' + files[i]
- if dex_index == 0:
- new_name = path + '/' + 'classes.dex'
- else:
- new_name = path + '/' + 'classes%d.dex' % dex_index
- dex_index += 1
- if os.path.exists(new_name):
- continue
- os.rename(old_name, new_name)
- print('[*] 重命名完毕')
-
- def extract_META_INF_from_apk(apk_path, target_path):
- r = zipfile.is_zipfile(apk_path)
- if r:
- fz = zipfile.ZipFile(apk_path, 'r')
- for file in fz.namelist():
- if file.startswith('META-INF'):
- fz.extract(file, target_path)
- else:
- print('[-] %s 不是一个APK文件' % apk_path)
-
- def zip_dir(dirname, zipfilename):
- filelist = []
- if os.path.isfile(dirname):
- if dirname.endswith('.dex'):
- filelist.append(dirname)
- else:
- for root, dirs, files in os.walk(dirname):
- for dir in dirs:
- # if dir == 'META-INF':
- # print('dir:', os.path.join(root, dir))
- filelist.append(os.path.join(root, dir))
- for name in files:
- # print('file:', os.path.join(root, name))
-
- filelist.append(os.path.join(root, name))
-
- z = zipfile.ZipFile(zipfilename, 'w', zipfile.ZIP_DEFLATED)
- for tar in filelist:
- arcname = tar[len(dirname):]
-
- if ('META-INF' in arcname or arcname.endswith('.dex')) and '.DS_Store' not in arcname:
- # print(tar + " -->rar: " + arcname)
- z.write(tar, arcname)
- print('[*] APK打包成功,你可以拖入APK进行分析啦!')
- z.close()
-
- if __name__ == '__main__':
- args = {
- 'dex_path': '脱壳后dex路径',
- 'apk_path': '原始带壳apk路径',
- 'output': '脱壳后apk路径'
- }
-
- rename_class(args['dex_path'])
- extract_META_INF_from_apk(args['apk_path'], args['dex_path'])
- zip_dir(args['dex_path'], args['output'])
-
效果如下:
之后就会把apk打包成功,就可以拖入jadx反编译查看源代码了。
完事手工✋🏻。