28 typedef struct _ATTRIBUTE_NODE
35 typedef struct _ATTRIBUTE_TREE_CONTEXT
41 typedef struct _TOKEN_PAGE_CONTEXT
47 HWND GroupsListViewHandle;
48 HWND PrivilegesListViewHandle;
51 PTOKEN_PRIVILEGES Privileges;
52 PTOKEN_GROUPS Capabilities;
61 _In_ LPPROPSHEETPAGE ppsp
72 _In_ HWND ParentWindowHandle,
100 _In_opt_ PVOID Parameter1,
101 _In_opt_ PVOID Parameter2,
102 _In_opt_ PVOID Context
120 _In_ HWND ParentWindowHandle,
122 _In_opt_ PVOID Context,
126 PROPSHEETHEADER propSheetHeader = {
sizeof(propSheetHeader) };
127 HPROPSHEETPAGE pages[1];
129 propSheetHeader.dwFlags =
133 propSheetHeader.hwndParent = ParentWindowHandle;
134 propSheetHeader.pszCaption = Title ? Title : L
"Token";
135 propSheetHeader.nPages = 1;
136 propSheetHeader.nStartPage = 0;
137 propSheetHeader.phpage = pages;
141 PropertySheet(&propSheetHeader);
146 _In_opt_ PVOID Context,
147 _In_opt_ DLGPROC HookProc
150 HPROPSHEETPAGE propSheetPageHandle;
151 PROPSHEETPAGE propSheetPage;
156 tokenPageContext->OpenObject = OpenObject;
157 tokenPageContext->Context = Context;
158 tokenPageContext->HookProc = HookProc;
160 memset(&propSheetPage, 0,
sizeof(PROPSHEETPAGE));
161 propSheetPage.dwSize =
sizeof(PROPSHEETPAGE);
162 propSheetPage.dwFlags = PSP_USECALLBACK;
163 propSheetPage.pszTemplate = MAKEINTRESOURCE(
IDD_OBJTOKEN);
165 propSheetPage.lParam = (LPARAM)tokenPageContext;
168 propSheetPageHandle = CreatePropertySheetPage(&propSheetPage);
173 return propSheetPageHandle;
179 _In_ LPPROPSHEETPAGE ppsp
186 if (uMsg == PSPCB_ADDREF)
190 else if (uMsg == PSPCB_RELEASE)
199 _In_ ULONG Attributes
205 if (Attributes & SE_GROUP_INTEGRITY)
207 if (Attributes & SE_GROUP_INTEGRITY_ENABLED)
213 if (Attributes & SE_GROUP_LOGON_ID)
214 baseString = L
"Logon ID";
215 else if (Attributes & SE_GROUP_MANDATORY)
216 baseString = L
"Mandatory";
217 else if (Attributes & SE_GROUP_OWNER)
218 baseString = L
"Owner";
219 else if (Attributes & SE_GROUP_RESOURCE)
220 baseString = L
"Resource";
221 else if (Attributes & SE_GROUP_USE_FOR_DENY_ONLY)
222 baseString = L
"Use for Deny Only";
228 if (Attributes & SE_GROUP_ENABLED_BY_DEFAULT)
230 else if (Attributes & SE_GROUP_ENABLED)
236 if (Attributes & SE_GROUP_ENABLED_BY_DEFAULT)
238 else if (Attributes & SE_GROUP_ENABLED)
247 _In_ ULONG Attributes
250 if (Attributes & SE_GROUP_INTEGRITY)
252 if (Attributes & SE_GROUP_INTEGRITY_ENABLED)
253 return RGB(0xe0, 0xf0, 0xe0);
255 return GetSysColor(COLOR_WINDOW);
258 if (Attributes & SE_GROUP_ENABLED_BY_DEFAULT)
259 return RGB(0xe0, 0xf0, 0xe0);
260 else if (Attributes & SE_GROUP_ENABLED)
261 return GetSysColor(COLOR_WINDOW);
263 return RGB(0xf0, 0xe0, 0xe0);
266 static COLORREF NTAPI PhpTokenGroupColorFunction(
269 _In_opt_ PVOID Context
272 PSID_AND_ATTRIBUTES sidAndAttributes = Param;
278 _In_ ULONG Attributes
281 if (Attributes & SE_PRIVILEGE_ENABLED_BY_DEFAULT)
282 return L
"Default Enabled";
283 else if (Attributes & SE_PRIVILEGE_ENABLED)
290 _In_ ULONG Attributes
293 if (Attributes & SE_PRIVILEGE_ENABLED_BY_DEFAULT)
294 return RGB(0xc0, 0xf0, 0xc0);
295 else if (Attributes & SE_PRIVILEGE_ENABLED)
296 return RGB(0xe0, 0xf0, 0xe0);
298 return RGB(0xf0, 0xe0, 0xe0);
301 static COLORREF NTAPI PhpTokenPrivilegeColorFunction(
304 _In_opt_ PVOID Context
307 PLUID_AND_ATTRIBUTES luidAndAttributes = Param;
313 _In_ TOKEN_ELEVATION_TYPE ElevationType
316 switch (ElevationType)
318 case TokenElevationTypeFull:
320 case TokenElevationTypeLimited:
331 _In_ HANDLE TokenHandle
334 PTOKEN_GROUPS groups;
342 ListView_DeleteAllItems(GroupsLv);
344 for (i = 0; i < groups->GroupCount; i++)
368 if (TokenPageContext->Groups)
369 PhFree(TokenPageContext->Groups);
371 TokenPageContext->Groups = groups;
384 hwndDlg, uMsg, wParam, lParam, L
"TokenPageContext");
398 if (!tokenPageContext)
401 if (tokenPageContext->HookProc)
403 if (tokenPageContext->HookProc(hwndDlg, uMsg, wParam, lParam))
415 tokenPageContext->GroupsListViewHandle = groupsLv = GetDlgItem(hwndDlg,
IDC_GROUPS);
416 tokenPageContext->PrivilegesListViewHandle = privilegesLv = GetDlgItem(hwndDlg,
IDC_PRIVILEGES);
435 SetDlgItemText(hwndDlg,
IDC_USER, L
"Unknown");
445 tokenPageContext->Context
448 PTOKEN_USER tokenUser;
452 TOKEN_ELEVATION_TYPE elevationType;
453 BOOLEAN isVirtualizationAllowed;
454 BOOLEAN isVirtualizationEnabled;
455 PTOKEN_APPCONTAINER_INFORMATION appContainerInfo;
486 if (isVirtualizationAllowed)
493 isVirtualizationEnabled ? L
"Yes" : L
"No"
511 appContainerSid = NULL;
515 if (appContainerInfo->TokenAppContainer)
542 for (i = 0; i < tokenPageContext->Privileges->PrivilegeCount; i++)
549 &tokenPageContext->Privileges->Privileges[i].Luid,
553 privilegeDisplayName = NULL;
558 &tokenPageContext->Privileges->Privileges[i]);
562 tokenPageContext->Privileges->Privileges[i].Attributes));
575 NtClose(tokenHandle);
581 if (tokenPageContext->Groups)
PhFree(tokenPageContext->Groups);
582 if (tokenPageContext->Privileges)
PhFree(tokenPageContext->Privileges);
587 switch (LOWORD(wParam))
594 PLUID_AND_ATTRIBUTES *privileges;
595 ULONG numberOfPrivileges;
604 L
"the selected privilege(s)",
605 L
"Removing privileges may reduce the functionality of the process, "
606 L
"and is permanent for the lifetime of the process.",
613 tokenPageContext->PrivilegesListViewHandle,
618 status = tokenPageContext->OpenObject(
620 TOKEN_ADJUST_PRIVILEGES,
621 tokenPageContext->Context
628 for (i = 0; i < numberOfPrivileges; i++)
636 switch (LOWORD(wParam))
639 newAttributes = SE_PRIVILEGE_ENABLED;
645 newAttributes = SE_PRIVILEGE_REMOVED;
653 privileges[i]->Attributes & SE_PRIVILEGE_ENABLED_BY_DEFAULT &&
674 &privileges[i]->Luid,
679 tokenPageContext->PrivilegesListViewHandle,
688 privileges[i]->Attributes = newAttributes;
690 tokenPageContext->PrivilegesListViewHandle,
699 tokenPageContext->PrivilegesListViewHandle,
706 PWSTR action = L
"set";
708 switch (LOWORD(wParam))
733 NtClose(tokenHandle);
737 PhShowStatus(hwndDlg, L
"Unable to open the token", status, 0);
756 MANDATORY_LEVEL integrityLevel;
778 tokenPageContext->Context
793 if (menuItem->
Id == integrityLevel)
797 else if (menuItem->
Id > (ULONG)integrityLevel)
804 NtClose(tokenHandle);
816 if (selectedItem && selectedItem->
Id != integrityLevel)
821 L
"the integrity level",
822 L
"Once lowered, the integrity level of the token cannot be raised again.",
826 if (
NT_SUCCESS(status = tokenPageContext->OpenObject(
828 TOKEN_QUERY | TOKEN_ADJUST_DEFAULT,
829 tokenPageContext->Context
832 static SID_IDENTIFIER_AUTHORITY mandatoryLabelAuthority = SECURITY_MANDATORY_LABEL_AUTHORITY;
834 UCHAR newSidBuffer[FIELD_OFFSET(SID, SubAuthority) +
sizeof(ULONG)];
836 TOKEN_MANDATORY_LABEL mandatoryLabel;
838 newSid = (PSID)newSidBuffer;
841 mandatoryLabel.Label.Sid = newSid;
842 mandatoryLabel.Label.Attributes = SE_GROUP_INTEGRITY;
848 sizeof(TOKEN_MANDATORY_LABEL)
854 NtClose(tokenHandle);
858 PhShowStatus(hwndDlg, L
"Unable to set the integrity level", status, 0);
875 LPNMHDR header = (LPNMHDR)lParam;
877 switch (header->code)
879 case PSN_QUERYINITIALFOCUS:
881 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)GetDlgItem(hwndDlg,
IDC_SESSIONID));
893 if ((HWND)wParam == tokenPageContext->PrivilegesListViewHandle)
897 point.x = (SHORT)LOWORD(lParam);
898 point.y = (SHORT)HIWORD(lParam);
900 if (point.x == -1 && point.y == -1)
903 if (ListView_GetSelectedCount(tokenPageContext->PrivilegesListViewHandle) != 0)
918 REFLECT_MESSAGE_DLG(hwndDlg, tokenPageContext->GroupsListViewHandle, uMsg, wParam, lParam);
919 REFLECT_MESSAGE_DLG(hwndDlg, tokenPageContext->PrivilegesListViewHandle, uMsg, wParam, lParam);
925 _In_ HWND ParentWindowHandle,
929 PROPSHEETHEADER propSheetHeader = {
sizeof(propSheetHeader) };
930 HPROPSHEETPAGE pages[6];
935 ULONG numberOfAccessEntries;
937 propSheetHeader.dwFlags =
941 propSheetHeader.hwndParent = ParentWindowHandle;
942 propSheetHeader.pszCaption = L
"Token";
943 propSheetHeader.nStartPage = 0;
944 propSheetHeader.phpage = pages;
950 memset(&page, 0,
sizeof(PROPSHEETPAGE));
951 page.dwSize =
sizeof(PROPSHEETPAGE);
954 page.lParam = (LPARAM)Context;
955 pages[numberOfPages++] = CreatePropertySheetPage(&page);
959 memset(&page, 0,
sizeof(PROPSHEETPAGE));
960 page.dwSize =
sizeof(PROPSHEETPAGE);
963 page.lParam = (LPARAM)Context;
964 pages[numberOfPages++] = CreatePropertySheetPage(&page);
970 memset(&page, 0,
sizeof(PROPSHEETPAGE));
971 page.dwSize =
sizeof(PROPSHEETPAGE);
974 page.lParam = (LPARAM)Context;
975 pages[numberOfPages++] = CreatePropertySheetPage(&page);
979 memset(&page, 0,
sizeof(PROPSHEETPAGE));
980 page.dwSize =
sizeof(PROPSHEETPAGE);
981 page.dwFlags = PSP_USETITLE;
983 page.pszTitle = L
"Claims";
985 page.lParam = (LPARAM)Context;
986 pages[numberOfPages++] = CreatePropertySheetPage(&page);
990 memset(&page, 0,
sizeof(PROPSHEETPAGE));
991 page.dwSize =
sizeof(PROPSHEETPAGE);
992 page.dwFlags = PSP_USETITLE;
994 page.pszTitle = L
"Attributes";
996 page.lParam = (LPARAM)Context;
997 pages[numberOfPages++] = CreatePropertySheetPage(&page);
1002 stdObjectSecurity.
OpenObject = Context->OpenObject;
1004 stdObjectSecurity.
Context = Context->Context;
1014 numberOfAccessEntries
1019 propSheetHeader.nPages = numberOfPages;
1020 PropertySheet(&propSheetHeader);
1023 static NTSTATUS PhpOpenLinkedToken(
1024 _Out_ PHANDLE Handle,
1025 _In_ ACCESS_MASK DesiredAccess,
1026 _In_opt_ PVOID Context
1043 if (!tokenPageContext)
1055 ULONG tokenSessionId = -1;
1056 PWSTR tokenElevated = L
"N/A";
1057 BOOLEAN hasLinkedToken =
FALSE;
1058 PWSTR tokenVirtualization = L
"N/A";
1059 WCHAR tokenSourceName[TOKEN_SOURCE_LENGTH + 1] = L
"Unknown";
1065 tokenPageContext->Context
1068 PTOKEN_USER tokenUser;
1069 PTOKEN_OWNER tokenOwner;
1070 PTOKEN_PRIMARY_GROUP tokenPrimaryGroup;
1071 TOKEN_ELEVATION_TYPE elevationType;
1072 BOOLEAN isVirtualizationAllowed;
1073 BOOLEAN isVirtualizationEnabled;
1092 tokenPrimaryGroup->PrimaryGroup,
TRUE, NULL));
1093 PhFree(tokenPrimaryGroup);
1103 hasLinkedToken = elevationType != TokenElevationTypeDefault;
1108 if (isVirtualizationAllowed)
1112 tokenVirtualization = isVirtualizationEnabled ? L
"Enabled" : L
"Disabled";
1117 tokenVirtualization = L
"Not Allowed";
1122 NtClose(tokenHandle);
1128 tokenPageContext->Context
1131 TOKEN_SOURCE tokenSource;
1136 tokenSource.SourceName,
1137 TOKEN_SOURCE_LENGTH,
1139 sizeof(tokenSourceName) / 2,
1143 PhPrintPointer(tokenSourceLuid, (PVOID)tokenSource.SourceIdentifier.LowPart);
1146 NtClose(tokenHandle);
1154 if (tokenSessionId != -1)
1164 if (!hasLinkedToken)
1170 switch (LOWORD(wParam))
1177 if (
NT_SUCCESS(status = tokenPageContext->OpenObject(
1180 tokenPageContext->Context
1184 NtClose(tokenHandle);
1188 PhShowStatus(hwndDlg, L
"Unable to open the token", status, 0);
1211 if (!tokenPageContext)
1219 PWSTR tokenType = L
"Unknown";
1220 PWSTR tokenImpersonationLevel = L
"Unknown";
1229 tokenPageContext->Context
1232 TOKEN_STATISTICS statistics;
1236 switch (statistics.TokenType)
1239 tokenType = L
"Primary";
1241 case TokenImpersonation:
1242 tokenType = L
"Impersonation";
1246 if (statistics.TokenType == TokenImpersonation)
1248 switch (statistics.ImpersonationLevel)
1250 case SecurityAnonymous:
1251 tokenImpersonationLevel = L
"Anonymous";
1253 case SecurityIdentification:
1254 tokenImpersonationLevel = L
"Identification";
1256 case SecurityImpersonation:
1257 tokenImpersonationLevel = L
"Impersonation";
1259 case SecurityDelegation:
1260 tokenImpersonationLevel = L
"Delegation";
1266 tokenImpersonationLevel = L
"N/A";
1270 PhPrintPointer(authenticationLuid, (PVOID)statistics.AuthenticationId.LowPart);
1274 memoryUsed =
PhaFormatSize(statistics.DynamicCharged - statistics.DynamicAvailable, -1);
1275 memoryAvailable =
PhaFormatSize(statistics.DynamicCharged, -1);
1278 NtClose(tokenHandle);
1281 SetDlgItemText(hwndDlg,
IDC_TYPE, tokenType);
1294 static COLORREF NTAPI PhpTokenCapabilitiesColorFunction(
1297 _In_opt_ PVOID Context
1300 PSID_AND_ATTRIBUTES sidAndAttributes = Param;
1317 if (!tokenPageContext)
1320 lvHandle = GetDlgItem(hwndDlg,
IDC_LIST);
1339 tokenPageContext->Context
1344 for (i = 0; i < tokenPageContext->Capabilities->GroupCount; i++)
1358 &tokenPageContext->Capabilities->Groups[i]);
1360 tokenPageContext->Capabilities->Groups[i].Attributes);
1368 if (ListView_GetItemCount(lvHandle) != 0)
1370 ListView_SetColumnWidth(lvHandle, 0, LVSCW_AUTOSIZE);
1377 NtClose(tokenHandle);
1383 PhFree(tokenPageContext->Capabilities);
1384 tokenPageContext->Capabilities = NULL;
1402 _In_opt_ PVOID Parameter1,
1403 _In_opt_ PVOID Parameter2,
1404 _In_opt_ PVOID Context
1438 isLeaf->
IsLeaf = node->Children->Count == 0;
1447 if (getCellText->
Id == 0)
1460 if (GetKeyState(VK_CONTROL) < 0)
1514 _In_ HWND TreeNewHandle
1534 for (i = 0; i < Context->NodeList->Count; i++)
1564 return L
"Octet String";
1566 return L
"(Unknown)";
1602 _In_ PCLAIM_SECURITY_ATTRIBUTE_V1 Attribute,
1603 _In_ ULONG ValueIndex
1608 switch (Attribute->ValueType)
1610 case CLAIM_SECURITY_ATTRIBUTE_TYPE_INT64:
1613 case CLAIM_SECURITY_ATTRIBUTE_TYPE_UINT64:
1616 case CLAIM_SECURITY_ATTRIBUTE_TYPE_STRING:
1618 case CLAIM_SECURITY_ATTRIBUTE_TYPE_FQBN:
1620 Attribute->Values.pFqbn[ValueIndex].Version,
1621 Attribute->Values.pFqbn[ValueIndex].Name);
1622 case CLAIM_SECURITY_ATTRIBUTE_TYPE_SID:
1624 if (
RtlValidSid(Attribute->Values.pOctetString[ValueIndex].pValue))
1633 name =
PhSidToStringSid(Attribute->Values.pOctetString[ValueIndex].pValue);
1640 case CLAIM_SECURITY_ATTRIBUTE_TYPE_BOOLEAN:
1641 return PhCreateString(Attribute->Values.pInt64[ValueIndex] != 0 ? L
"True" : L
"False");
1642 case CLAIM_SECURITY_ATTRIBUTE_TYPE_OCTET_STRING:
1651 _In_ ULONG ValueIndex
1656 switch (Attribute->ValueType)
1668 Attribute->Values.pFqbn[ValueIndex].Version,
1669 Attribute->Values.pFqbn[ValueIndex].Name.Length /
sizeof(WCHAR),
1670 Attribute->Values.pFqbn[ValueIndex].Name.Buffer);
1673 if (
RtlValidSid(Attribute->Values.pOctetString[ValueIndex].pValue))
1682 name =
PhSidToStringSid(Attribute->Values.pOctetString[ValueIndex].pValue);
1690 return PhCreateString(Attribute->Values.pInt64[ValueIndex] != 0 ? L
"True" : L
"False");
1701 _In_ BOOLEAN DeviceClaims,
1706 PCLAIM_SECURITY_ATTRIBUTES_INFORMATION info;
1710 if (!
NT_SUCCESS(TokenPageContext->OpenObject(
1713 TokenPageContext->Context
1719 for (i = 0; i < info->AttributeCount; i++)
1721 PCLAIM_SECURITY_ATTRIBUTE_V1 attribute = &info->Attribute.pAttributeV1[i];
1737 for (j = 0; j < attribute->ValueCount; j++)
1749 NtClose(tokenHandle);
1768 if (!tokenPageContext)
1771 tnHandle = GetDlgItem(hwndDlg,
IDC_LIST);
1789 if (userNode->Children->Count == 0)
1791 if (deviceNode->Children->Count == 0)
1818 if (!
NT_SUCCESS(TokenPageContext->OpenObject(
1821 TokenPageContext->Context
1858 NtClose(tokenHandle);
1877 if (!tokenPageContext)
1880 tnHandle = GetDlgItem(hwndDlg,
IDC_LIST);
1892 if (tokenPageContext->AuthzTreeContext.RootList->Count == 0)