DCOM 使用 RPC_C_IMP_LEVEL_IDENTIFY 作为默认模拟级别,用于默认的出站 IUnknown 调用,参见 https://learn.microsoft.com/en-us/windows/win32/com/com-security-defaults。当然,COM 服务器可以通过显式调用 CoInitializeSecurity 来覆盖该设置。
我们知道大多数 Windows 服务注册其 DCOM 服务器以提供功能,共享进程服务 由 svchost 承载,并从注册表读取默认模拟级别。
如果我们通过某个 DCOM 调用将恶意的 IUnknown 对象作为参数传递,服务进程将对 ProxyObject 调用 IRemUnknown::RemQueryInterface/RemRelease/RemAddref,此时由于我们是 DCOM Server,便可以通过 CoImpersonateClient 获得 SecurityImpersonation 令牌。
以下是默认安装中 ImpersonationLevel 被显式设置为 RPC_C_IMP_LEVEL_IMPERSONATE 的情况:
#after 12r2
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Svchost\print@ImpersonationLevel
#2022 only
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Svchost\McpManagementServiceGroup@ImpersonationLevel
这些服务分别是 PrinterNotify 和 McpManagementService,以 SYSTEM 身份运行。
请注意,此代码仅支持 x64 和 NetFX 4.x,但您可以稍作修改以兼容 FX2.0/x86(IUnknown vtbl hook,参见 McpManagementPotato)。
csc /unsafe PrinterNotifyPotato.cs
csc /unsafe McpManagementPotato.cs
McpManagementPotato/PrinterNotifyPotato <command>


感谢 UnmarshalPwn!
(还有我爱我的猫 Vanilla,有人能把它变成猫娘吗?)