1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
'use strict';
const dexMap=new Map(); var dex_count=1;
function get_self_process_name(){ var open=new NativeFunction(Module.getExportByName('libc.so','open'),'int',['pointer','int']); var read=new NativeFunction(Module.getExportByName('libc.so','read'),'int',['int','pointer','int']); var close=new NativeFunction(Module.getExportByName('libc.so','close'),'int',['int']); var path=Memory.allocUtf8String("/proc/self/cmdline"); var fd=open(path,0); if(fd!=-1){ var buf=Memory.alloc(0x1000); read(fd,buf,0x1000); close(fd); return ptr(buf).readCString(); } return "-1"; }
function chmod(path){ var func=new NativeFunction(Module.getExportByName('libc.so','chmod'),'int',['pointer','int']); func(Memory.allocUtf8String(path),755); }
function Mkdir(path){ if(path.indexOf("com")==-1)return; var mkdir=new NativeFunction(Module.getExportByName('libc.so','mkdir'),'int',['pointer','int']); var opendir=new NativeFunction(Module.getExportByName('libc.so','opendir'),'pointer',['pointer']); var closedir=new NativeFunction(Module.getExportByName('libc.so','closedir'),'int',['pointer']); var cpath=Memory.allocUtf8String(path); var dir=opendir(cpath); if(dir!=0){ closedir(dir); return; } mkdir(cpath,0o755); chmod(path); console.log("[Mkdir]->",path); }
function antiDetectFrida(Base){ var crashAddr=Base.add(0x4E864); console.log("[crashAddr]->",crashAddr);
var range=Process.findRangeByAddress(crashAddr); if(range){ Memory.protect(range.base,range.size,'rwx'); console.log("[protect]->",range.base,range.size); }
Interceptor.replace(crashAddr,new NativeCallback(function(){},'void',[])); console.log("[antiDetectFrida] success"); }
function analysisDex(Base){ var addr=Base.add(0x4DB44); console.log("[DefineClass]->",addr);
var range=Process.findRangeByAddress(addr); if(range){ Memory.protect(range.base,range.size,'rwx'); }
Interceptor.attach(addr,{ onEnter:function(args){ try{ this.dex_file=this.context.x5; if(this.dex_file.isNull())return;
var base=ptr(this.dex_file).add(Process.pointerSize).readPointer(); if(base.isNull())return;
var size=ptr(this.dex_file).add(Process.pointerSize*2).readUInt(); if(size<0x1000||size>0x20000000)return;
var magic=ptr(base).readCString(); if(magic.indexOf("dex")!=0)return;
let dup=false; for(let [b,s] of dexMap.entries()){ if(b.equals(base)&&s===size){ dup=true; break; } }
if(!dup){ dexMap.set(base,size); console.log("[DexFile]->",base,size,magic); }
}catch(e){ console.log("[DefineClass error]->",e); } } }); }
function dumpDex(){ console.log("\n[*] start dump dex\n");
dexMap.forEach((size,base)=>{ try{ var magic=ptr(base).readCString(); if(magic.indexOf("dex")!=0)return;
var process_name=get_self_process_name(); if(process_name=="-1")return;
var dir="/data/data/"+process_name+"/files"; Mkdir(dir);
dir+="/dump_dex_"+process_name; Mkdir(dir);
var path=dir+"/class"+(dex_count==1?"":dex_count)+".dex";
try{ Memory.protect(ptr(base),size,'rwx'); }catch(e){}
var buf=ptr(base).readByteArray(size); var fd=new File(path,"wb");
if(fd){ dex_count++; fd.write(buf); fd.flush(); fd.close(); console.log("[dump dex]->",path); }
}catch(e){ console.log("[dumpDex error]->",e); } });
console.log("\n[*] dump finished\n"); }
function NativeFunc(){ console.log("[Hook Begin]");
var Base=Module.getBaseAddress("libdpt.so"); console.log("[Base]->",Base);
antiDetectFrida(Base); analysisDex(Base); }
function hook_android_dlopen_ext(){ var isHook=false;
Interceptor.attach(Module.findExportByName(null,"android_dlopen_ext"),{ onEnter:function(args){ this.name=""; if(args[0]){ try{ this.name=args[0].readCString(); }catch(e){} }
if(this.name.indexOf("libdpt.so")>=0){
console.log("[dlopen]->",this.name);
var symbols=Process.getModuleByName("linker64").enumerateSymbols(); var callConstructorAdd=null;
for(var i=0;i<symbols.length;i++){ var s=symbols[i]; if(s.name.indexOf("__dl__ZN6soinfo17call_constructorsEv")!=-1){ callConstructorAdd=s.address; break; } }
console.log("[call_constructors]->",callConstructorAdd);
if(callConstructorAdd&&!isHook){
isHook=true;
Interceptor.attach(callConstructorAdd,{ onEnter:function(args){
console.log("[call_constructors enter]");
try{ NativeFunc(); }catch(e){ console.log(e); }
setTimeout(function(){ dumpDex(); },10000); } }); } } } }); }
setImmediate(function(){ console.log("[*] dpt dump start"); hook_android_dlopen_ext(); });
|