cobbr / cobbr/Covenant

[Issue] Shell commands don't use impersonated tokens

Open
#45 12 comments 0 reactions 0 assignees View on GitHub
bug high-priority
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:

![netonly](https://user-images.githubusercontent.com/35996395/63762720-95dd5880-c8c3-11e9-8939-58705508c5f0.png)

### 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.

![interactivelogonfailing](https://user-images.githubusercontent.com/35996395/63763017-33388c80-c8c4-11e9-9e8f-050db032e57c.png)
- 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:
![interactivelogoncorrect](https://user-images.githubusercontent.com/35996395/63763526-2b2d1c80-c8c5-11e9-98b7-f02c0d00e274.png)

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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.