當前位置:
首頁 > 新聞 > CVE-2018-8412:通過MS Office for Mac的Legacy Package進行提權

CVE-2018-8412:通過MS Office for Mac的Legacy Package進行提權

註:補丁已經發布,請及時將你的MAU升級到18081201


Microsoft Autoupdate Helper 3.18(180410) + legacy SilverLight insecure installer package EoP


影響範圍:

Microsoft Office for Mac 2016和SkypeForBusiness(16.17.0.65)


本報告中涉及兩個主要缺陷:


1.代碼簽名驗證繞過;


2.不安全的installer模塊載入。


XPC 驗證繞過


在/Library/PrivilegedHelperTools/com.microsoft.autoupdate.helper中有一個XPC服務com.microsoft.autoupdate.helper。


該服務是基於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

在XPC建立連接的時候,會檢查對方pid對應的代碼簽名是否在白名單列表之內:

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這是不可信任的,因為exec*函數可以將進程本身替換為另一個進程,且可以保持前一個pid不變。具體請參閱 MacOS/iOS userspace entitlement checking is racy和Don』t Trust the PID!


實際上這種方法是不可利用的。當調用者嘗試替換自身時,失效的處理程序會被調用,這會導致[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_* env spawn一個有效進程來啟用動態代碼注入。


由於以下文件不受保護,因此可以濫用它們來繞過簽名檢查:

/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

如果你想要保護這些二進位文件,可以使用以下任一方法:



1.庫驗證,將-o library添加到「Other Code Signing Flags」;


2.macho文件的Header中有名為

RESTRICT的Segment段,且該段有名為

restrict的sections,則macho就會阻止進程的依附。


3.使用entitlements簽名MachO文件。


現在,我已具備與XPC通信的能力。


MAU 提供的介面有一個 - [MAUHelperTool installUpdateWithPackage:withXMLPath:withReply:],它接受來自XPC客戶端的路徑並會安裝它,但它會鎖定包文件並在包上執行數字簽名驗證!



legacy SilverLight package 中不安全的模塊載入


我無論如何都無法繞過pkg文件上的簽名驗證。因此,我決定放棄對它的繞過。


在檢查了一些有效包之後,我找到了legacy SilverLight installer: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"`

以及使用rundylib打開一個固定路徑的鏈接庫。


這個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
", 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

均可由非特權用戶寫入。但替換SLMSPRBootstrap.dylib需要條件競爭,比較難以控制;而Cache則不存在這個問題。


利用

利用步驟如下:


1.DYLD_INSERT_LIBRARIES注入「Microsoft AutoUpdate」;


2.將易受攻擊的SilverLight installer放置在某路徑下,發送XPC到updaterhelper請求安裝;


3.創建cache文件夾,並將共享庫放置在root目錄中;


4.安裝程序被執行,我們的惡意代碼則將由rooted進程載入。


Demo



*參考來源:medium,FB小編secist編譯,轉載請註明來自FreeBuf.COM


喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 FreeBuf 的精彩文章:

BlackHat 2018 | 將亮相的10款網路終端安全產品

TAG:FreeBuf |