After a successful call to both LogonUser and ImpersonateLoggedOnUser it doesn't appear that my process is running as the new user...
system("whoami");
prints out: Chris-PC\Chris
when it should be: Chris-PC\LimitedGuy
Is there a function I'm not calling or something?
My code:
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");
}