iOS Theos & 动态调试(获取支付宝账户密码)

一、Theos配置

Theos 是一个不需要使用Xcode就能管理,开发和部署iOS软件的跨平台开发工具。进行越狱iOS开发扩展或者调整时,Theos是一件非常重要的工具,很多越狱开发都使用了这个工具。
推荐配置在自己的家目录,不要配置在/opt目录。

Theos的安装可以参考

1.1 ldid

ldid是专门用来签名iOS可执行文件的工具,用来代替Xcodecodesign。专门用于越狱插件的签名。theos开发插件依赖ldid

1.2 nic.pl

➜  ~ nic.pl
NIC 2.0 - New Instance Creator
------------------------------
  [1.] iphone/activator_event
  [2.] iphone/activator_listener
  [3.] iphone/application_modern
  [4.] iphone/application_swift
  [5.] iphone/cydget
  [6.] iphone/flipswitch_switch
  [7.] iphone/framework
  [8.] iphone/library
  [9.] iphone/notification_center_widget
  [10.] iphone/notification_center_widget-7up
  [11.] iphone/preference_bundle_modern
  [12.] iphone/theme
  [13.] iphone/tool
  [14.] iphone/tool_swift
  [15.] iphone/tweak
  [16.] iphone/tweak_with_simple_preferences
  [17.] iphone/xpc_service
Choose a Template (required):

nic.pl出现选择模板则配置成功了。

二、动态调试支付宝

2.1 动态分析支付宝登录密码

2.1.1 分析登录点击逻辑

使用手机端cycript附加支付宝进程

zaizai:~ root# cycript -p AlipayWallet
cy# HPCurrentVC()
#""
cy# #0x10bd75560.view.recursiveDescription().toString()

搜索下输入的密码123456

image.png

可以看到密码是aluTextField 0x10cadf800aluInputBox 0x121cb4b40中。

再搜索下登录(由于编码问题,先在python环境中转码再搜索):

>>> str = u"登录"
>>> str
u'\u767b\u5f55'
>>>

image.png

登录按钮是AUButton 0x12098c9c0

查看AUButton 0x12098c9c0allTargets

cy# #0x12098c9c0.allTargets
[NSSet setWithArray:@[#">",#">"]]]

一个是自己,一个是ALUAccuratePWDView 0x121cad170。也就是登录按钮点击事件调用了ALUAccuratePWDView的方法。

查看AUButton 0x12098c9c0allControlEvents

cy# #0x12098c9c0.allControlEvents
64

这里的64就是26

   UIControlEventTouchUpInside           = 1 <<  6,

查看AUButton 0x12098c9c0 调用的的ALUAccuratePWDView 0x121cad170对象的方法actionsForTarget: forControlEvent:

cy# [#0x12098c9c0 actionsForTarget:#0x121cad170 forControlEvent:64]
@["onNext"]

这样就获取到了登录按钮(AUButton)点击调用了ALUAccuratePWDViewonNext方法。
dump头文件获取onNext方法如下:

- (void)onNext;

所以Hook代码如下:

%hook ALUAccuratePWDView

- (void)onNext {
    
}

%end

2.1.2 分析密码逻辑

上面已经找到了登录按钮调用方法,接下来要分析输入框。对于输入框aluTextField 0x10cadf800aluInputBox 0x121cb4b40中。
而在ALUAccuratePWDView 0x121cad170中有如下代码:

@property(retain, nonatomic) aluLoginBox *loginBox; // @synthesize loginBox=_loginBox;

那么aluInputBox应该和aluLoginBox有关,在aluLoginBox中有如下代码:

    aluInputBox *_loginIdInputBox;
    aluInputBox *_passwordInputBox;

aluInputBox中正好有一个aluTextField

    aluTextField *_textField;

那么猜测_passwordInputBox应该就是aluInputBox 0x121cb4b40
总结:在ALUAccuratePWDView 0x121cad170 -> _loginBox -> _passwordInputBox->_textField

验证

cy# #0x121cad170->_loginBox->_passwordInputBox->_textField
#"; placeholder = \xe8\xaf\xb7\xe8\xbe\x93\xe5\x85\xa5\xe7\x99\xbb\xe5\xbd\x95\xe5\xaf\x86\xe7\xa0\x81; borderStyle = None; background = <_UITextFieldNoBackgroundProvider: 0x28319de40: textfield=>; layer = >"

aluTextField: 0x10cadf800就是密码输入框:

image.png

所以获取密码的方式为:self -> _loginBox -> _passwordInputBox->_textField
同理可以获得登录账户:self-> _labelLoginID
修改Hook代码如下:

%hook ALUAccuratePWDView

- (void)onNext {
//账户
//self-> _loginBox->_loginIdInputBox-> _textField
//密码
//self -> _labelLoginID
}

%end

2.2 Theos获取支付宝密码

2.2.1 创建Tweak工程

➜  HPProject nic.pl
NIC 2.0 - New Instance Creator
------------------------------
  [1.] iphone/activator_event
  [2.] iphone/activator_listener
  [3.] iphone/application_modern
  [4.] iphone/application_swift
  [5.] iphone/cydget
  [6.] iphone/flipswitch_switch
  [7.] iphone/framework
  [8.] iphone/library
  [9.] iphone/notification_center_widget
  [10.] iphone/notification_center_widget-7up
  [11.] iphone/preference_bundle_modern
  [12.] iphone/theme
  [13.] iphone/tool
  [14.] iphone/tool_swift
  [15.] iphone/tweak
  [16.] iphone/tweak_with_simple_preferences
  [17.] iphone/xpc_service
Choose a Template (required): 15
Project Name (required): AlipayHook
Package Name [com.yourcompany.alipayhook]: com.hotpotcat.alipayhook
Author/Maintainer Name [ZP]:
[iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]: com.alipay.iphoneclient
[iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]: AlipayWallet
Instantiating iphone/tweak in alipayhook/...
Done.
  • tweak15代表创建插件。
  • Project Name:工程名。
  • Package Name:包名称,都小写不能驼峰。
  • Author/Maintainer Name:不填默认电脑名称
  • [iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]:要附加的进程(BundleId),不写默认springboard
  • [iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]:插件安装后要杀掉的进程。默认SpringBoard。⚠️推荐给默认值,给应用进程有可能Hook失败杀不掉App

这样就创建了插件工程了。

BundleId获取

zaizai:~ root# cycript -p AlipayWallet
cy# APPID
@"com.alipay.iphoneclient"

2.2.2 Tweak工程配置

工程结构如下:

image.png

直接将工程拖到Sublime Text中:

  • .plist中是包的名称
{ Filter = { Bundles = ( "com.alipay.iphoneclient" ); }; }
  • control是关于工程配置。版本号等相关信息。
  • makefile是编译配置
    安装到手机是走的SSH安装, 需要增加配置设置IP端口号。这里配置的是走的USB
export THEOS_DEVICE_IP=localhost
export THEOS_DEVICE_PORT=12345
IP和端口号配置

可以配置到.zshrc中,这样不用每个工程都配置了。

  • Tweak.x是写logos hook代码的地方,一般会将后缀改为.xm 。需要同时修改makefileAlipayHook_FILES = Tweak.xm

2.2.3 Hook代码

#import 

%hook ALUAccuratePWDView

- (void)onNext {
    NSLog(@"\n\n\n\n\n\n");
    UIView *loginBox = MSHookIvar(self,"_loginBox");
    //账户
    //self-> _labelLoginID
    UILabel *labelLoginID = MSHookIvar(self,"_labelLoginID");
    NSString *accountStr = labelLoginID.text;
    NSLog(@"账户:%@",accountStr);
    //密码
    //self -> _loginBox -> _passwordInputBox->_textField
    UIView *passwordInputBox = MSHookIvar(loginBox,"_passwordInputBox");
    UITextField *pwdTextField = MSHookIvar(passwordInputBox,"_textField");
    NSString *pwdStr = pwdTextField.text;
    NSLog(@"密码:%@",pwdStr);
    NSLog(@"\n\n\n\n\n\n");
}

%end

2.2.4 编译、打包、安装

编译make

➜  alipayhook make
==> Notice: Build may be slow as Theos isn’t using all available CPU cores on this computer. Consider upgrading GNU Make: https://github.com/theos/theos/wiki/Parallel-Building
> Making all for tweak AlipayHook…
==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm (armv7)…
==> Linking tweak AlipayHook (armv7)…
ld: warning: building for iOS, but linking in .tbd file (/Users/zaizai/.HotpotCat/theos/vendor/lib/CydiaSubstrate.framework/CydiaSubstrate.tbd) built for iOS Simulator
==> Generating debug symbols for AlipayHook…
rm /Users/zaizai/HPProject/alipayhook/.theos/obj/debug/armv7/Tweak.xm.mm
==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm (arm64)…
==> Linking tweak AlipayHook (arm64)…
ld: warning: building for iOS, but linking in .tbd file (/Users/zaizai/.HotpotCat/theos/vendor/lib/CydiaSubstrate.framework/CydiaSubstrate.tbd) built for iOS Simulator
==> Generating debug symbols for AlipayHook…
rm /Users/zaizai/HPProject/alipayhook/.theos/obj/debug/arm64/Tweak.xm.mm
==> Merging tweak AlipayHook…
==> Signing AlipayHook…

打包make package

➜  alipayhook make package
==> Notice: Build may be slow as Theos isn’t using all available CPU cores on this computer. Consider upgrading GNU Make: https://github.com/theos/theos/wiki/Parallel-Building
> Making all for tweak AlipayHook…
make[2]: Nothing to be done for `internal-library-compile'.
> Making stage for tweak AlipayHook…
dm.pl: building package `com.hotpotcat.alipayhook:iphoneos-arm' in `./packages/com.hotpotcat.alipayhook_0.0.1-1+debug_iphoneos-arm.deb'

打包完成后生成.deb文件。

安装 make install

➜  alipayhook make install
==> Installing…
Selecting previously unselected package com.hotpotcat.alipayhook.
(Reading database ... 1927 files and directories currently installed.)
Preparing to unpack /tmp/_theos_install.deb ...
Unpacking com.hotpotcat.alipayhook (0.0.1-4+debug) ...
Setting up com.hotpotcat.alipayhook (0.0.1-4+debug) ...
==> Unloading AlipayWallet…

安装好之后正常对应的进程会被杀掉,安装的插件会出现在cydia已安装中:

AlipayHook插件

  • make编译
  • make package打包
  • make install安装
  • 工程目录中不能有中文
  • make clean清空缓存
  • 如果有多个XCode需要选择XCode
➜  alipayhook xcode-select -p
/Applications/Xcode.app/Contents/Developer
➜  alipayhook xcode-select --switch /Applications/Xcode.app/Contents/Developer

⚠️在makefile同级目录编译。
make package;make install可以同时进行。
如果安装没有杀掉进程,发现没有Hook成功,那么创建工程的时候直接
[iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]直接给默认值SpringBoard

运行

通过console查看日志看是否获取账户密码成功。

image.png

这个时候就成功获得了账号密码。

你可能感兴趣的:(iOS Theos & 动态调试(获取支付宝账户密码))