【问题标题】:How to have service ImpersonateLoggedOnUser but with high mandatory integrity level?如何拥有服务 ImpersonateLoggedOnUser 但具有高强制性完整性级别?
【发布时间】:2010-12-21 04:34:01
【问题描述】:

根据Blocking mouse input from a service in Vista BlockInput() 需要较高的强制性完整性级别。此外,服务无法使用该功能,因为它不在桌面上运行。每当需要与桌面进行偶尔的交互时,我都会临时使用 ImpersonateLoggedOnUser() 服务,然后是 RevertToSelf() 但是,登录用户不是管理员。那么如何在某些模拟期间将完整性级别设置为高,以便可以使用 BlockInput()?我无法从 MSDN 文档中找出有关修改 ImpersonateLoggedOnUser() 采用的令牌的信息。有什么帮助吗?

谢谢

[Edit:] 尝试修改我的模拟代码如下:

以前,我有这样的代码,它模拟用户访问用户的注册表和文件(稍后使用 CreateProcessAsUser() 启动用户程序):

if (!WTSQueryUserToken(sid, &token))  throw "ERROR: Could not get logged on user token";
if (!DuplicateTokenEx(token, TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE | TOKEN_QUERY | TOKEN_ADJUST_DEFAULT | TOKEN_IMPERSONATE, 0, SecurityImpersonation, TokenPrimary, &userTok))
{
    CloseHandle(token);
    throw "ERROR: Could not duplicate user token";
}
CloseHandle(token);
if (!ImpersonateLoggedOnUser(userTok)) throw "ERROR: Could not impersonate logged on user";
... // Do stuff needing impersonation
if (!RevertToSelf()) throw "ERROR: Could not revert to self";

正在执行 BlockInput(1);睡眠(5000);在 ImpersonateLoggedOnUser() 不阻止输入之后。所以我尝试在 ImpersonateLoggedOnUser() 之前添加以下内容:

PSID sid(0);
if (!ConvertStringSidToSid(SDDL_ML_HIGH, &sid)) throw "ERROR: Could not convert string to SID";
TOKEN_MANDATORY_LABEL tml;
tml.Label.Attributes = SE_GROUP_INTEGRITY | SE_GROUP_INTEGRITY_ENABLED;
tml.Label.Sid = sid;
if (!SetTokenInformation(userTok, TokenIntegrityLevel, &tml, sizeof(tml) + GetLengthSid(sid)))) throw "ERROR: Could not set token information";
LocalFree(sid);

在执行过程中我没有收到任何错误,表明它应该设置正确。但是输入仍然没有被阻止!

【问题讨论】:

    标签: winapi authorization impersonation


    【解决方案1】:

    我最终通过以管理员用户身份从服务启动一个单独的进程来解决这个问题,并且该服务要求它阻止输入。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      • 1970-01-01
      • 2017-10-17
      • 2011-11-07
      • 1970-01-01
      • 2011-08-01
      相关资源
      最近更新 更多