UAC Bypass - CMSTPLUA COM Exploitation

COM is a binary standard (not a language or an API library) that defines how compiled objects expose functionality through interfaces (pointer-based function tables), so that objects regardless of the language they were written in, can call each other's methods. In order to access functions in the interface, one has to get the pointer to that particular interface (which is pointer to array of pointers of member functions called pVtbl) in COM class.
A COM class can be identified using CLSID which is a GUID (i.e. no other class can have same CLSID) which associates with a DLL or EXE on windows. And Interface in COM class is identified using IID which is also a GUID . Check the registry hive HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\UAC\COMAutoApprovalList which contains autoelevated COM objects.

Windows exposes several COM objects that perform elevated operations through UAC (User Access Control) elevation mechanism. From one of them is CMSTPLUA implemented in cmlua.dll which exposes a interface ICMLuaUtil with one of a method ShellExec which is leveraged to execute shell commands with higher privilege that bypass UAC because autoapproval is set to true.
Using OleView we can see exposed interface by CMSTPLUA COM class object, it can be seen in properties that both Elevation and AutoApproval are set to True .


If we try to see definition of ICMLuaUtil Interface which inherits IUnknown interface (a mandatory fundamental interface in COM exposing QueryInterface(), AddRef(), and Release() methods), it lists some public methods which we will see later in IDA for their naming.

Loading C:\Windows\System32\cmlua.dll in IDA, we can see the vftable which holds the pointer virtual methods of the CCMLuaUtil class and the first three methods are from the IUnknown interface but our point of interest is ShellExec method which is the 7th method in class. With that we have also identified the CLSID and IID for it.


From vftable we have recovered the structure of ShellExec which expects a pointer to SHELLEXECUTEINFOW structure.

Now inorder to execute a shell with Admin privilege, COM client needs to request elevation using the elevation moniker, also elevation requires COM class to be configured to support it as we have seen above in OleView.
Implementation
We are going to achieve this via DLL injection, injecting our crafted dll with a simple loader into explorer.exe .
Here is our elevated prompt :)

References
https://github.com/0xSec1/UAC-Bypass - Source Code
https://gist.github.com/hfiref0x/196af729106b780db1c73428b5a5d68d
https://learn.microsoft.com/en-us/windows/win32/com/com-fundamentals
Last updated