权限提升代码
void AdjustPrivilege(int pid, BOOL bEnable)
{
HANDLE hProcess;
HANDLE hToken=0;
TOKEN_PRIVILEGES tkp;
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = 0;
if (bEnable)
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (LookupPrivilegeValue(NULL, "SeDebugPrivilege", &tkp.Privileges[0].Luid))
{
if (hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid))
{
if (OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken))
{
if (AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL))
{
CloseHandle(hToken);
}
}
CloseHandle(hProcess);
}
}
}
{
HANDLE hProcess;
HANDLE hToken=0;
TOKEN_PRIVILEGES tkp;
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = 0;
if (bEnable)
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (LookupPrivilegeValue(NULL, "SeDebugPrivilege", &tkp.Privileges[0].Luid))
{
if (hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid))
{
if (OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken))
{
if (AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL))
{
CloseHandle(hToken);
}
}
CloseHandle(hProcess);
}
}
}
我最擅长从零开始创造世界,所以从来不怕失败,它最多也就让我一无所有。