c++ - ImpersonateLoggedOnUser 似乎不起作用

标签 c++ winapi authentication impersonation

成功调用 LogonUser 和 ImpersonateLoggedOnUser 后,我的进程似乎没有作为新用户运行...

系统(“我是谁”);

打印出来: 克里斯-PC\克里斯

什么时候应该: 克里斯-PC\LimitedGuy

有没有我没有调用的函数之类的?

我的代码:

if(argc == 6) // impersonate
        {

            printf("[~] Logging in as %ws\\\\%ws..\n", argv[3], argv[4]);
            if(!LogonUser(argv[4], argv[3], argv[5], LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &logonToken))
            {
                printf("[!] Failed to login as %ws. Error Code: %X\n", argv[4], GetLastError());
                return 1;
            }


            if(!ImpersonateLoggedOnUser(logonToken))
            {
                printf("[!] ImpersonateLoggedOnUser failed with error code: %X\n", GetLastError());
                return 1;
            }

            LoadUserProfile(logonToken, &plinfo);
            system("whoami");
            printf("[~] Login successful!\n");
} 

最佳答案

当您使用系统调用时,会创建一个新进程来执行命令,但在 Windows 中,新进程始终是使用来自父进程而不是线程的 token 创建的(除非您专门使用 CreateProcessAsUser、CreateProcessWithLogonW 等之一. 电话)。因此,在您的情况下,“whoami”是在原始用户的上下文中执行的,而不是在模拟用户的上下文中执行的。要检查被模拟的用户的名称,请调用 GetUserName。

关于c++ - ImpersonateLoggedOnUser 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1552098/

相关文章:

C++ 字典 API

c++ - Qt - 更新 PaintGL

c++ - YouCompleteMe 无法自动完成

c# - 如何在 ListView 控件 header 上复制 Windows 资源管理器列筛选

c++ - boost asio 读缓冲区

c++ - VC++ win32 API编程 : how can I get the image out of the clipboard and display it in a windows?

c++ - IDC 是什么意思?

authentication - 使用 JWT 使用 Asp.net 核心进行 GraphQL 身份验证

Java : How setup an SSL One-Way authentification for a server-client over a LAN?

.net - .NET FormsAuthentication.Encrypt() 方法使用什么加密方法?