Ida动态调试步骤

adb forward tcp:23946 tcp:23946 adb shell am  start -D -n com.hundun.yanxishe/.modules.welcome.WelcomeActivity jdb -connect com.sun.jdi.SocketAttach:port=8642,hostname=localhost

apktool invalid resource directory name: res navigation

反编译: apktool d yanxishenew.apk 回编译: apktool b yanxishenew 报错: W: invalid resource directory name: E:decodeapktoolyanxishenew1res navigation 解决方法: 使用aapt2  apktool b –use-aapt2 yanxishenew 执行结果: E:decodeapktool>apktool b –use-aapt2 yanxishenew1 I: Using Apktool 2.4.1 I: Checking whether sources has changed… I: Checking whether sources has changed… I: Checking whether sources has changed… I: Checking whether sources has changed… I: Checking whether resources has changed… I: Building resources… W: E:decodeapktoolyanxishenew1resvaluespublic.xml:2756: error: resource 'drawable/$avd_hide_password__0' has invalid entry name '$avd_hide_password__0'. Invalid character '$avd_hide_password__0'. W: E:decodeapktoolyanxishenew1resvaluespublic.xml:2757: error: resource 'drawable/$avd_hide_password__1' has invalid entry name '$avd_hide_password__1'. Invalid character '$avd_hide_password__1'. W: E:decodeapktoolyanxishenew1resvaluespublic.xml:2758: error: resource 'drawable/$avd_hide_password__2' has invalid entry name '$avd_hide_password__2'. Invalid character '$avd_hide_password__2'. W: E:decodeapktoolyanxishenew1resvaluespublic.xml:2759: error: resource 'drawable/$avd_show_password__0' has invalid entry name '$avd_show_password__0'. Invalid character '$avd_show_password__0'. W: E:decodeapktoolyanxishenew1resvaluespublic.xml:2760: error: resource 'drawable/$avd_show_password__1' has invalid entry name '$avd_show_password__1'. Invalid character '$avd_show_password__1'. W: E:decodeapktoolyanxishenew1resvaluespublic.xml:2761: error: resource 'drawable/$avd_show_password__2' has invalid entry name '$avd_show_password__2'. Invalid character '$avd_show_password__2'. W: brut_util_Jar_185611557998604586.tmp W 09-27 23:02:05 18748 21244 ApkAssets.cpp:137] resources.arsc in APK 'C:UsersAdamAppDataLocalapktoolframework1.apk' is compressed. I: Copying libs… (/lib) I: Copying libs… (/kotlin) I: Copying libs… (/META-INF/services) I: Building apk file… I: Copying unknown files/dir… I: Built apk… E:decodeapktool> dist 目录下成功编译apk

Frida 找不到类: java.lang.ClassNotFoundException: Didn’t find class

用frida hook公司线上app(经过360加固的),发现有的类能够hook到,有的类hook不到,提示如: Error: java.lang.ClassNotFoundException: Didn't find class "duozhao.com.baselib.util.RsaUtil2" on path: DexPathList … 于是乎准备hook一下DexClassLoader的loadClass方法打印一下加载的class: var dexclassLoader = Java.use("dalvik.system.DexClassLoader"); //var pathclassLoader=Java.use("dalvik.system.PathClassLoader"); var hookClass = undefined; var ClassUse = Java.use("java.lang.Class"); var hooked = false; dexclassLoader.loadClass.overload("java.lang.String","boolean").implementation=function (name,resolve) {   console.log("加载类:"+name);  return   this.loadClass(name,resolve); }; 发现还是无法打印出想要的类,此时考虑可能是360加固改变了classloader,把加固后的app拿到jax下看,StupApp中以下代码:    public final void attachBaseContext(Context context) {         boolean r0;         super.attachBaseContext(context);         C0002.m6();         f5 = context;         if (f2 == null) {             f2 = this;         }         if (f3 == null) {             Boolean valueOf = Boolean.valueOf(C0002.m3());             Boolean valueOf2 = Boolean.valueOf(false);             Boolean valueOf3 = Boolean.valueOf(false);             if (Build.CPU_ABI.contains("64") || Build.CPU_ABI2.contains("64")) {                 valueOf2 = Boolean.valueOf(true);             }             if (Build.CPU_ABI.contains("mips") || Build.CPU_ABI2.contains("mips")) {                 valueOf3 = Boolean.valueOf(true);             }             if (valueOf.booleanValue() && needX86Bridge) {                 System.loadLibrary("X86Bridge");             }             if (!loadFromLib) {                 String absolutePath = context.getFilesDir().getParentFile().getAbsolutePath();                 try {                     absolutePath = context.getFilesDir().getParentFile().getCanonicalPath();                 } catch (Exception e) {                 }                 String str = absolutePath + "/.jiagu";                 f10 = m8(str, valueOf2.booleanValue(), valueOf3.booleanValue());                 f6 = m8(str, false, false);                 f7 = str + File.separator + f6;                 f8 = str + File.separator + f10;                 f9 = str;                 if (valueOf3.booleanValue()) {                     C0002.m4(context, f4 + "_mips.so", str, f6);                 } else if (!valueOf.booleanValue() || needX86Bridge) {                     C0002.m4(context, f4 + ".so", str, f6);                 } else {                     C0002.m4(context, f4 + "_x86.so", str, f6);                 }                 if (!valueOf2.booleanValue() || valueOf3.booleanValue()) { … Read more

Use Frida hook Android so File

我们自己写一个简单的app,java层调用so 方法返回的字符串打印输出,java层和c代码如下  public class TestUtil {     static {         System.loadLibrary("security");     }     public static native String getSecretPro(int adam); } #调用jni方法 LogUtil.e("adam",TestUtil.getSecretPro(23)); #C方法返回字符串 JNIEXPORT jstring JNICALL Java_com_adam_ndktest_TestUtil_getSecretPro   (JNIEnv *env, jclass jobj, jint val){   return (*env)->NewStringUTF(env,"eveve");   } 打包生成apk,安装到手机 把libsecurity.so文件拖入ida分析, 由上图可知,Java_com_adam_ndktest_TestUtil_getSecretPro方法的偏移地址是0x630,字符串便宜地址是0x64f,那么我们用基址+偏移地址就是函数的绝对地址了,frida获取so的基地址方法如下: var soAddr=Module.findBaseAddress("libsecurity.so"); Java_com_adam_ndktest_TestUtil_getSecretPro地址是soAddr+0x630: var proAddr=soAddr.add(0x630 ); 我们要直接hook返回值的话就是soAddr+0x64f地址对应的字符串 ,然后通过Memory.readUtf8String方法读取,更改返回值的话需要用到JNIEnv api的newStringUtf方法,完整的代码如下: Java.perform(function () {    // Memory.readUtf8String var mru8s = function(addr) {return Memory.readUtf8String(addr);};     var soAddr=Module.findBaseAddress("libsecurity.so");     console.log("soAddr:"+soAddr);     var proAddr=soAddr.add(0x630);     console.log("proAddr:"+proAddr);        Interceptor.attach(proAddr, {       onEnter: function (args) {               console.log("—–华丽的分割线—–");       },       onLeave: function(retval){       var staddr=soAddr.add(0x64f);       console.log(staddr);       var nat=new NativePointer(staddr);       console.log("nat:"+nat);       console.log("str:"+mru8s(staddr));   //读取返回的字符串          //替换返回字符串        var env = Java.vm.getEnv();        var jstring = env.newStringUtf("lixiaopeng");         retval.replace(ptr(jstring));         send("retval:"+retval);       }    });      });

Frida连接远程设备报错:Failed to spawn: unable to connect to remote frida-server

  hook app过程中由于usb松动总断开,所以只好连wifi,首先是用adb连接设备 adb tcpip 5555 adb connect 192.168.43.137:5555 #ip是远程设备的ip地址 进行frida调试: frida -R -f  com.tencent.mm  -l mm.js 会报错: Failed to spawn: unable to connect to remote frida-server 解决方法: 端口转发: adb forward tcp:27042 tcp:27042 adb forward tcp:27043 tcp:27043