Android IDA 动态调试so(过掉JNI_Onload调
![](https://img.haomeiwen.com/i13570404/5ecd8b1c60a56f5d.png)
做一题阿里的逆向题
jdax中打开MainActivity
![](https://img.haomeiwen.com/i13570404/c2dc3def8bb59b09.png)
ida中打开so , 看起来是静态注册
![](https://img.haomeiwen.com/i13570404/f81433d38830dce6.png)
下面有两种办法
-
frida hook , 让securityCheck 返回true
03.png
js代码:
setImmediate(function () {
console.log("[*] Starting script");
if (Java.available) {
Java.perform(function () {
var checkClazz = Java.use('com.yaotong.crackme.MainActivity');
checkClazz.securityCheck.implementation = function(a){
var rc = this.securityCheck(a);
console.log("arg1 = " + a);
console.log(typeof(rc));
console.log("res = " + rc);
return true;
};
})
} else {
console.log("jvm error");
}
});
python
# -*- coding: utf-8 -*-
import time
import frida
import pprint
device8 = frida.get_usb_device()
pid = device8.spawn("com.yaotong.crackme")
device8.resume(pid)
time.sleep(1)
session = device8.attach(pid)
with open("./js/ali.js", 'r', encoding='utf-8') as f:
script = session.create_script(f.read())
def my_message_handler(message, payload):
if message['type'] == 'send':
print('send type message: {}'.format(message))
else:
print(message)
script.on("message", my_message_handler)
script.load()
input() #等待输入
![](https://img.haomeiwen.com/i13570404/814dfda2e6c5f5dc.png)
- 分析so, 修改so, 重新编译成apk
ida 动态调试 so
前提是配置好 andriod server 端口转发等
adb shell am start -D -n 打开对应app
![](https://img.haomeiwen.com/i13570404/8df7196fcbe54213.png)
![](https://img.haomeiwen.com/i13570404/973535905e1d836a.png)
配置ida
打开IDA ,点击debugger->select debugger ,这样选择,然后确定
![](https://img.haomeiwen.com/i13570404/2626d85b5d79af91.png)
然后再Debugger->process options 进行如下设置
![](https://img.haomeiwen.com/i13570404/cc757da39aa0e633.png)
然后Debugger->attach to process ,找到目标进程 点击进去
![](https://img.haomeiwen.com/i13570404/2757721e6030d9e7.png)
接下来出现的选项点yes,然后Debugger->Debugger options进行如下设置
![](https://img.haomeiwen.com/i13570404/5b22c6c01903b488.png)
设置好了之后按F9,启动程序,打开ddms(SDK tools 文件夹),打开cmd输入
jdb -connect com.sun.jdi.SocketAttach:hostname=127.0.0.1,port=8700
,然后接着f9,直到jdb attach 住了(IDA出现的界面选项中 有yes点yes,有same 点same);
不打开ddms会报以下异常:
![](https://img.haomeiwen.com/i13570404/17ebf936c41c69e4.png)
打开ddms
![](https://img.haomeiwen.com/i13570404/f2c1402cc346c10f.png)
app继续运行
![](https://img.haomeiwen.com/i13570404/b7c9a3f7c9cdf5a1.png)
ida中继续按 F9
直到出现下图, 说明加载crackme.so
![](https://img.haomeiwen.com/i13570404/088d5cda0a28fdd3.png)
右边是寄存器的值
![](https://img.haomeiwen.com/i13570404/15ef5fb009278aad.png)
![](https://img.haomeiwen.com/i13570404/2d90cfb1fef1747e.png)
ctrl + s 查看加载so的情况
![](https://img.haomeiwen.com/i13570404/21ee5e17c1eebf61.png)
然后再右侧moudules中搜索crackme.so中打开Jni_onload,下个断点,F9,出现选项点yes;
![](https://img.haomeiwen.com/i13570404/de39e9529c3ddb1a.png)
![](https://img.haomeiwen.com/i13570404/578aefa48522ff0a.png)
接着开始F7 F8单步调试。多次调试发现在运行玩BLX R7之后程序会退出,那么此处应该就是反调试检测机制了。
打开R7寄存器 出现pthread_create ,证明猜测正确
![](https://img.haomeiwen.com/i13570404/9026af5628f47143.png)
然后使用用IDA pro静态打开so 文件 找到汇编代码,产看blx R7 的十六进制,37 FF 2F E1
![](https://img.haomeiwen.com/i13570404/72609dee115bf88a.png)
使用010 Editor或者win hex修改成 00 00 00 00 就是直接nop掉这条指令(直接删除指令的话,文件会发生错乱,因为so文件有固定的格式,比如很多段的内容,每个段的偏移值都是保存的,这样删除的话会影响偏移值)。
![](https://img.haomeiwen.com/i13570404/9e0b3375e548a604.png)
使用 apkToolBox 重新生成apk, 并重签名
![](https://img.haomeiwen.com/i13570404/d24e38610ca61735.png)
重新在ida调试
在securityCheck中打断点, 慢慢调试
![](https://img.haomeiwen.com/i13570404/40e2a6fca29e8deb.png)
![](https://img.haomeiwen.com/i13570404/a4ca6f52c14577d4.png)
搞掂
![](https://img.haomeiwen.com/i13570404/f31d0bd4650774f3.png)
参考文章
https://blog.csdn.net/Viewz/article/details/97757862
https://blog.csdn.net/hbhgyu/article/details/81321923
链接:https://pan.baidu.com/s/1oOH9RgukXJcXianq8jgYhg
提取码:5lzf