Skip to content

Commit 477109a

Browse files
committed
More error checking, fixed readme (updated this one by accident lmao), proper unicode implementation of setwindowhookex injection, GH Injector SM is also a unicode project now
1 parent 390faa4 commit 477109a

14 files changed

+46
-29
lines changed

GH Injector Library/Error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@
282282
#define HOOK_SCAN_ERR_CREATE_PROCESS_FAILED 0x50000008 //CreateProcessW : win32 error
283283
#define HOOK_SCAN_ERR_WAIT_FAILED 0x50000009 //WaitForSingleObject : win32 error
284284
#define HOOK_SCAN_ERR_WAIT_TIMEOUT 0x5000000A //WaitForSingleObject : waiting timed out
285+
#define HOOK_SCAN_ERR_BUFFER_TOO_SMALL 0x5000000B //internal error : the buffer passed to ValidateInjectionFunctions is too small
285286

286287

287288

GH Injector Library/Handle Hijacking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ NTSTATUS EnumHandles(char * pBuffer, ULONG Size, ULONG * SizeOut, UINT & Count)
1111

1212
if (NT_FAIL(ntRet))
1313
{
14-
LOG("Failed to grab handle list\n");
14+
LOG("Failed to grab handle list: %08X\n", ntRet);
1515

1616
return ntRet;
1717
}

GH Injector Library/Hook Scanner.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ bool __stdcall ValidateInjectionFunctions(DWORD dwTargetProcessId, DWORD & Error
326326
{
327327
LOG("Provided buffer too small\n");
328328

329+
ErrorCode = HOOK_SCAN_ERR_BUFFER_TOO_SMALL;
330+
329331
return false;
330332
}
331333

@@ -381,10 +383,10 @@ bool __stdcall RestoreInjectionFunctions(DWORD dwTargetProcessId, DWORD & ErrorC
381383
*CountOut = SuccessCount;
382384
}
383385

384-
LOG("%d of %d hook(s) restored\n", SuccessCount, Count);
385-
386386
CloseHandle(hTargetProc);
387387

388+
LOG("%d of %d hook(s) restored\n", SuccessCount, Count);
389+
388390
return true;
389391
}
390392

GH Injector Library/Injection Generic WOW64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ DWORD InjectDLL_WOW64(const wchar_t * szDllFile, HANDLE hTargetProc, INJECTION_M
109109

110110
LOG("Shell written to memory\n");
111111

112-
LOG("Enterting StartRoutine_WOW64\n");
112+
LOG("Entering StartRoutine_WOW64\n");
113113

114114
DWORD remote_ret = 0;
115115
DWORD dwRet = StartRoutine_WOW64(hTargetProc, (f_Routine_WOW64)(MDWD(pShell)), MDWD(pArg), Method, (Flags & INJ_THREAD_CREATE_CLOAKED) != 0, remote_ret, Timeout, error_data);

GH Injector Library/Injection Generic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ DWORD InjectDLL(const wchar_t * szDllFile, HANDLE hTargetProc, INJECTION_MODE Mo
9696

9797
LOG("Shell written to memory\n");
9898

99-
LOG("Enterting StartRoutine\n");
99+
LOG("Entering StartRoutine\n");
100100

101101
DWORD remote_ret = 0;
102102
DWORD dwRet = StartRoutine(hTargetProc, ReCa<f_Routine>(pShell), pArg, Method, (Flags & INJ_THREAD_CREATE_CLOAKED) != 0, remote_ret, Timeout, error_data);

GH Injector Library/Injection.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,19 @@ DWORD HijackHandle(INJECTIONDATAW * pData, ERROR_DATA & error_data)
488488
LastErrCode = INJ_ERR_CANT_OPEN_PROCESS;
489489
INIT_ERROR_DATA(error_data, GetLastError());
490490

491+
LOG("Failed to attach to process %06X\n", i.OwnerPID);
492+
491493
continue;
492494
}
495+
496+
LOG("Attached to process %06X\n", i.OwnerPID);
493497

494498
if (!IsElevatedProcess(hHijackProc) || !IsNativeProcess(hHijackProc))
495499
{
496500
LastErrCode = INJ_ERR_HIJACK_NO_NATIVE_HANDLE;
497501
INIT_ERROR_DATA(error_data, INJ_ERR_ADVANCED_NOT_DEFINED);
498502

499-
LOG("Can't open process %06X\n", i.OwnerPID);
503+
LOG("Process isn't elevated or native\n");
500504

501505
CloseHandle(hHijackProc);
502506

@@ -518,7 +522,7 @@ DWORD HijackHandle(INJECTIONDATAW * pData, ERROR_DATA & error_data)
518522
continue;
519523
}
520524

521-
LOG("Injection module loaded\n");
525+
LOG("Injection module loaded into hijack process\n");
522526

523527
HINSTANCE hInjectionModuleEx = hijack_data.hDllOut;
524528
f_Routine pRemoteInjectW = ReCa<f_Routine>(ReCa<UINT_PTR>(InjectW) - ReCa<UINT_PTR>(g_hInjMod) + ReCa<UINT_PTR>(hInjectionModuleEx));
@@ -554,6 +558,8 @@ DWORD HijackHandle(INJECTIONDATAW * pData, ERROR_DATA & error_data)
554558
continue;
555559
}
556560

561+
LOG("Handle value: %04X\n", i.hValue);
562+
557563
pData->hHandleValue = 0;
558564

559565
LOG("Injection data written to hijack process\n");

GH Injector Library/Manual Mapping WOW64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ DWORD MMAP_WOW64::ManualMap_WOW64(const wchar_t * szDllFile, HANDLE hTargetProc,
120120

121121
LOG("Shell written to memory\n");
122122

123-
LOG("Enterting StartRoutine_WOW64\n");
123+
LOG("Entering StartRoutine_WOW64\n");
124124

125125
DWORD remote_ret = 0;
126126
DWORD dwRet = StartRoutine_WOW64(hTargetProc, (f_Routine_WOW64)(MDWD(pShell)), MDWD(pArg), Method, (Flags & INJ_THREAD_CREATE_CLOAKED) != 0, remote_ret, Timeout, error_data);

GH Injector Library/Manual Mapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ DWORD MMAP_NATIVE::ManualMap(const wchar_t * szDllFile, HANDLE hTargetProc, LAUN
128128

129129
LOG("Shell written to memory\n");
130130

131-
LOG("Enterting StartRoutine\n");
131+
LOG("Entering StartRoutine\n");
132132

133133
DWORD remote_ret = 0;
134134
DWORD dwRet = StartRoutine(hTargetProc, ReCa<f_Routine>(pShell), pArg, Method, (Flags & INJ_THREAD_CREATE_CLOAKED) != 0, remote_ret, Timeout, error_data);

GH Injector Library/SetWindowsHookEx WOW64.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ DWORD SR_SetWindowsHookEx_WOW64(HANDLE hTargetProc, f_Routine_WOW64 pRoutine, DW
9898
std::wstring smPath = g_RootPathW;
9999
smPath += SM_EXE_FILENAME86;
100100

101-
wchar_t cmdLine[] = L"\"" SM_EXE_FILENAME86 "\"";
101+
wchar_t cmdLine[] = L"\"" SM_EXE_FILENAME86 "\" 0";
102102

103103
PROCESS_INFORMATION pi{ 0 };
104104
STARTUPINFOW si{ 0 };
@@ -156,6 +156,8 @@ DWORD SR_SetWindowsHookEx_WOW64(HANDLE hTargetProc, f_Routine_WOW64 pRoutine, DW
156156

157157
LOG("Token prepared\n");
158158

159+
LOG("Launching %ls:\n %ls\n", SM_EXE_FILENAME86, cmdLine);
160+
159161
if (!CreateProcessAsUserW(hAdminToken, smPath.c_str(), cmdLine, nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi))
160162
{
161163
INIT_ERROR_DATA(error_data, GetLastError());
@@ -178,6 +180,8 @@ DWORD SR_SetWindowsHookEx_WOW64(HANDLE hTargetProc, f_Routine_WOW64 pRoutine, DW
178180
}
179181
else
180182
{
183+
LOG("Launching %ls:\n %ls\n", SM_EXE_FILENAME86, cmdLine);
184+
181185
if (!CreateProcessW(smPath.c_str(), cmdLine, nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi))
182186
{
183187
INIT_ERROR_DATA(error_data, GetLastError());

GH Injector Library/SetWindowsHookEx.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ DWORD SR_SetWindowsHookEx(HANDLE hTargetProc, f_Routine pRoutine, void * pArg, U
138138
std::wstring smPath = g_RootPathW;
139139
smPath += SM_EXE_FILENAME;
140140

141-
wchar_t cmdLine[] = L"\"" SM_EXE_FILENAME "\"";
141+
wchar_t cmdLine[] = L"\"" SM_EXE_FILENAME "\" 0";
142142

143143
PROCESS_INFORMATION pi{ 0 };
144144
STARTUPINFOW si{ 0 };
@@ -199,6 +199,8 @@ DWORD SR_SetWindowsHookEx(HANDLE hTargetProc, f_Routine pRoutine, void * pArg, U
199199

200200
LOG("Token prepared\n");
201201

202+
LOG("Launching %ls:\n %ls\n", SM_EXE_FILENAME, cmdLine);
203+
202204
if (!CreateProcessAsUserW(hAdminToken, smPath.c_str(), cmdLine, nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi))
203205
{
204206
INIT_ERROR_DATA(error_data, GetLastError());
@@ -221,7 +223,9 @@ DWORD SR_SetWindowsHookEx(HANDLE hTargetProc, f_Routine pRoutine, void * pArg, U
221223
CloseHandle(hUserToken);
222224
}
223225
else
224-
{
226+
{
227+
LOG("Launching %ls:\n %ls\n", SM_EXE_FILENAME, cmdLine);
228+
225229
if (!CreateProcessW(smPath.c_str(), cmdLine, nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi))
226230
{
227231
INIT_ERROR_DATA(error_data, GetLastError());

GH Injector Library/Tools.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,9 @@ bool IsElevatedProcess(HANDLE hTargetProc)
143143

144144
void ErrorLog(ERROR_INFO * info)
145145
{
146-
wchar_t ErrorLogName[] = L"GH_Inj_Log.txt";
146+
auto FullPath = g_RootPathW;
147+
FullPath += L"GH_Inj_Log.txt";
147148

148-
wchar_t FullPath[MAX_PATH]{ 0 };
149-
StringCbCopyW(FullPath, sizeof(FullPath), g_RootPathW.c_str());
150-
StringCbCatW(FullPath, sizeof(FullPath), ErrorLogName);
151-
152149
time_t time_raw = time(nullptr);
153150
tm time_info;
154151
localtime_s(&time_info, &time_raw);
@@ -189,7 +186,7 @@ void ErrorLog(ERROR_INFO * info)
189186
std::wofstream error_log(FullPath, std::ios_base::out | std::ios_base::app);
190187
if (!error_log.good())
191188
{
192-
LOG("Failed to open/create error log file:\n%ls\n", FullPath);
189+
LOG("Failed to open/create error log file:\n%ls\n", FullPath.c_str());
193190

194191
return;
195192
}
@@ -226,6 +223,9 @@ std::wstring InjectionModeToString(INJECTION_MODE mode)
226223
case INJECTION_MODE::IM_LdrpLoadDll:
227224
return std::wstring(L"LdrpLoadDll");
228225

226+
case INJECTION_MODE::IM_LdrpLoadDllInternal:
227+
return std::wstring(L"LdrpLoadDllInternal");
228+
229229
case INJECTION_MODE::IM_ManualMap:
230230
return std::wstring(L"ManualMap");
231231

GH Injector Library/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ BOOL WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, void * pReserved)
8686
if (sym_ntdll_native_ret.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready)
8787
{
8888
LOG("Attempting to interrupt native ntdll.pdb donwload thread\n");
89+
8990
sym_ntdll_native.Interrupt();
91+
9092
if (sym_ntdll_native_ret.wait_for(std::chrono::milliseconds(100)) != std::future_status::ready)
9193
{
9294
LOG("Native ntdll pdb download thread didn't exit properly.\n");
@@ -97,7 +99,9 @@ BOOL WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, void * pReserved)
9799
if (sym_ntdll_wow64_ret.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready)
98100
{
99101
LOG("Attempting to interrupt wow64 ntdll.pdb donwload thread\n");
102+
100103
sym_ntdll_wow64.Interrupt();
104+
101105
if (sym_ntdll_wow64_ret.wait_for(std::chrono::milliseconds(100)) != std::future_status::ready)
102106
{
103107
LOG("Wow64 ntdll pdb download thread didn't exit properly.\n");

GH Injector SM/GH Injector SM/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
#include "main.h"
44

5-
int main(int argc, char * argv[])
5+
#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:wmainCRTStartup")
6+
7+
int wmain(int argc, wchar_t * argv[])
68
{
79
if (argc < 2)
810
{
@@ -16,10 +18,10 @@ int main(int argc, char * argv[])
1618
#ifndef _WIN64
1719
else if (argv[1][0] == '1')
1820
{
19-
HANDLE hEventStart = reinterpret_cast<HANDLE>(strtol(argv[2], nullptr, 0x10));
21+
HANDLE hEventStart = reinterpret_cast<HANDLE>(wcstol(argv[2], nullptr, 0x10));
2022
SetEvent(hEventStart);
2123

22-
HANDLE hEventEnd = reinterpret_cast<HANDLE>(strtol(argv[3], nullptr, 0x10));
24+
HANDLE hEventEnd = reinterpret_cast<HANDLE>(wcstol(argv[3], nullptr, 0x10));
2325
WaitForSingleObject(hEventEnd, INFINITE);
2426

2527
CloseHandle(hEventStart);

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,14 @@ Session seperation can be bypassed with all methods.
3131
- TLS initialization
3232
- Security cookie initalization
3333

34-
### Additional features
34+
### Additional features:
35+
3536
- Various cloaking options
3637
- PEB unlinking
3738
- PE header cloaking
3839
- Thread cloaking
3940
- Handle hijacking
4041
- Hook scanning/restoring
41-
- Fancy process picker
42-
43-
### Shortcut generation:
44-
45-
Too lazy to reopen the injector everytime you want to inject the same dll? Generate a shortcut.
46-
Select the dll you want to inject in the list, configure the options you want and make sure the target process is running. Then click the "Generate Shortcut" button and a shortcut will be generated in the directory of the injector.
47-
Now you can just double click to perform the injection. The spawned console injector waits for the specified target process to launch.
4842

4943
----
5044

0 commit comments

Comments
 (0)