ImpersonateLoggedOnUser 之后 OpenProcessToken 失败
我有一项冒充用户的服务。该服务作为本地系统运行。该用户是本地管理员和域管理员。模拟之后,我需要调整进程的令牌权限。我希望使用 OpenProcessToken
来完成此操作,然后在返回的令牌句柄上使用 AdjustTokenPrivileges
来完成此操作。
调用 LogonUser
和 ImpersonateLoggedOnUser
后,以下调用因访问被拒绝而失败。
HANDLE hToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
{
Log("Error=%d", GetLastError());
}
我正在使用 LOGON32_LOGON_INTERACTIVE
和 LOGON32_PROVIDER_DEFAULT
登录用户。
对用户令牌调整相同权限成功。
I have a service that is impersonating a user. The service is running as Local System. The user is a local administrator and domain administrator. After impersonation, it's necessary for me to adjust the token privileges of the process. I hoped to do it using OpenProcessToken
and then AdjustTokenPrivileges
on the returned token handle.
After calling LogonUser
and ImpersonateLoggedOnUser
the following call is failing with access denied.
HANDLE hToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
{
Log("Error=%d", GetLastError());
}
I'm logging on the user using LOGON32_LOGON_INTERACTIVE
and LOGON32_PROVIDER_DEFAULT
.
Adjusting the same privilege on the user token succeeds.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个由两部分组成的答案,具体取决于您想要执行的操作:
1)如果您想调整模拟令牌的权限,您需要使用 OpenThreadToken 函数,而不是 OpenProcessToken。模拟影响的是线程,而不是整个进程。试试这个:
2) 如果您确实想要调整进程令牌的权限,您可能应该在不模拟客户端时执行此操作。您可以根据需要打开和关闭模拟。
This is a two-part answer, depending on what you are trying to do:
1) If you want to adjust the privileges for the impersonation token, you need to use the OpenThreadToken function, not OpenProcessToken. Impersonation affects the thread, not the process as a whole. Try this:
2) If you really did want to adjust the privileges for the process token, you should probably do this at a point when you are not impersonating the client. You can turn impersonation on and off as necessary.