Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Card
I noticed there are some issues in token management, in particular when it comes to creating a sacrificial logon session with
make-token
command. With this PR I may have solved the issue by forcing the goroutine to use always the same thread, in which it was calledImpersonateLoggedOnUser
, only when necessary. In addition i modified theRev2Self
to also close the Handle to the token.Details
If you try to run
make-token
and thenrubeus --in-process triage
you may notice that theLUID
showed in the rubeus command changes unexpectedly.Here an example:
As you can see before make-token LUID is
0x91bb1
. After running make-token a new LUID is created0x522b1c
running rubeus first time. The third time aftermake-token
instead rubeus shows again that the LUID is0x91bb1
.This probably happens because the goroutine executing the handler gets assigned a random thread. In order to solve the issue I use
runtime.LockOSThread()
in order to bound the goroutine to the same thread. Before callingruntime.LockOSThread()
ImpersonateLoggedOnUser
in order to set the token in the goroutine thread. The bounding of the goroutine to the same thread withruntime.LockOSThread()
is applied only forsysHandlers
when the variablepriv.CurrenToken
is different from 0.With the modification in the PR here is the behaviour:
You can see now that after
make-token
, whenrubeus --in-process triage
is executed the LUID remains0xa71711
. Afterrev2self
the LUID displayed is the previous one.In addition I've modified
Rev2Self
so that it closes the handle to the token, while I introducedTRev2Self
that just callssyscalls.RevToSelf()
from win32 API.