[Issue] Shell commands don't use impersonated tokens
- Dominant language
- C#
- Stars
- 4.7k
- Forks
- 822
- PR merge metrics
- No merged PRs in 30d
Description
Hi Ryan :)
I've been playing around these days with Covenant and I've realized that MakeToken's functionality may not be working as intended.
### 1 - Token applied wrongly on ShellCmd actions?
The new token created with MakeToken seems is not working with Shellcmd. However, with powershell it does:

### 2 - Logon Types not working on low-priv users?
When using MakeToken with a low-priv user, only the logon type LOGON32_LOGON_NEW_CREDENTIALS seems to work. If another one is used, let's say LOGON32_LOGON_INTERACTIVE, the session breaks.

- As you can see, if I run MakeToken with LOGON32_LOGON_NEW_CREDENTIALS, it says that the token has been made and impersonated correctly.
- But when I try to do the same with LOGON32_LOGON_INTERACTIVE, the session breaks.
However, when doing this same process with an admin user, it succeeds:

I've seen that MakeToken is using
- LogonUserA to create a token with a logon session associated.
- ImpersonateLoggedOnUser to apply that token to the primary thread of our process.
As Microsoft remarks, admin should not be needed (https://docs.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-impersonateloggedonuser):
> All impersonate functions, including ImpersonateLoggedOnUser allow the requested impersonation if one of the following is true:
> ...
> A process (or another process in the caller's logon session) created the token using explicit credentials through LogonUser or LsaLogonUser function.
> ...
Many thanks!!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.