iOS逆向之hook框架frida的安装和使用

举报
Serendipity·y 发表于 2022/02/16 23:54:06 2022/02/16
【摘要】 一、Frida 利用 Hopper、class-dump、ios-ssl-kill-switch、Keychain-Dumper、MachOParser 可以进行静态分析。使用 CycriptTrick...

一、Frida

  • 利用 Hopper、class-dump、ios-ssl-kill-switch、Keychain-Dumper、MachOParser 可以进行静态分析。
  • 使用 CycriptTricks(Powerful private methods)、UIButton 的sendActionsForControlEvents、DerekSelander LLDB(Python scripts to aid in your debugging sessions)、frida 可以进行动态调试分析。
  • 采用 Theos、MonkeyDev 进行开发调 试iphone/tool、iphone/tweak。
  • Frida 是一款基于 Python + javascript 的 hook 框架,通杀 android\iOS\linux\win\osx 各平台。Frida 原理是手机端安装一个 server 程序把手机端的端口转到 PC 端写的 python 脚本进行通信,而 Python 脚本中采用 javascript 语言编写 hook 代码。

① install frida on device

  • Start Cydia and add Frida’s repository by navigating to Manage -> Sources -> Edit -> Add and entering https://build.frida.re
  • apt-get update:
-rwxr-xr-x 1 root wheel 11292672 Oct 14 00:54 /usr/sbin/frida-server*
-rw-r--r-- 1 root wheel 779 Oct 14 00:54 /Library/LaunchDaemons/re.frida.server.plist

  
 
  • 1
  • 2

② install frida on mac

  • 安装 pip, pip 是 Python 的包管理工具:
$ sudo easy_install pip

  
 
  • 1
  • 安装:
$ sudo -H pip install frida

  
 
  • 1
  • 升级 frida:
$ sudo pip install --upgrade frida --ignore-installed six

  
 
  • 1
  • 通过 USB 连接设备,确保 Frida 正常工作:
-U, --usb  connect to USB device -a, --applications  list only applications -i, --installed  include all installed applications

  
 
  • 1
$  frida-ps -Uai
PID  Name          Identifier                 
---  ------------  ---------------------------
904  Cydia         com.saurik.Cydia           
856  微信            com.tencent.xin            
858  邮件            com.apple.mobilemail       
App Store     com.apple.AppStore         

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

③ debug

  • pdb.py can be invoked as a script to debug other scripts:
$ python -m pdb  ./dump.py 微信
> /Users/devzkn/Downloads/kevin-software/ios-Reverse_Engineering/frida-ios-dump-master/dump.py(7)<module>()
-> import sys

  
 
  • 1
  • 2
  • 3
  • pdb 常用命令:
(Pdb) h
Documented commands (type help <topic>):
========================================
EOF    bt         cont      enable  jump  pp       run      unt   
a      c          continue  exit    l     q        s        until 
alias  cl         d         h       list  quit     step     up    
args   clear      debug     help    n     r        tbreak   w     
b      commands   disable   ignore  next  restart  u        whatis
break  condition  down      j       p     return   unalias  where 

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 说明:
break 或 b: 设置断点 设置断点
continue 或 c: 继续执行程序
list 或 l: 查看当前行的代码段
step 或 s: 进入函数
return 或 r: 执行代码直到从当前函数返回
exit 或 q: 中止并退出
next 或 n: 执行下一行
pp : 打印变量的值

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
(Pdb) pp os.getcwd()
'/Users/devzkn/Downloads/kevin\xef\xbc\x8dsoftware/ios-Reverse_Engineering/frida-ios-dump-master'

  
 
  • 1
  • 2
  • 打印汉字:
(Pdb) print sys.argv
['./dump.py', '\xe5\xbe\xae\xe4\xbf\xa1']
(Pdb) print sys.argv[1]
微信

  
 
  • 1
  • 2
  • 3
  • 4

④ 利用 frida 进行 dump

  • frida-ios-dump :https://github.com/zhangkn/frida-ios-dump
    • 安装上面步骤 install frida on device and mac;
    • 使用 usbmuxd 进行端口转发,本地端口 2222,转发到 iOS 的 22 端口;
    • 执行 dump.py。
devzkndeMacBook-Pro:bin devzkn$ frida-ps -Uai
 PID  Name          Identifier                 
----  ------------  ---------------------------
1314  App Store     com.apple.AppStore         
2151  微信            com.tencent.xin            
2183  淘宝联盟          com.alimama.moon           
1309  设置            com.apple.Preferences      

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 必须在 dump.py 所在的目录下执行,即使使用 ln -l 也会失败:
devzkndeMacBook-Pro:frida-ios-dump-master devzkn$ ./dump.py 驱蚊大咖
open target  app......
start dump target app......

  
 
  • 1
  • 2
  • 3

二、常见问题

① Operation not permitted

  • Operation not permitted: /var/folders/6t/h404bjcd5tb_4q86tpv_251rv_0h0j/T/pip-sYsqDS-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info;
  • This is because OS X El Capitan ships with six 1.4.1 installed already and when it attempts to uninstall it (because awscli depends on botocore, botocore depends on python-dateutil, and python-dateutil depends on six >= 1.5) it doesn’t have permission to do so because System Integrity Protection doesn’t allow even root to modify those directories.
$ sudo -H pip install --ignore-installed six

  
 
  • 1
  • 检测 frida-server 没有启动:
iPhone:/usr/sbin root# killall SpringBoard
iPhone:/usr/sbin root# ps -e |grep frida-server
 2290 ttys000    0:00.01 grep frida-server

  
 
  • 1
  • 2
  • 3

② frida Failed to spawn 的替代方案

  • 先使用 frida-ps -Uai 查看 PID;
  • 使用 frida -p attach:
$ frida -U -p 1262
     ____
    / _  |   Frida 10.6.27 - A world-class dynamic instrumentation framework
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at http://www.frida.re/docs/home/
                                                                                
[iPhone::PID::1262]-> 

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

③ 使用中文路径导致 frida-ios-dump 失败

  • 具体的问题分析过程:
(Pdb) l
108    script = loadJsFile(session, APP_JS);
109    name = target.decode('utf8');
110    script.post(name);
111    opened.wait();
112    session.detach();
113  ->  createDir(os.getcwd()+"/"+OUTPUT)
114    print "start dump target app......"
115    session = device.attach(name);
116    script = loadJsFile(session, DUMP_JS);
117    script.post("dump");
118    finished.wait();
(Pdb) s
--Return--
> /Users/devzkn/Downloads/kevin-software/ios-Reverse_Engineering/frida-ios-dump-master/dump.py(113)main()->None
-> createDir(os.getcwd()+"/"+OUTPUT)
(Pdb) l
108    script = loadJsFile(session, APP_JS);
109    name = target.decode('utf8');
110    script.post(name);
111    opened.wait();
112    session.detach();
113  ->  createDir(os.getcwd()+"/"+OUTPUT)
114    print "start dump target app......"
115    session = device.attach(name);
116    script = loadJsFile(session, DUMP_JS);
117    script.post("dump");
118    finished.wait();
(Pdb) s
UnicodeDecodeError: UnicodeD...ge(128)')
> /Users/devzkn/Downloads/kevin-software/ios-Reverse_Engineering/frida-ios-dump-master/dump.py(127)<module>()
-> main(sys.argv[1])
(Pdb) l
122    if len(sys.argv) < 2:
123     print "usage: ./dump.py 微信"
124     sys.exit(0)
125    else:
126     try:
127  ->    main(sys.argv[1])
128     except KeyboardInterrupt:
129      if session:
130       session.detach()
131      sys.exit()
132     except:
(Pdb) s
> /Users/devzkn/Downloads/kevin-software/ios-Reverse_Engineering/frida-ios-dump-master/dump.py(128)<module>()
-> except KeyboardInterrupt:
(Pdb) pp UnicodeDecodeError
<type 'exceptions.UnicodeDecodeError'>

  
 
  • 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
  • 创建目录命名最好使用英文,否则脚本不支持中文路径的话,就容易出问题;比如 frida-ios-dump 就不支持存储路径是中文的。

文章来源: blog.csdn.net,作者:Serendipity·y,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/Forever_wj/article/details/120916255

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。