-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
154 lines (121 loc) · 4.83 KB
/
main.cpp
File metadata and controls
154 lines (121 loc) · 4.83 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
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
143
144
145
146
147
148
149
150
151
152
153
154
#include <iostream>
#include <filesystem>
#include <windows.h>
#include <psapi.h>
#include <TlHelp32.h>
#include <Shlwapi.h>
//Library needed by Linker to check file existance
#pragma comment(lib, "Shlwapi.lib")
DWORD GetProcessByName(const char* lpProcessName)
{
char lpCurrentProcessName[255];
PROCESSENTRY32 ProcList{};
ProcList.dwSize = sizeof(ProcList);
const HANDLE hProcList = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcList == INVALID_HANDLE_VALUE)
return -1;
if (!Process32First(hProcList, &ProcList))
return -1;
wcstombs_s(nullptr, lpCurrentProcessName, ProcList.szExeFile, 255);
if (lstrcmpA(lpCurrentProcessName, lpProcessName) == 0)
return ProcList.th32ProcessID;
while (Process32Next(hProcList, &ProcList))
{
wcstombs_s(nullptr, lpCurrentProcessName, ProcList.szExeFile, 255);
if (lstrcmpA(lpCurrentProcessName, lpProcessName) == 0)
return ProcList.th32ProcessID;
}
return -1;
}
bool IsProcessRunning(const std::string& pName)
{
DWORD processes[1024];
DWORD cbNeeded;
DWORD cProcesses;
if (!EnumProcesses(processes, sizeof(processes), &cbNeeded))
return false;
cProcesses = cbNeeded / sizeof(DWORD);
for (DWORD i = 0; i < cProcesses; i++)
{
if (processes[i] == 0)
continue;
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processes[i]);
if (hProcess == NULL)
continue;
char buffer[MAX_PATH];
GetModuleBaseNameA(hProcess, NULL, buffer, MAX_PATH);
CloseHandle(hProcess);
if (pName == buffer)
return true;
}
return false;
}
VOID RunExecutable(LPCTSTR lpApplicationName)
{
// additional information
STARTUPINFO si;
PROCESS_INFORMATION pi;
// set the size of the structures
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
// start the program up
CreateProcess(lpApplicationName, // the path
NULL, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi // Pointer to PROCESS_INFORMATION structure (removed extra parentheses)
);
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
void InjectDLL(const int procID, const char* DllPath)
{
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID); // Opening the Process with All Access
// Allocate memory for the dllpath in the target process, length of the path string + null terminator
LPVOID pDllPath = VirtualAllocEx(handle, 0, strlen(DllPath) + 1, MEM_COMMIT, PAGE_READWRITE);
// Write the path to the address of the memory we just allocated in the target process
WriteProcessMemory(handle, pDllPath, (LPVOID)DllPath, strlen(DllPath) + 1, 0);
// Create a Remote Thread in the target process which calls LoadLibraryA as our dllpath as an argument -> program loads our dll
HANDLE hLoadThread = CreateRemoteThread(handle, 0, 0,
(LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA"), pDllPath, 0, 0);
WaitForSingleObject(hLoadThread, INFINITE); // Wait for the execution of our loader thread to finish
VirtualFreeEx(handle, pDllPath, strlen(DllPath) + 1, MEM_RELEASE); // Free the memory allocated for our dll path
printf("[+] Injected DLL");
}
int main() {
if (IsProcessRunning("OnlyUP-Win64-Shipping.exe")) {
printf("[+] Found running OnlyUp process...\n");
}
else {
printf("[i] Didnt found running OnlyUp process...\n");
printf("[i] Starting OnlyUp...\n");
LPCWSTR pathToExe = L".\\OnlyUP\\Binaries\\Win64\\OnlyUP-Win64-Shipping.exe";
ShellExecuteW(NULL, L"open", pathToExe, NULL, NULL, SW_SHOWNORMAL);
printf("[+] Started OnlyUp...\n");
}
Sleep(5000);
const DWORD pid = GetProcessByName("OnlyUP-Win64-Shipping.exe");
while (pid == (DWORD)-1) {
const DWORD pid = GetProcessByName("OnlyUP-Win64-Shipping.exe");
}
if (PathFileExists(L"OnlyUpMultiplayer.dll") == FALSE)
{
printf("[!] DLL file does NOT exist\n");
Sleep(10000);
return EXIT_FAILURE;
}
printf("[+] Located DLL and Process\n");
printf("[i] Injecting...\n");
std::filesystem::path path = std::filesystem::current_path();
path.append("OnlyUpMultiplayer.dll");
std::string pathToDLL = path.u8string();
InjectDLL(pid, pathToDLL.c_str());
Sleep(10000);
}