16 SE_ASSIGNPRIMARYTOKEN_NAME,
26 SE_CREATE_GLOBAL_NAME,
27 SE_CREATE_PAGEFILE_NAME,
28 SE_CREATE_PERMANENT_NAME,
29 SE_CREATE_SYMBOLIC_LINK_NAME,
32 SE_ENABLE_DELEGATION_NAME,
34 SE_INC_BASE_PRIORITY_NAME,
35 SE_INCREASE_QUOTA_NAME,
36 SE_INC_WORKING_SET_NAME,
39 SE_MACHINE_ACCOUNT_NAME,
40 SE_MANAGE_VOLUME_NAME,
41 SE_PROF_SINGLE_PROCESS_NAME,
43 SE_REMOTE_SHUTDOWN_NAME,
48 SE_SYSTEM_ENVIRONMENT_NAME,
49 SE_SYSTEM_PROFILE_NAME,
51 SE_TAKE_OWNERSHIP_NAME,
54 SE_TRUSTED_CREDMAN_ACCESS_NAME,
56 SE_UNSOLICITED_INPUT_NAME
69 HMODULE
module = LoadLibraryW(L
"wtsapi32.dll");
70 HANDLE token =
nullptr;
71 decltype(WTSQueryUserToken)* wtsQueryUserToken =
72 (
decltype(WTSQueryUserToken)*) GetProcAddress(module,
"WTSQueryUserToken");
73 if (wtsQueryUserToken)
75 wtsQueryUserToken(sessionID, &token);
95 TOKEN_LINKED_TOKEN tlt;
96 HANDLE hNewLinkedToken =
nullptr;
98 if (GetTokenInformation(token, (TOKEN_INFORMATION_CLASS)TokenLinkedToken,
99 &tlt,
sizeof(TOKEN_LINKED_TOKEN), &len))
101 token = tlt.LinkedToken;
102 hNewLinkedToken = token;
104 return hNewLinkedToken;
120 if (!LookupPrivilegeValue(
nullptr, priv, &luidOfPriv))
125 TOKEN_PRIVILEGES tokenPriv;
126 tokenPriv.PrivilegeCount = 1;
127 tokenPriv.Privileges[0].Luid = luidOfPriv;
128 tokenPriv.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED : 0;
130 SetLastError(ERROR_SUCCESS);
131 if (!AdjustTokenPrivileges(token,
false, &tokenPriv,
132 sizeof(tokenPriv),
nullptr,
nullptr))
137 return GetLastError() == ERROR_SUCCESS;
152 LPCTSTR *unneededPrivs,
155 HANDLE obtainedToken =
nullptr;
159 HANDLE process = GetCurrentProcess();
160 if (!OpenProcessToken(process, TOKEN_ALL_ACCESS_P, &obtainedToken))
162 LOG_WARN((
"Could not obtain token for current process, no "
163 "privileges changed. (%d)", GetLastError()));
166 token = obtainedToken;
170 for (
size_t i = 0;
i <
count;
i++)
174 LOG((
"Disabled unneeded token privilege: %s.",
179 LOG((
"Could not disable token privilege value: %s. (%d)",
180 unneededPrivs[i], GetLastError()));
187 CloseHandle(obtainedToken);
205 static const size_t PrivsToDisableSize =
222 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
227 TOKEN_ELEVATION_TYPE elevationType;
229 bool canElevate = GetTokenInformation(token, TokenElevationType,
231 sizeof(elevationType), &len) &&
232 (elevationType == TokenElevationTypeLimited);
static BOOL DisableUnneededPrivileges(HANDLE token, LPCTSTR *unneededPrivs, size_t count)
static LPCTSTR PrivsToDisable[]
static HANDLE OpenLinkedToken(HANDLE token)
static bool CanUserElevate()
static HANDLE OpenUserToken(DWORD sessionID)
static BOOL SetPrivilege(HANDLE token, LPCTSTR privs, BOOL enable)
static BOOL DisablePrivileges(HANDLE token)
const wchar_t *typedef BOOL