Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_user_token fails if thread is holding an impersonation token #699

Open
upsidedwn opened this issue Feb 6, 2024 · 1 comment
Open

Comments

@upsidedwn
Copy link

upsidedwn commented Feb 6, 2024

Currently, get_user_token fails if the current thread is holding an impersonation token.

meterpreter > getsid
[-] stdapi_sys_config_getsid: Operation failed: Access is denied.

Here, we see that OpenAsSelf is set to FALSE.

if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &hToken))
{
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
{
BREAK_ON_ERROR("[TOKEN] Failed to get a valid token for thread/process.");
}
}

From MSDN, we see that the call will fail.

The OpenAsSelf parameter allows the caller of this function to open the access token of a specified thread when the caller is impersonating a token at SecurityIdentification level. Without this parameter, the calling thread cannot open the access token on the specified thread because it is impossible to open executive-level objects by using the SecurityIdentification impersonation level.

Would suggest we try again if with OpenAsSelf set to TRUE, if the existing two tries fail. If this is acceptable, I can create a PR.

 if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &hToken)) 
 { 
 	if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) 
 	{ 
            if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE, &hToken)) 
            {
                BREAK_ON_ERROR("[TOKEN] Failed to get a valid token for thread/process."); 
            }
 	} 
 } 
@smcintyre-r7
Copy link
Contributor

I think that sounds like a reasonable solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants