Skip to content

Commit ee19fb0

Browse files
committed
Add workaround for Font Driver Host token psuedo container
1 parent 130d47b commit ee19fb0

File tree

1 file changed

+82
-9
lines changed

1 file changed

+82
-9
lines changed

ProcessHacker/tokprp.c

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* token properties
44
*
55
* Copyright (C) 2010-2012 wj32
6-
* Copyright (C) 2017-2019 dmex
6+
* Copyright (C) 2017-2021 dmex
77
*
88
* This file is part of Process Hacker.
99
*
@@ -496,6 +496,18 @@ static NTSTATUS NTAPI PhpTokenGroupResolveWorker(
496496
{
497497
PhMoveReference(&sidString, PhConcatStringRefZ(&sidString->sr, L" (APP_CAPABILITY)"));
498498
}
499+
else
500+
{
501+
ULONG subAuthority;
502+
503+
subAuthority = *RtlSubAuthoritySid(context->TokenGroupSid, 0);
504+
//RtlIdentifierAuthoritySid(tokenUser->User.Sid) == (BYTE[])SECURITY_NT_AUTHORITY
505+
506+
if (subAuthority == SECURITY_UMFD_BASE_RID)
507+
{
508+
PhMoveReference(&sidString, PhCreateString(L"Font Driver Host\\UMFD"));
509+
}
510+
}
499511

500512
if (sidString)
501513
{
@@ -3273,10 +3285,26 @@ PPH_STRING PhpGetTokenFolderPath(
32733285

32743286
if (NT_SUCCESS(PhGetTokenUser(TokenHandle, &tokenUser)))
32753287
{
3276-
if (tokenUserSid = PhSidToStringSid(tokenUser->User.Sid))
3288+
ULONG subAuthority;
3289+
3290+
subAuthority = *RtlSubAuthoritySid(tokenUser->User.Sid, 0);
3291+
//RtlIdentifierAuthoritySid(tokenUser->User.Sid) == (BYTE[])SECURITY_NT_AUTHORITY
3292+
3293+
if (subAuthority == SECURITY_UMFD_BASE_RID)
3294+
{
3295+
if (tokenUserSid = PhSidToStringSid(&PhSeLocalSystemSid))
3296+
{
3297+
profileKeyPath = PhConcatStringRef2(&servicesKeyName, &tokenUserSid->sr);
3298+
PhDereferenceObject(tokenUserSid);
3299+
}
3300+
}
3301+
else
32773302
{
3278-
profileKeyPath = PhConcatStringRef2(&servicesKeyName, &tokenUserSid->sr);
3279-
PhDereferenceObject(tokenUserSid);
3303+
if (tokenUserSid = PhSidToStringSid(tokenUser->User.Sid))
3304+
{
3305+
profileKeyPath = PhConcatStringRef2(&servicesKeyName, &tokenUserSid->sr);
3306+
PhDereferenceObject(tokenUserSid);
3307+
}
32803308
}
32813309

32823310
PhFree(tokenUser);
@@ -3363,6 +3391,7 @@ PPH_STRING PhpGetTokenRegistryPath(
33633391
}
33643392

33653393
PPH_STRING PhpGetTokenAppContainerFolderPath(
3394+
_In_ HANDLE TokenHandle,
33663395
_In_ PSID TokenAppContainerSid
33673396
)
33683397
{
@@ -3372,17 +3401,61 @@ PPH_STRING PhpGetTokenAppContainerFolderPath(
33723401

33733402
appContainerSid = PhSidToStringSid(TokenAppContainerSid);
33743403

3375-
if (GetAppContainerFolderPath_Import())
3404+
if (NT_SUCCESS(PhImpersonateToken(NtCurrentThread(), TokenHandle)))
33763405
{
3377-
if (SUCCEEDED(GetAppContainerFolderPath_Import()(appContainerSid->Buffer, &folderPath)) && folderPath)
3406+
if (GetAppContainerFolderPath_Import())
33783407
{
3379-
appContainerFolderPath = PhCreateString(folderPath);
3380-
CoTaskMemFree(folderPath);
3408+
if (SUCCEEDED(GetAppContainerFolderPath_Import()(appContainerSid->Buffer, &folderPath)) && folderPath)
3409+
{
3410+
appContainerFolderPath = PhCreateString(folderPath);
3411+
CoTaskMemFree(folderPath);
3412+
}
33813413
}
3414+
3415+
PhRevertImpersonationToken(NtCurrentThread());
33823416
}
33833417

33843418
PhDereferenceObject(appContainerSid);
33853419

3420+
// Workaround for psuedo Appcontainers created by System processes that default to the \systemprofile path. (dmex)
3421+
if (PhIsNullOrEmptyString(appContainerFolderPath))
3422+
{
3423+
PTOKEN_USER tokenUser;
3424+
3425+
if (NT_SUCCESS(PhGetTokenUser(TokenHandle, &tokenUser)))
3426+
{
3427+
ULONG subAuthority;
3428+
PPH_STRING tokenProfilePathString;
3429+
PPH_STRING appContainerName;
3430+
3431+
subAuthority = *RtlSubAuthoritySid(tokenUser->User.Sid, 0);
3432+
//RtlIdentifierAuthoritySid(tokenUser->User.Sid) == (BYTE[])SECURITY_NT_AUTHORITY
3433+
3434+
if (subAuthority == SECURITY_UMFD_BASE_RID)
3435+
{
3436+
if (tokenProfilePathString = PhpGetTokenFolderPath(TokenHandle))
3437+
{
3438+
if (appContainerName = PhGetAppContainerName(TokenAppContainerSid))
3439+
{
3440+
static PH_STRINGREF appDataPackagePath = PH_STRINGREF_INIT(L"\\AppData\\Local\\Packages\\");
3441+
3442+
PhMoveReference(&appContainerFolderPath, PhConcatStringRef3(
3443+
&tokenProfilePathString->sr,
3444+
&appDataPackagePath,
3445+
&appContainerName->sr
3446+
));
3447+
3448+
PhDereferenceObject(appContainerName);
3449+
}
3450+
3451+
PhDereferenceObject(tokenProfilePathString);
3452+
}
3453+
}
3454+
3455+
PhFree(tokenUser);
3456+
}
3457+
}
3458+
33863459
return appContainerFolderPath;
33873460
}
33883461

@@ -3641,7 +3714,7 @@ INT_PTR CALLBACK PhpTokenContainerPageProc(
36413714
{
36423715
if (appContainerInfo->TokenAppContainer)
36433716
{
3644-
appContainerFolderPath = PhpGetTokenAppContainerFolderPath(appContainerInfo->TokenAppContainer);
3717+
appContainerFolderPath = PhpGetTokenAppContainerFolderPath(tokenHandle, appContainerInfo->TokenAppContainer);
36453718
}
36463719

36473720
PhFree(appContainerInfo);

0 commit comments

Comments
 (0)