Java.perform(function(){ var a=Java.use("com.ad2001.frida0x1.MainActivity"); a.get_random.implementation=function(){ console.log("method get_random has been hooked!"); var ret=this.get_random(); var i=ret*2+4; console.log("ret is "+ret+" input is "+i); return ret; } })
ptrace注入
frida -U ‘Frida 0x1’ -l 1.js
涉及重载,参数类型和传参确认
1 2 3 4 5 6 7 8
Java.perform(function(){ var a=Java.use("com.ad2001.frida0x1.MainActivity"); a.check.overload('int','int').implementation=function(i,i2){ console.log("i is "+i+" i2 is "+i2); var t=i*2+4; console.log("true is t "+t); } })
0x2
1 2 3 4
Java.perform(function(){ var a=Java.use("com.ad2001.frida0x2.MainActivity"); a.get_flag(4919); })
Spawned com.ad2001.frida0x2. Resuming main thread!
Java.perform(function(){ var a=Java.use("com.ad2001.frida0x3.Checker"); a.code.value=512; })
0x4
MainActivity未加载该实例,手动创建调用check
1 2 3 4 5 6
Java.perform(function(){ var check=Java.use("com.ad2001.frida0x4.Check"); var a=check.$new(); //创建Check类 var ret=a.get_flag(1337); console.log("flag is "+ret); })
0x5
wrong eg.
1 2 3 4 5
Java.perform(function(){ var a =Java.use("com.ad2001.frida0x5.MainActivity"); var get=a.$new(); get.flag(1337); })
Android 组件,如Activity子类,依赖于应用程序上下文来正常运行
Android UI 组件通常需要一个特定的线程以及与之关联的Looper
所以不能直接use实例而是现有实例上调用
1 2 3 4 5 6 7 8 9
Java.perform(function() { Java.choose('com.ad2001.frida0x5.MainActivity', { onMatch: function(instance) { // "instance" is the instance for the MainActivity console.log("Instance found"); instance.flag(1337); // Calling the function }, onComplete: function() {} }); });
注:Java.performNow()在新版本中被移除
0x6
1 2 3 4 5 6 7 8 9 10 11 12 13
Java.perform(function(){ Java.choose("com.ad2001.frida0x6.MainActivity",{ onMatch:function(instance){ console.log("Instance found"); var a=Java.use("com.ad2001.frida0x6.Checker"); var hoge=a.$new(); hoge.num1.value=1234; hoge.num2.value=4321; instance.get_flag(hoge); }, onComplete:function(){} }) })
0x7
多了个构造方法
1 2 3 4 5 6 7 8 9 10 11
Java.perform(function(){ Java.choose("com.ad2001.frida0x7.MainActivity",{ onMatch:function(instance){ console.log("Instance found"); var a=Java.use("com.ad2001.frida0x7.Checker"); var hoge=a.$new(666,666); instance.flag(hoge); }, onComplete:function(){} }) })
var address=Module.getExportByName("libc.so","strcmp"); Interceptor.attach(address,{ onEnter: function(args){ //这里args[]的1和2不一定分别对应哪个,但就两次尝试 var v1=Memory.readUtf8String(args[0]); //此处v1为输入 var v2=Memory.readUtf8String(args[1]); if(v1.includes("Hello")){ console.log("succeed in hooking"); console.log("the input is "+v1+"\nthe flag is "+v2); } }, onLeave:function(retval){} });
0x9
对native的return 1方法hook
1 2 3 4 5 6 7 8 9
var addr=Module.getExportByName("liba0x9.so","Java_com_ad2001_a0x9_MainActivity_check_1flag"); Interceptor.attach(addr,{ onEnter:function(args){}, onLeave:function(retval){ console.log("oraginal ret is "+retval); retval.replace(1337); console.log("now the ret is "+retval); } })