Add primary token check for PhImpersonateToken
@@ -9905,6 +9905,22 @@ NTSTATUS PhImpersonateToken(
)
{
NTSTATUS status;
+ TOKEN_TYPE tokenType;
+ ULONG returnLength;
+
+ status = NtQueryInformationToken(
+ TokenHandle,
+ TokenType,
+ &tokenType,
+ sizeof(TOKEN_TYPE),
+ &returnLength
+ );
+
+ if (!NT_SUCCESS(status))
+ return status;
+
+ if (tokenType == TokenPrimary)
+ {
SECURITY_QUALITY_OF_SERVICE securityService;
OBJECT_ATTRIBUTES objectAttributes;
HANDLE tokenHandle;
@@ -9943,6 +9959,16 @@ NTSTATUS PhImpersonateToken(
);
NtClose(tokenHandle);
+ }
+ else
+ {
+ status = NtSetInformationThread(
+ ThreadHandle,
+ ThreadImpersonationToken,
+ &TokenHandle,
+ sizeof(HANDLE)
+ );
+ }
return status;
}
