forked from Adepts-Of-0xCC/MiniDumpWriteDumpPoC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cpp
94 lines (70 loc) · 2.68 KB
/
utils.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "utils.h"
#include <stdio.h>
#include <Windows.h>
unsigned char* encrypt(void* buffer, long long size, char key) {
unsigned char* new_buff = (unsigned char*)malloc(size);
for (long long i = 0; i < size; ++i)
new_buff[i] = *(((unsigned char*)buffer) + i) ^ key;
return new_buff;
}
char* prepareBuffer(const char* buffer, int buffer_size, long pos, int* real_size) {
*real_size = buffer_size + sizeof(pos) + sizeof(buffer_size);
char* full_buffer = (char*)malloc(*real_size);
memcpy(full_buffer, &pos, sizeof(pos));
memcpy(full_buffer + sizeof(pos), &buffer_size, sizeof(buffer_size));
memcpy(full_buffer + sizeof(pos) + sizeof(buffer_size), buffer, buffer_size);
return full_buffer;
}
bool IsElevated() {
BOOL fRet = FALSE;
HANDLE hToken = NULL;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {
TOKEN_ELEVATION Elevation = { 0 };
DWORD cbSize = sizeof(TOKEN_ELEVATION);
if (GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize)) {
fRet = Elevation.TokenIsElevated;
}
}
if (hToken) {
CloseHandle(hToken);
}
return fRet;
}
bool SetDebugPrivilege() {
HANDLE hToken = NULL;
TOKEN_PRIVILEGES TokenPrivileges = { 0 };
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken)) {
return FALSE;
}
TokenPrivileges.PrivilegeCount = 1;
TokenPrivileges.Privileges[0].Attributes = TRUE ? SE_PRIVILEGE_ENABLED : 0;
const wchar_t* lpwPriv = L"SeDebugPrivilege";
if (!LookupPrivilegeValueW(NULL, (LPCWSTR)lpwPriv, &TokenPrivileges.Privileges[0].Luid)) {
CloseHandle(hToken);
printf("I dont have SeDebugPirvs\n");
return FALSE;
}
if (!AdjustTokenPrivileges(hToken, FALSE, &TokenPrivileges, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {
CloseHandle(hToken);
printf("Could not adjust to SeDebugPirvs\n");
return FALSE;
}
CloseHandle(hToken);
return TRUE;
}
bool preparePipe(void* read_handle, void *write_handle) {
bool success = false;
SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, true };
if (!CreatePipe(&read_handle, &write_handle, &sa, 0)) {
printf("[!] ERR:: Could not create a pipe\n");
}
else {
printf("[i] Pipe created\n");
success = true;
STARTUPINFOA startup_info;
GetStartupInfoA(&startup_info);
startup_info.hStdInput = read_handle;
SetHandleInformation(write_handle, HANDLE_FLAG_INHERIT, 0);
}
return success;
}