首页
社区
课程
招聘
[原创]基于frida的脱壳工具
发表于: 2018-7-5 12:40 25822

[原创]基于frida的脱壳工具

2018-7-5 12:40
25822

frida-unpack

基于Frida的脱壳工具

0x0 frida环境搭建

frida环境搭建,参考frida官网:frida

0x2 原理说明

利用frida hook libart.so中的OpenMemory方法,拿到内存中dex的地址,计算出dex文件的大小,从内存中将dex导出。
ps:查看OpenMemory的导出名称,可以将手机中的libart.so通过adb pull命令导出到电脑,然后利用:
nm libart.so |grep OpenMemory命令来查看到出名。

0x3 脚本用法

  • 在手机上启动frida server端
  • 执行脱壳脚本
      ./inject.sh 要脱壳的应用的包名 OpenMemory.js
    
  • 脱壳后的dex保存在/data/data/应用包名/目录下

0x4 脚本测试环境

此脚本在以下环境测试通过

  • android os: 7.1.2 32bit (64位可能要改OpenMemory的签名)
  • legu: libshella-2.8.so
  • 360: libjiagu.so

0x5 参考链接

0x06 python脚本支持

python frida_unpack.py 应用包名

0x07 相关技巧

  • 利用c++filt命令还原C++ name managling之后的函数名

      c++filt _ZN3art7DexFile10OpenMemoryEPKhjRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEjPNS_6MemMapEPKNS_10OatDexFileEPS9_
    
      输出:
      art::DexFile::OpenMemory(unsigned char const*, unsigned int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int, art::MemMap*, art::OatDexFile const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)
    

源码见github链接:https://github.com/dstmath/frida-unpack


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2018-7-9 15:39 被dstmath编辑 ,原因: c++filt
收藏
免费 0
支持
分享
打赏 + 2.00雪花
打赏次数 1 雪花 + 2.00
 
赞赏  junkboy   +2.00 2018/07/05
最新回复 (31)
雪    币: 11716
活跃值: (133)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
支持一下
2018-7-5 12:50
0
雪    币: 624
活跃值: (2234)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
3
楼主,你的legu,360的样本是最新版吗?可悲的是,frida低版本的安卓Android 4.0.4+ 兼容性不好.
2018-7-5 23:43
0
雪    币: 1
活跃值: (713)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
66666
2018-7-6 11:58
0
雪    币: 294
活跃值: (56)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
5
东西很不错。
最后于 2018-7-22 22:03 被小琦编辑 ,原因:
2018-7-22 12:07
0
雪    币: 124
活跃值: (364)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
oncreate能还原?
2018-7-25 07:18
0
雪    币: 1
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
我尝试了js代码
Interceptor.attach(Module.findExportByName("libart.so", "_ZN3art7DexFile10OpenMemoryEPKhjRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEjPNS_6MemMapEPKNS_10OatDexFileEPS9_"), {
    onEnter: function (args) {

    },
    onLeave: function (retval) {

    }
});

系统是4.4或者5.0的都尝试了。都是弹出同样的报错。{u'columnNumber': 1, u'description': u'Error: expected a pointer', u'fileName': u'frida/runtime/core.js', u'lineNumber': 471, u'type': u'error', u'stack': u'Error: expected a pointer\n    at frida/runtime/core.js:471\n    at script1.js:10'}

但是测试其他native hook,如下
Interceptor.attach(Module.findExportByName("libc.so" , "open"), {
就正常

有知道原因的吗?

楼主有联系方式吗?需要咨询点问题
最后于 2018-7-29 17:58 被Gino_859435编辑 ,原因:
2018-7-29 17:56
0
雪    币: 242
活跃值: (41)
能力值: ( LV4,RANK:44 )
在线值:
发帖
回帖
粉丝
8
不行啊,我frida 10.6.52版本,android 7.0下脱libshella2.8的壳手机总是重启.

======================
重启解决了,但是还是报错Failed to spawn: unexpectedly timed out while waiting for app to launch 

======================
干脆换模拟器没有超时的报错了,但是又有新的问题。
Spawned `com.xxx.xxx`. Resuming main thread!            
[Unknown sdk_google_phone_armv7::com.xxx.xxxxxxx]-> magic : dex
035
dex_size :14568192
Error: failed to open file (No such file or directory)
    at repl1.js:22
magic : dex
035
dex_size :292
Error: failed to open file (No such file or directory)
    at repl1.js:22

最后于 2018-7-31 15:13 被xeldax编辑 ,原因:
2018-7-31 11:56
0
雪    币: 54
活跃值: (690)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
xeldax 不行啊,我frida&nbsp;10.6.52版本,android&nbsp;7.0下脱libshella2.8的壳手机总是重启.======================重启解决了 ...
device = frida.get_usb_device(10)   连接时,修改下超时时间。默认是0
2018-7-31 14:04
0
雪    币: 242
活跃值: (41)
能力值: ( LV4,RANK:44 )
在线值:
发帖
回帖
粉丝
10
这个是设置过了但还是不行,我后来干脆换了安卓模拟器就好了,但是还是有报错。
Error: failed to open file (No such file or directory)    at repl1.js:22
我还卡在这里
2018-7-31 15:12
0
雪    币: 242
活跃值: (41)
能力值: ( LV4,RANK:44 )
在线值:
发帖
回帖
粉丝
11
成功了,可以用了,我犯蠢文件夹没改
2018-7-31 15:30
0
雪    币: 38
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12

D:\frida-unpack-master>frida -R -f com.android.browser -l OpenMemory.js --no-pause
     ____
    / _  |   Frida 12.0.8 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at http://www.frida.re/docs/home/
Spawned `com.android.browser`. Resuming main thread!
[Remote::com.android.browser]-> Error: access violation accessing 0xf35a8
    at repl1.js:14
Error: access violation accessing 0xc539c
    at repl1.js:14
[Remote::com.android.browser]->
[Remote::com.android.browser]->

各位好,我执行始终报内存不能访问。换了模拟器,虚拟机都不行。
2018-8-7 10:53
0
雪    币: 30
活跃值: (106)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
C:\Users\Administrator>python C:\Users\Administrator\Desktop\frida-unpack-master
\frida-unpack-master\frida_unpack.py com.jlzb.android
  File "C:\Users\Administrator\Desktop\frida-unpack-master\frida-unpack-master\f
rida_unpack.py", line 9
    print hex(base),size
            ^
SyntaxError: invalid syntax

我安卓7.0的 n5 试了这个 不行 请问是什么原因?
2018-8-8 22:36
0
雪    币: 30
活跃值: (106)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
14
ex 导出目录为: /data/data/com.waqu.android.firebull
raceback (most recent call last):
 File "D:\Program Files\Python36\lib\site-packages\frida\core.py", line 295, in
_on_message
   callback(message, data)
 File "C:\Users\Administrator\Desktop\frida-unpack-master\frida-unpack-master\f
ida_unpack.py", line 7, in on_message
   base = message['payload']['base']
keyError: 'payload'

这是关键词不存在?
2018-8-9 15:03
0
雪    币: 121
活跃值: (44)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
15
总是 报权限不足,无法创建 或者 无法打开文件。怎么办?
2018-8-14 20:39
0
雪    币: 121
活跃值: (44)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
16
{'type': 'error', 'description': 'Error: failed to open file (Permission denied)
', 'stack': 'Error: failed to open file (Permission denied)\n    at script1.js:1
3', 'fileName': 'script1.js', 'lineNumber': 13, 'columnNumber': 1}
2018-8-14 20:46
0
雪    币: 54
活跃值: (690)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
17
linlon {'type': 'error', 'description': 'Error: failed to open file (Permission denied) ', 'stack': 'Error ...
设置-》应用-》找到APP,给它读写权限
2018-8-15 09:26
0
雪    币: 2
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
18
     ____
    / _  |   Frida 12.0.8 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at http://www.frida.re/docs/home/
Failed to spawn: the 'argv' option is not supported when spawning Android apps
原来是sever版本不对,更新后又提示 access violation:
Spawned `com.ionicframework.cgbank122507`. Resuming main thread!
Error: access violation accessing 0x130d4
    at repl1.js:14
Error: access violation accessing 0x130d4
    at repl1.js:14
Error: access violation accessing 0x63bd44
    at repl1.js:14
问题有待分析,换了个手机,终于脱壳成功了,感谢楼主!
最后于 2018-8-17 18:55 被wxfishso编辑 ,原因:
2018-8-16 19:53
0
雪    币: 121
活跃值: (44)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
19
chmlqw 设置-》应用-》找到APP,给它读写权限
太感谢了,确实是这个原因 
但是我想把文件输出的时候,又提示 没有这个属性
AttributeError: 'Session' object has no attribute 'read_bytes'
查了下 py源码,确实是没有,文档中也没有,是版本问题吗?
2018-8-17 23:29
0
雪    币: 121
活跃值: (44)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
20
知道了 
def on_message(message ,data):
    print (message)
    f = open("1.luc","wb")
    f.write(data)
    f.close()
这样写就没问题了 
2018-8-17 23:47
0
雪    币: 30
活跃值: (106)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
21
linlon 知道了 def on_message(message ,data): print (message) f = open("1.luc","wb&q ...
你用的是模拟器 还是手机的?
2018-8-18 17:31
0
雪    币: 294
活跃值: (56)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
22
真机 7.1.2  arm64 的  不用改吃成64位OpenMemory的签名  不然会报错。 
用 inject.sh com.xx.xx OpenMemory.js

Usage: ./inject.sh packageName xx.js
     ____
    / _  |   Frida 12.1.1 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at http://www.frida.re/docs/home/
Spawning ` com.xx.xx`...
Spawned ` com.xx.xx`. Resuming main thread!
[Huawei Nexus 6P::com.xx.xx]-> magic : dex
035
dex_size :995208
magic : dex
035
dex_size :995208
magic : qh
dex_size :879191396
Error: breakpoint triggered
    at /repl1.js:27
magic : dex
035
dex_size :5154472
magic : dex
035
dex_size :5154472
magic : dex
035
dex_size :259656
magic : dex
035
dex_size :324
magic : dex
035
dex_size :324
magic : dex
035
dex_size :5154472
magic : dex
035
dex_size :995208
magic : dex
035
dex_size :995208
2018-8-31 23:06
0
雪    币: 144
活跃值: (335)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
23
牛逼支持一个
2018-9-1 10:48
0
雪    币: 8603
活跃值: (3810)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
24
Traceback (most recent call last):
  File "E:\Python27\lib\site-packages\frida\core.py", line 295, in _on_message
    callback(message, data)
  File "F:/code/untitled/frida-unpack-master/frida_unpack.py", line 7, in on_message
    base = message['payload']['base']
KeyError: 'payload'


请问这个怎么破啊?
2018-9-1 18:03
0
雪    币: 1
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
25
可用,成功,支持一个
2018-9-17 09:24
0
游客
登录 | 注册 方可回帖
返回
//