3
3
* token properties
4
4
*
5
5
* Copyright (C) 2010-2012 wj32
6
- * Copyright (C) 2017-2019 dmex
6
+ * Copyright (C) 2017-2021 dmex
7
7
*
8
8
* This file is part of Process Hacker.
9
9
*
@@ -496,6 +496,18 @@ static NTSTATUS NTAPI PhpTokenGroupResolveWorker(
496
496
{
497
497
PhMoveReference (& sidString , PhConcatStringRefZ (& sidString -> sr , L" (APP_CAPABILITY)" ));
498
498
}
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
+ }
499
511
500
512
if (sidString )
501
513
{
@@ -3273,10 +3285,26 @@ PPH_STRING PhpGetTokenFolderPath(
3273
3285
3274
3286
if (NT_SUCCESS (PhGetTokenUser (TokenHandle , & tokenUser )))
3275
3287
{
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
3277
3302
{
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
+ }
3280
3308
}
3281
3309
3282
3310
PhFree (tokenUser );
@@ -3363,6 +3391,7 @@ PPH_STRING PhpGetTokenRegistryPath(
3363
3391
}
3364
3392
3365
3393
PPH_STRING PhpGetTokenAppContainerFolderPath (
3394
+ _In_ HANDLE TokenHandle ,
3366
3395
_In_ PSID TokenAppContainerSid
3367
3396
)
3368
3397
{
@@ -3372,17 +3401,61 @@ PPH_STRING PhpGetTokenAppContainerFolderPath(
3372
3401
3373
3402
appContainerSid = PhSidToStringSid (TokenAppContainerSid );
3374
3403
3375
- if (GetAppContainerFolderPath_Import ( ))
3404
+ if (NT_SUCCESS ( PhImpersonateToken ( NtCurrentThread (), TokenHandle ) ))
3376
3405
{
3377
- if (SUCCEEDED ( GetAppContainerFolderPath_Import ()( appContainerSid -> Buffer , & folderPath )) && folderPath )
3406
+ if (GetAppContainerFolderPath_Import ())
3378
3407
{
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
+ }
3381
3413
}
3414
+
3415
+ PhRevertImpersonationToken (NtCurrentThread ());
3382
3416
}
3383
3417
3384
3418
PhDereferenceObject (appContainerSid );
3385
3419
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
+
3386
3459
return appContainerFolderPath ;
3387
3460
}
3388
3461
@@ -3641,7 +3714,7 @@ INT_PTR CALLBACK PhpTokenContainerPageProc(
3641
3714
{
3642
3715
if (appContainerInfo -> TokenAppContainer )
3643
3716
{
3644
- appContainerFolderPath = PhpGetTokenAppContainerFolderPath (appContainerInfo -> TokenAppContainer );
3717
+ appContainerFolderPath = PhpGetTokenAppContainerFolderPath (tokenHandle , appContainerInfo -> TokenAppContainer );
3645
3718
}
3646
3719
3647
3720
PhFree (appContainerInfo );
0 commit comments