MASTG-TOOL-0046: Cycript

已弃用的工具

此工具已弃用,不应再使用。

原因: Cycript 不再积极维护,并且在现代 iOS 版本上失效。它最后一次有意义的更新是在 2009 年至 2013 年之间。由于 Cydia Substrate 的更改,像 cynject 这样的关键组件在 2019 年左右的 iOS 12 上中断,并且尚未修复。 Frida 提供了更广泛的兼容性、主动支持和更强大的动态检测功能。

替代方案:

Cycript 是 Jay Freeman (又名 Saurik) 开发的一种脚本语言。 它将 JavaScriptCore 虚拟机注入到正在运行的进程中。 使用 Cycript 交互式控制台,用户可以使用混合 Objective-C++ 和 JavaScript 语法来操作进程。 支持访问和实例化正在运行的进程中的 Objective-C 类。 可以使用 Cydia Substrate 将 Cycript 注入到正在运行的进程中,类似于调试器,Cydia Substrate 是开发 Cydia 运行时补丁的标准框架,这些补丁在 iOS 上称为 Cydia Substrate 扩展。 它包括 Cynject,这是一种为 Cycript 提供代码注入支持的工具。

为了安装 Cycript,首先下载、解压并安装 SDK。

#on iphone
$ wget https://cydia.saurik.com/api/latest/3 -O cycript.zip && unzip cycript.zip
$ sudo cp -a Cycript.lib/*.dylib /usr/lib
$ sudo cp -a Cycript.lib/cycript-apl /usr/bin/cycript

要生成交互式 Cycript shell,请运行 "./cycript",或者如果 Cycript 在您的路径上,则运行 "cycript"。

$ cycript
cy#

要注入到正在运行的进程中,我们首先需要找到进程 ID (PID)。 运行该应用程序并确保该应用程序位于前台。 运行 cycript -p <PID> 会将 Cycript 注入到该进程中。 为了说明,我们将注入到 SpringBoard(它始终在运行)。

$ ps -ef | grep SpringBoard
501 78 1 0 0:00.00 ?? 0:10.57 /System/Library/CoreServices/SpringBoard.app/SpringBoard
$ ./cycript -p 78
cy#

您可以尝试的第一件事是获取应用程序实例 (UIApplication),您可以使用 Objective-C 语法

cy# [UIApplication sharedApplication]
cy# var a = [UIApplication sharedApplication]

现在使用该变量来获取应用程序的委托类

cy# a.delegate

让我们尝试使用 Cycript 在 SpringBoard 上触发警报消息。

cy# alertView = [[UIAlertView alloc] initWithTitle:@"OWASP MASTG" message:@"Mobile Application Security Testing Guide"  delegate:nil cancelButtonitle:@"OK" otherButtonTitles:nil]
#"<UIAlertView: 0x1645c550; frame = (0 0; 0 0); layer = <CALayer: 0x164df160>>"
cy# [alertView show]
cy# [alertView release]

使用 Cycript 查找应用程序的文档目录

cy# [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask][0]
#"file:///var/mobile/Containers/Data/Application/A8AE15EE-DC8B-4F1C-91A5-1FED35212DF/Documents/"

命令 [[UIApp keyWindow] recursiveDescription].toString() 返回 keyWindow 的视图层次结构。 显示了 keyWindow 的每个子视图和子子视图的描述。 缩进空格反映了视图之间的关系。 例如,UILabelUITextFieldUIButtonUIView 的子视图。

cy# [[UIApp keyWindow] recursiveDescription].toString()
`<UIWindow: 0x16e82190; frame = (0 0; 320 568); gestureRecognizers = <NSArray: 0x16e80ac0>; layer = <UIWindowLayer: 0x16e63ce0>>
  | <UIView: 0x16e935f0; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x16e93680>>
  |    | <UILabel: 0x16e8f840; frame = (0 40; 82 20.5); text = 'i am groot!'; hidden = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x16e8f920>>
  |    | <UILabel: 0x16e8e030; frame = (0 110.5; 320 20.5); text = 'A Secret Is Found In The ...'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x16e8e290>>
  |    | <UITextField: 0x16e8fbd0; frame = (8 141; 304 30); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x16e94550>; layer = <CALayer: 0x16e8fea0>>
  |    |    | <_UITextFieldRoundedRectBackgroundViewNeue: 0x16e92770; frame = (0 0; 304 30); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x16e92990>>
  |    | <UIButton: 0x16d901e0; frame = (8 191; 304 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x16d90490>>
  |    |    | <UIButtonLabel: 0x16e72b70; frame = (133 6; 38 18); text = 'Verify'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x16e974b0>>
  |    | <_UILayoutGuide: 0x16d92a00; frame = (0 0; 0 20); hidden = YES; layer = <CALayer: 0x16e936b0>>
  |    | <_UILayoutGuide: 0x16d92c10; frame = (0 568; 0 0); hidden = YES; layer = <CALayer: 0x16d92cb0>>`

您还可以使用 Cycript 的内置函数,例如 choose,它会在堆中搜索给定 Objective-C 类的实例

cy# choose(SBIconModel)
[#"<SBIconModel: 0x1590c8430>"]

Cycript 手册 中了解更多信息。