MCPcopy Create free account
hub / github.com/T3nb3w/ComDotNetExploit / EnablePrivilege

Method EnablePrivilege

Bypass_COM_PPL/trustinstaller_utils.cpp:4–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include "trustinstaller_utils.h"
3
4void Elevate::EnablePrivilege(std::wstring privilegeName)
5{
6 HANDLE hToken;
7 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken))
8 throw std::runtime_error("OpenProcessToken failed: " + std::to_string(GetLastError()));
9
10 LUID luid;
11 if (!LookupPrivilegeValueW(nullptr, privilegeName.c_str(), &luid))
12 {
13 CloseHandle(hToken);
14 throw std::runtime_error("LookupPrivilegeValue failed: " + std::to_string(GetLastError()));
15 }
16
17 TOKEN_PRIVILEGES tp;
18 tp.PrivilegeCount = 1;
19 tp.Privileges[0].Luid = luid;
20 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
21 if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
22 {
23 CloseHandle(hToken);
24 throw std::runtime_error("AdjustTokenPrivilege failed: " + std::to_string(GetLastError()));
25 }
26
27 CloseHandle(hToken);
28}
29
30DWORD Elevate::GetProcessIdByName(std::wstring processName)
31{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected