前言
上篇帖子分析了frida_dump脚本如何实现dump dex的原理,本篇分析frida_unpack如何脱壳的。
frida_unpack地址
frida_unpack作者提供了rpc调用和js脚本调用两种方式,本次分析js脚本调用,其实js脚本调用没问题的话,可以直接copy到rpc调用里面,都是一样的。
原版核心函数分析
'use strict';
/**
* 此脚本在以下环境测试通过
* android os: 7.1.2 32bit (64位可能要改OpenMemory的签名)
* legu: libshella-2.8.so
* 360:libjiagu.so
*/
Interceptor.attach(Module.findExportByName("libart.so", "_ZN3art7DexFile10OpenMemoryEPKhjRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEjPNS_6MemMapEPKNS_10OatDexFileEPS9_"), {
onEnter: function (args) {
//dex起始位置
var begin = args[1]
//打印magic
console.log("magic : " + Memory.readUtf8String(begin))
//dex fileSize 地址
var address = parseInt(begin,16) + 0x20
//dex 大小
var dex_size = Memory.readInt(ptr(address))
console.log("dex_size :" + dex_size)
//dump dex 到/data/data/pkg/目录下
var file = new File("/data/data/xxx.xxx.xxx/" + dex_size + ".dex", "wb")
file.write(Memory.readByteArray(begin, dex_size))
file.flush()
file.close()
},
onLeave: function (retval) {
if (retval.toInt32() > 0) {
/* do something */
}
}
});
作者提供的这个脚本是在32位android 7环境下的。可以看出frida_unpack的脱壳点是hook了OpenMemory函数,通过参数拿到dex文件头,从dex文件头+0x20偏移处得到dex的文件长度, 然后dump到手机上的。但是这个脚本不能直接运行,没有给出真实的dump路径。
作者在github上也说了,android 10上的脱壳点变成了OpenCommon了。
android 10为/apex/com.android.runtime/lib/libdexfile.so方法为OpenCommon
我在安卓在线源码网站 上查询到从android 8及以后OpenMemory都变成了OpenCommon,所以你想用原版的脚本运行在android 7以上的环境时,都需要修改脚本,否则不能成功脱壳。
修改后的unpack.js
function dump_dex(){
var libdexfileAddr = Module.getExportByName("libdexfile.so","_ZN3art13DexFileLoader10OpenCommonEPKhjS2_jRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEjPKNS_10OatDexFileEbbPS9_NS3_10unique_ptrINS_16DexFileContainerENS3_14default_deleteISH_EEEEPNS0_12VerifyResultE")
if (libdexfileAddr == undefined || libdexfileAddr == null){
console.error("libdexfileAddr = ",libdexfileAddr)
return;
}
Interceptor.attach(libdexfileAddr,{
onEnter: function(args){
//dex在内存中的起始位置
var base = args[1];
//console.log("base = " , base)
var size = args[2];
//console.log("size = " ,size)
//打印magic 并验证
// var magic1 = Memory.readUtf8String(base);
//console.log("magic1",magic1)
var magic = ptr(base).readCString();
if(magic.indexOf("dex") == 0){
//找到了dex文件
//Dexd filesize地址
//var address = parseInt(base,16) + 0x20
//var dex_size = Memory.readInt(ptr(address))
//console.log("dex_size = ", size);
&nbs
支付2UD,阅读全文
还有更多的精彩内容,作者设置为付费后可见