-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRains DLL Injector (x64).cpp
226 lines (220 loc) · 7.23 KB
/
Rains DLL Injector (x64).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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
#include <string>
#include <shobjidl.h>
BOOL IsProcessRunning(DWORD pid)
{
HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, pid);
DWORD ret = WaitForSingleObject(process, 0);
CloseHandle(process);
return ret == WAIT_TIMEOUT;
}
DWORD MyGetProcessId(std::wstring ProcessName) // non-conflicting function name
{
PROCESSENTRY32 pt;
HANDLE hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pt.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hsnap, &pt)) { // must call this first
do {
LPCTSTR proc = ProcessName.c_str();
if (!lstrcmpi(pt.szExeFile, proc)) {
CloseHandle(hsnap);
return pt.th32ProcessID;
}
} while (Process32Next(hsnap, &pt));
}
CloseHandle(hsnap);
return 0;
}
const char* OpenDialog()
{
COMDLG_FILTERSPEC ComDlgFS[1] = { {L"DLL files", L"*.dll"} };
IFileOpenDialog* pFileOpen = NULL;
IShellItem* pShellItem = NULL;
wchar_t* ppszName = NULL;
CoInitialize(NULL);
CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_IFileOpenDialog, (void**)(&pFileOpen));
pFileOpen->SetFileTypes(1, ComDlgFS);
pFileOpen->SetTitle(L"DLL File to inject");
pFileOpen->Show(0);
pFileOpen->GetResult(&pShellItem);
pShellItem->GetDisplayName(SIGDN_FILESYSPATH, &ppszName);
wprintf(L"%s\n", ppszName);
CoTaskMemFree(ppszName);
pShellItem->Release();
pFileOpen->Release();
CoUninitialize();
getchar();
return 0;
}
void Inject(DWORD pid, std::string way)
{
if (way == "LLA")
{
std::cout << "DLL Location -> ";
std::string dllName;
std::cin >> dllName;
size_t sz = strlen(dllName.c_str());
HANDLE hProcess;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
LPVOID lpBaseAddress;
lpBaseAddress = VirtualAllocEx(hProcess, NULL, sz, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(hProcess, lpBaseAddress, dllName.c_str(), sz, NULL);
HMODULE hModule = GetModuleHandle(L"kernel32.dll");
LPVOID lpStartAddress = GetProcAddress(hModule, "LoadLibraryA");
HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)lpStartAddress, lpBaseAddress, 0, NULL);
if (hThread)
{
std::cout << "Successfully Injected " << dllName << "\n";
std::cout << "App will be closed in 5 seconds.\n";
Sleep(5000);
}
else
{
std::cout << "Failed to Inject " << dllName << "\n";
std::cout << "App will be closed in 5 seconds.\n";
Sleep(5000);
}
}
else if (way == "TH")
{
std::cout << "\nSoon..\n";
std::cout << "App will be closed in 5 seconds.\n";
Sleep(5000);
}
else if (way == "MM")
{
std::cout << "\nSoon..\n";
std::cout << "App will be closed in 5 seconds.\n";
Sleep(5000);
}
else
{
std::cout << "Injection type is invalid, Please contact the application developer.";
std::cout << "App will be closed in 5 seconds.\n";
Sleep(5000);
}
}
void Kill(DWORD pid)
{
HANDLE handy;
handy = OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, TRUE, pid);
TerminateProcess(handy, 0);
std::cout << "Process Has Been Killed.\n";
std::cout << "App will be closed in 5 seconds.\n";
Sleep(5000);
}
int main()
{
SetConsoleTitleA("Rains DLL Injector (x64)");
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h, 4);
std::cout << "Rains DLL Injector\n";
std::cout << "Made by <Ra1n6666/>#6666\n\n";
SetConsoleTextAttribute(h, 15);
std::cout << "Enter Process Name -> ";
std::wstring process;
std::wcin >> process;
DWORD procid = MyGetProcessId(process);
if (procid != 0)
{
SetConsoleTextAttribute(h, 2);
std::cout << "Process Is Valid.\n";
SetConsoleTextAttribute(h, 15);
std::cout << "\n----------Process----------\n";
std::cout << "Process Bits -> ";
SetConsoleTextAttribute(h, 2);
std::wcout << "Soon..\n";
SetConsoleTextAttribute(h, 15);
std::cout << "Process Name -> ";
SetConsoleTextAttribute(h, 2);
std::wcout << process << "\n";
SetConsoleTextAttribute(h, 15);
std::cout << "Process ID -> ";
SetConsoleTextAttribute(h, 2);
std::cout << procid << "\n";
SetConsoleTextAttribute(h, 15);
std::cout << "---------------------------\n\n";
SetConsoleTextAttribute(h, 15);
std::cout << "[";
SetConsoleTextAttribute(h, 2);
std::cout << "1";
SetConsoleTextAttribute(h, 15);
std::cout << "] ";
std::cout << "Inject DLL\n";
SetConsoleTextAttribute(h, 15);
std::cout << "[";
SetConsoleTextAttribute(h, 4);
std::cout << "2";
SetConsoleTextAttribute(h, 15);
std::cout << "] ";
std::cout << "Kill Process\n";
std::cout << "Choose An Option -> ";
std::string option;
std::cin >> option;
if (option == "1")
{
SetConsoleTextAttribute(h, 15);
std::cout << "\n[";
SetConsoleTextAttribute(h, 2);
std::cout << "1";
SetConsoleTextAttribute(h, 15);
std::cout << "] ";
std::cout << "Load Library\n";
SetConsoleTextAttribute(h, 15);
std::cout << "[";
SetConsoleTextAttribute(h, 2);
std::cout << "2";
SetConsoleTextAttribute(h, 15);
std::cout << "] ";
std::cout << "Thread Hijacking\n";
SetConsoleTextAttribute(h, 15);
std::cout << "[";
SetConsoleTextAttribute(h, 2);
std::cout << "3";
SetConsoleTextAttribute(h, 15);
std::cout << "] ";
std::cout << "Manual Map\n";
std::cout << "Injection Type -> ";
std::string type;
std::cin >> type;
if (type == "1")
{
Inject(procid, "LLA");
}
else if (type == "2")
{
Inject(procid, "TH");
}
else if (type == "3")
{
Inject(procid, "MM");
}
else
{
std::cout << "Choice is invalid.\n";
std::cout << "App will be closed in 5 seconds.\n";
Sleep(5000);
}
}
else if (option == "2")
{
Kill(procid);
}
else
{
std::cout << "Choice is invalid.\n";
std::cout << "App will be closed in 5 seconds.\n";
Sleep(5000);
}
}
else
{
SetConsoleTextAttribute(h, 4);
std::cout << "\nProcess Is Invalid.\n";
SetConsoleTextAttribute(h, 15);
std::cout << "App will be closed in 5 seconds.\n";
Sleep(5000);
}
}