没有SeImpersonatePrivilege的ImpersonateLoggedOnUser

时间:2014-08-05 06:30:02

标签: c++ windows winapi windows-8 impersonation

我有一个非管理员用户(没有SeImpersonatePrivilege),需要暂时模仿其他用户。根据{{​​3}}(强调我的):

如果满足下列条件之一,则所有模拟函数(包括ImpersonateLoggedOnUser)都允许请求模拟:
• The requested impersonation level of the token is less than SecurityImpersonation,
such as SecurityIdentification or SecurityAnonymous.
• The caller has the SeImpersonatePrivilege privilege.
• A process (or another process in the caller's logon session) created the token
using explicit credentials through LogonUser or LsaLogonUser function.
• The authenticated identity is same as the caller.

我正在尝试使用斜体方法。我可以使用LogonUserW创建令牌:

HANDLE token = NULL;
if (::LogonUserW(user, L".", password, LOGON32_LOGON_INTERACTIVE,
    LOGON32_PROVIDER_DEFAULT, &token))
{
    if (::ImpersonateLoggedOnUser(token))
    {
        DoOtherUserStuff();
    }
}

这称呼成功;我到达DoOtherUserStuff函数。但是,当我尝试使用我刚刚创建的令牌来执行任何需要权限检查的任务时,它就会失败。 GetLastError返回1346,即

  

未提供所需的模拟级别,或者提供的模拟级别无效。

如果您尝试使用通过其他方法(OpenThreadToken等)获得的令牌模拟其他用户并且没有SeImpersonatePrivilege,则会出现此错误。但是,我使用具有显式凭据的LogonUser创建令牌。为什么不工作? MSDN文档是错误的吗?

我尝试过使用不同的登录类型和不同的登录提供程序,但无济于事。 LOGON32_LOGON_NETWORK会按预期生成模拟令牌,但会以完全相同的方式失败。

系统是Windows 8.0企业版。呼叫者是Microsoft帐户,但登录和模拟的用户是本地帐户。

0 个答案:

没有答案
相关问题