-
Notifications
You must be signed in to change notification settings - Fork 8
/
globals.hpp
142 lines (127 loc) · 3.35 KB
/
globals.hpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
*
* Title: EQU8 User-Mode Bypass and Injector
* Author: hotline
*
*/
#pragma once
#include <Windows.h>
#include <functional>
#include <fstream>
#include <memory>
#include "processuser.hpp"
#include "trustedinstaller.hpp"
using namespace std;
namespace globals
{
namespace string
{
inline auto erase_all_sub_str(std::string& mainStr, const std::string& toErase) -> void
{
auto pos = std::string::npos;
while ((pos = mainStr.find(toErase)) != std::string::npos)
{
mainStr.erase(pos, toErase.length());
}
}
}
namespace validation
{
static CHAR path[MAX_PATH];
inline function<void(void)> set_user = []()
{
ofstream file;
const auto current_user = getenv("USERPROFILE");
file.open("C:\\ProgramData\\user.equ8", ios::out | ios::trunc);
file << current_user << "\\Desktop";
file.close();
};
inline function<void(void)> validate_system = []()
{
bool is_system;
std::string user;
GetUserFromProcess(GetCurrentProcessId(), user);
std::string user_name = getenv("USERPROFILE");
string::erase_all_sub_str(user_name, "C:\\Users\\");
if (user == user_name)
{
is_system = false;
}
else
{
is_system = true;
}
GetModuleFileNameA(nullptr, path, MAX_PATH);
if (!is_system)
{
set_user();
create_process(path);
TerminateProcess(GetCurrentProcess(), 0);
}
};
inline auto get_user() -> ::string
{
ifstream input_file("C:\\ProgramData\\user.equ8");
if (!input_file.is_open())
return "C:\\";
return ::string((istreambuf_iterator<char>(input_file)), istreambuf_iterator<char>());
};
}
namespace process
{
inline auto get_process_pid_by_name(const char* ProcessName) -> DWORD
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
DWORD targetProcessId = 0;
const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE)
{
while (Process32Next(snapshot, &entry) == TRUE)
{
if (_stricmp(entry.szExeFile, ProcessName) == 0)
{
targetProcessId = entry.th32ProcessID;
break;
}
}
}
CloseHandle(snapshot);
return targetProcessId;
}
inline auto inject_dll(HANDLE handle, std::string_view dll_path) -> void
{
auto* dll_path_addr = VirtualAllocEx(handle, nullptr, dll_path.size(), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (!dll_path_addr)
return;
if (!WriteProcessMemory(handle, dll_path_addr, dll_path.data(), dll_path.size(), nullptr))
return;
const auto remote_thread = CreateRemoteThread(handle, nullptr, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(LoadLibraryA),
dll_path_addr, 0, nullptr);
if (!remote_thread)
return;
WaitForSingleObject(remote_thread, INFINITE);
}
}
namespace file
{
inline auto open_file_name(const char* filter = "All Files (*.dll)\0*.dll\0", HWND owner = nullptr) -> ::string
{
OPENFILENAME ofn;
char fileName[MAX_PATH] = "";
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = owner;
ofn.lpstrFilter = filter;
ofn.lpstrFile = fileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrInitialDir = validation::get_user().c_str();
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "";
::string fileNameStr;
if (GetOpenFileNameA(&ofn))
fileNameStr = fileName;
return fileNameStr;
}
}
}