-
-
[翻译]CVE-2018–8412: Office 2016 for Mac通过旧版程序包进行权限升级
-
2018-9-11 22:17 5078
-
补丁已发布,请将您的MAU (Microsoft AutoUpdate)升级到18081201
微软自动更新助手 (Microsoft Autoupdate Helper) 3.18(180410) + 旧版不安全SilverLight安装包权限升级漏洞(EoP)
此问题波及Microsoft Office for Mac 2016和SkypeForBusiness(16.17.0.65)
本报告涵盖两个主要缺陷:
- 代码签名校验绕过
- 不安全的安装包模块加载
XPC验证绕过
在 /Library/PrivilegedHelperTools/com.microsoft.autoupdate.helper
中有一个 XPC服务com.microsoft.autoupdate.helper
。
(XPC是OSX下的一种跨进程通信技术。 它定义了两个运行进程可以相互通信的方式。)
它基于NSXPCConnection,仅导出以下两个XPC接口:
@protocol MAUHelperToolProtocol - (void)logString:(NSString *)arg1 atLevel:(int)arg2 fromAppName:(NSString *)arg3; - (void)installUpdateWithPackage:(NSString *)arg1 withXMLPath:(NSString *)arg2 withReply:(void (^)(NSString *))arg3; @end
仅允许白名单上的有效Microsoft签名二进制文件通过:
char __cdecl -[MAUHelperTool listener:shouldAcceptNewConnection:](MAUHelperTool *self, SEL a2, id a3, id a4) { ... caller_pid = (unsigned __int64)objc_msgSend(v6, "processIdentifier", self); ksecguestattrpid = kSecGuestAttributePid; number_with_pid = objc_msgSend(&OBJC_CLASS___NSNumber, "numberWithInt:", caller_pid); pid_as_nsnumber = objc_retainAutoreleasedReturnValue(number_with_pid); _dict = objc_msgSend( &OBJC_CLASS___NSDictionary, "dictionaryWithObjects:forKeys:count:", &pid_as_nsnumber, &ksecguestattrpid, 1LL); attributes = objc_retainAutoreleasedReturnValue(_dict); objc_release(pid_as_nsnumber); guest_code = 0LL; v12 = 0; if ( !(unsigned int)SecCodeCopyGuestWithAttributes(0LL, attributes, 0LL, &guest_code) )// kSecCSDefaultFlags { v43 = 0LL; v12 = 0; if ( !(unsigned int)SecRequirementCreateWithString( CFSTR("(identifier \"com.microsoft.autoupdate2\" or identifier \"com.microsoft.autoupdate.fba\") and anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] and certificate leaf[field.1.2.840.113635.100.6.1.13] and certificate leaf[subject.OU] = UBF8T346G9"), 0LL, &v43) ) v12 = (unsigned int)SecCodeCheckValidity(guest_code, 0LL, v43) == 0; if ( v43 ) CFRelease(v43);
以下是两种可能的绕过方式。
首先, 它使用pid(进程ID), 这是不可信任的, 因为 exec*
函数可以将本身进程替换成另一个, 同时保持pid不变。详细内容请见 MacOS/iOS用户空间权利指派检查非常宽松 and 别信任进程ID!
实际上这种方式是不可行的。 当调用者尝试替换自身时,将调用失效处理程序,这会导致[MAUHelperTool shouldExit]
方法返回true。
v30 = _NSConcreteStackBlock; v31 = -1040187392; v32 = 0; v33 = sub_100002748; v34 = &unk_100008440; v19 = (void *)objc_retain(v27, v7); v35 = v19; objc_copyWeak(&v36, &v43); objc_msgSend(v7, "setInvalidationHandler:", &v30); v20 = objc_msgSend(v19, "loggingConnections"); v21 = (void *)objc_retainAutoreleasedReturnValue(v20); objc_msgSend(v21, "performSelectorOnMainThread:withObject:waitUntilDone:", "addObject:", v7, 1LL); objc_release(v21); __int64 __fastcall sub_100002748(__int64 a1) { void *v1; // rax void *v2; // r14 __int64 v3; // rbx v1 = objc_msgSend(*(void **)(a1 + 32), "loggingConnections"); v2 = (void *)objc_retainAutoreleasedReturnValue(v1); v3 = objc_loadWeakRetained(a1 + 40); objc_msgSend(v2, "performSelectorOnMainThread:withObject:waitUntilDone:", "removeObject:", v3, 1LL); objc_release(v3); return objc_release(v2); }
然后主事件循环将终止该进程。 所以这是不可行的。
但另一种方法是使用DYLD_ *
环境变量生成一个有效的进程,以启用动态代码注入。
由于以下文件不受保护,因此可以滥用它们来绕过签名检查。
/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app/Contents/MacOS/Microsoft AutoUpdate
/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app/Contents/MacOS/Microsoft AU Daemon.app/Contents/MacOS/Microsoft AU Daemon
可以使用下面任一方法来保护这些二进制文件:
- 库验证, 将
-o library
添加到 "Other Code Signing Flags" - MachO 文件包含名为
__RESTRICT
或__restrict
的部分 - MachO 文件使用权利指派签名
所以现在我可以与XPC通信。
弄乱log(日志)是没用的。 - [MAUHelperTool installUpdateWithPackage:withXMLPath:withReply:]
接受来自XPC客户端的路径并安装它。 但它会锁定程序包并在包上执行数字签名验证!
旧版SilverLight程序包的不安全模块加载
我无法绕过pkg文件上的签名验证,这个问题似乎无法解决。
我做出了决定:不要绕过。
在检查了一些有效的包之后,我找到了旧版的SilverLight的安装包:https://www.microsoft.com/getsilverlight/Get-Started/Install/Default
这个安装包当然是被信任的:
$ pkgutil --check-sign /Volumes/Silverlight/silverlight.pkg Package "silverlight.pkg": Status: signed by a certificate trusted by Mac OS X Certificate Chain: 1. Developer ID Installer: Microsoft Corporation (UBF8T346G9) SHA1 fingerprint: 9B 6B 91 3B B1 3F 68 26 12 20 EC 72 11 F0 F2 0E 92 E4 B1 EB ----------------------------------------------------------------------------- 2. Developer ID Certification Authority SHA1 fingerprint: 3B 16 6C 3B 7D C4 B7 51 C9 FE 2A FA B9 13 56 41 E3 88 E1 86 ----------------------------------------------------------------------------- 3. Apple Root CA SHA1 fingerprint: 61 1E 5B 66 2C 59 3A 08 FF 58 D1 4A E2 24 52 D1 98 DF 6C 60
post-install脚本引起了我的注意。
设置全局写入权限:
pushd /Library/Internet\ Plug-Ins/ rm -rf WPFe.plugin/ chown -R root:admin Silverlight.plugin/ chmod -R 775 Silverlight.plugin/ popd pushd /Library/Application\ Support/Microsoft/ chown -R root:admin Silverlight/ chmod -R 775 Silverlight/ popd pushd /Library/Application\ Support/ chown root:admin Microsoft/ chmod 775 Microsoft/
有意思的命令:
_PRIBX=`ls -r "/Library/Application Support/Microsoft/PlayReady/Cache" | grep .key | awk '{if (NR==1) {print $1}}' ` if [ "$_PRIBX" ] then _PRIBXVER=`./PlayReadyGetIBXVersionTool "/Library/Application Support/Microsoft/PlayReady/Cache/"$_PRIBX` if [ "$_PRIBXVER" = "mspribx.1.5.8" ] pushd "/tmp/SilverlightInstallTools" _SPRDResult=`./rundylib "/Library/Internet Plug-Ins/Silverlight.plugin/Contents/MacOS/SLMSPRBootstrap.dylib"`
(在之前的chmod命令后,它是可写入的)
所以它们起到什么作用呢?
rundylib
, 就如它名字所示
int __cdecl main(int argc, const char **argv, const char **envp) { ... v3 = argv[1]; if ( !v3 ) { puts("ERROR: Invalid path "); return 1; } v5 = dlopen(v3, 5); }
那么PlayReadyGetIBXVersionTool呢?
signed int __cdecl GetDyLibVersion(const char *path, unsigned int *a2, unsigned int *a3, unsigned int *a4) { ... handle = dlopen(path, 1); if ( handle ) { v6 = _dyld_image_count(); for ( i = 0; ; ++i ) { if ( i == v6 ) goto LABEL_22; v8 = _dyld_get_image_name(i); if ( !v8 ) { v9 = dlerror(); printf("Image name not found or index out of range. Error: %s\n", v9); v5 = 5; goto LABEL_21; } if ( !strcmp(v8, path) ) break; } v10 = _dyld_get_image_header(i); if ( !v10 ) {
它在特权进程中从“Cache”加载并执行共享库,只是为了获得版本信息。
/Library/Internet Plug-Ins/Silverlight.plugin/Contents/MacOS/SLMSPRBootstrap.dylib
和 /Library/Application Support/Microsoft/PlayReady/Cache
均可由非特权用户写入。但前者需要条件竞争,我更喜欢稳定的漏洞。
漏洞利用
因此,这个漏洞利用非常简单。
- 将
DYLD_INSERT_LIBRARIES
注入 "Microsoft AutoUpdate" - 将不安全的SilverLight安装包放在某处, 发送 XPC 到 updaterhelper以请求安装
- 创建缓存文件夹并将共享库放置在root context中
- 安装包被执行,我们的恶意代码由rooted进程加载
演示 (注意此为Youtube视频,考虑翻墙观看):
https://youtu.be/EmVmLuX6TS4
原文链接:https://medium.com/0xcc/cve-2018-8412-ms-office-2016-for-mac-privilege-escalation-via-a-legacy-package-7fccdbf71d9b
翻译: 看雪翻译小组 一壶葱茜
校对: 看雪翻译小组 Nxe# hello
[培训]内核驱动高级班,冲击BAT一流互联网大厂工 作,每周日13:00-18:00直播授课