gpt4 book ai didi

iphone - 在运行时检测 iPhone 上的 UDID 欺骗

转载 作者:行者123 更新时间:2023-12-03 18:19:13 25 4
gpt4 key购买 nike

越狱的 iPhone 让我很恼火,因为它通过使用 MobileSubstrate 污染了 iOS 上的一些基本 API。

http://www.iphonedevwiki.net/index.php/MobileSubstrate

我相信许多应用程序使用 UDID 作为验证设备和/或用户的方式,因为它是半自动且方便的,但您应该意识到这个问题:UIDevice 并不像应有的那样防篡改。有一个名为 UDID Faker 的应用程序,它可以让您轻松地在运行时欺骗别人的 UDID。

http://www.iphone-network.net/how-to-fake-udid-on-ios-4/

这是它的源代码:

//
// UDIDFaker.m
// UDIDFaker
//

#include "substrate.h"

#define ALog(...) NSLog(@"*** udidfaker: %@", [NSString stringWithFormat:__VA_ARGS__]);
#define kConfigPath @"/var/mobile/Library/Preferences/com.Reilly.UDIDFaker.plist"

@protocol Hook
- (NSString *)orig_uniqueIdentifier;
@end

NSString *fakeUDID = nil;

static NSString *$UIDevice$uniqueIdentifier(UIDevice<Hook> *self, SEL sel) {

if(fakeUDID != nil) {
ALog(@"fakeUDID %@", fakeUDID);
/* if it's a set value, make sure it's sane, and return it; else return the default one */
return ([fakeUDID length] == 40) ? fakeUDID : [self orig_uniqueIdentifier];

}
/* ... if it doesn't then return the original UDID */
else {
return [self orig_uniqueIdentifier];
}
}

__attribute__((constructor)) static void udidfakerInitialize() {

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *appsBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
ALog(@"Loading UDID Faker into %@", appsBundleIdentifier);


NSDictionary *config = [NSDictionary dictionaryWithContentsOfFile: kConfigPath];
fakeUDID = [config objectForKey: appsBundleIdentifier];
[fakeUDID retain];

if(fakeUDID != nil) {

ALog(@"Hooking UDID Faker into %@", appsBundleIdentifier);
MSHookMessage(objc_getClass("UIDevice"), @selector(uniqueIdentifier), (IMP)&$UIDevice$uniqueIdentifier, "orig_");
}

[pool release];
}

如您所见,UIDevice 类中的 uniqueIdentifier 方法现在会在任何应用程序上返回 fakeUDID。

Skype 和其他一些应用程序似乎可以检测到这种污点,但我不知道该怎么做。

我想做的是:当启动时检测到受污染的 UIDevice 时,发出警报并退出(0)。

想法?

最佳答案

没有真正安全的方法来检查 UDID 是否真实。 UDID 是通过 liblockdown 获取的,它通过安全通道与lockdownd 通信以接收 UDID:

+-----------+
| your code |
+-----------+
|
+----------+ +-------------+ +-----------+
| UIDevice |<----->| liblockdown |<=====>| lockdownd | (trusted data)
+----------+ +-------------+ +-----------+
untrusted user trusted user

设备越狱后,4个组件均可更换。

<小时/>

检测 UDID Faker 是否存在的一种方法是检查其特有的某些标识(文件、函数等)是否存在。这是一种非常具体且脆弱的反击,因为当检测方法暴露时,欺骗者可以简单地改变标识来隐藏自己的存在。

例如,UDID Faker 依赖于 plist 文件 /var/mobile/Library/Preferences/com.Reilly.UDIDFaker.plist。因此,您可以检查该文件是否存在:

NSString* fakerPrefPath = @"/var/mobile/Library/Preferences/com.Reilly.UDIDFaker.plist";
if ([[NSFileManager defaultManager] fileExistsAtPath:fakerPrefPath])) {
// UDID faker exists, tell user the uninstall etc.
}

它还定义了方法-[UIDevice orig_uniqueIdentifier],可用于绕过伪造者:

UIDevice* device = [UIDevice currentDevice];
if ([device respondsToSelector:@selector(orig_uniqueIdentifier)])
return [device orig_uniqueIdentifier];
else
return device.uniqueIdentifier;

当然,欺骗者可以简单地重命名这些东西。

<小时/>

更可靠的方法在于 Mobile Substrate 的工作原理。注入(inject)的代码必须位于 dylib/bundle 中,该代码加载到与 UIKit 不同的内存区域中。因此,您只需检查-uniqueIdentifier方法的函数指针是否在可接受的范围内即可。

// get range of code defined in UIKit 
uint32_t count = _dyld_image_count();
void* uikit_loc = 0;
for (uint32_t i = 0; i < count; ++ i) {
if (!strcmp(_dyld_get_image_name(i), "/System/Library/Frameworks/UIKit.framework/UIKit")) {
uikit_loc = _dyld_get_image_header(i);
break;
}
}

....

IMP funcptr = [UIDevice instanceMethodForSelector:@selector(uniqueIdentifier)];
if (funcptr < uikit_loc) {
// tainted function
}
<小时/>

无论如何,UDID Faker 是一个非常高级的黑客(即它可以很容易地避免)。它通过提供虚假 ID 劫持 UIDevice 和 liblockdown 之间的链接。

+-----------+
| your code |
+-----------+
|
+----------+ +-------------+ +-----------+
| UIDevice |<--. | liblockdown |<=====>| lockdownd | (trusted data)
+----------+ | +-------------+ +-----------+
| +------------+
‘-->| UDID Faker |
+------------+

因此,您可以将询问 UDID 的代码移至 liblockdown 级别。这可用于越狱平台的应用程序,但这不适用于 AppStore 应用程序,因为 liblockdown 是私有(private) API。此外,欺骗者还可以劫持 liblockdown(这很容易,我希望没有人这么做),甚至可以替换 lockd 本身。

                   +-----------+
| your code |
+-----------+
|
+----------+ +-------------+ +-----------+
| UIDevice |<--. | liblockdown |<=====>| lockdownd | (trusted data)
+----------+ | +-------------+ +-----------+
| +------------+
‘-->| UDID Faker |
+------------+

(我不会在这里展示如何使用 liblockdown。您应该能够从您链接到的网站找到足够的信息。)

关于iphone - 在运行时检测 iPhone 上的 UDID 欺骗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4165138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com