Skip to content

Commit 94eebf8

Browse files
committed
Added LdrpLoadDllInternal injection, small modifications to manual mapping, integrated custom print function and callback integration and added a ton of debug prints, wow64 shellcodes not updated, unstable release
1 parent 138052f commit 94eebf8

34 files changed

+1593
-390
lines changed

GH Injector Library/Download Manager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ BOOL DownloadManager::SetInterruptEvent(HANDLE hInterrupt)
115115
CloseHandle(m_hInterruptEvent);
116116
}
117117

118+
LOG("New interrupt event specified\n");
119+
118120
return DuplicateHandle(GetCurrentProcess(), hInterrupt, GetCurrentProcess(), &m_hInterruptEvent, NULL, FALSE, DUPLICATE_SAME_ACCESS);
119121
}
120122

GH Injector Library/Eject.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22

33
#include "Eject.h"
44

5+
//gonna make this better eventually, forgot it existed
6+
57
void EjectDll(HANDLE hTargetProc, HINSTANCE hModBase)
68
{
9+
LOG("Ejecting injection library from hijack process\n");
10+
711
HANDLE hThread = nullptr;
812
if (FAILED(NATIVE::NtCreateThreadEx(&hThread, THREAD_ALL_ACCESS, nullptr, hTargetProc, FreeLibrary, ReCa<void*>(hModBase), NULL, 0, 0, 0, nullptr)))
913
{
14+
LOG("Failed to eject library\n");
15+
1016
return;
1117
}
1218

13-
WaitForSingleObject(hThread, INFINITE);
19+
WaitForSingleObject(hThread, 500);
1420

1521
CloseHandle(hThread);
22+
23+
LOG("Library ejected\n");
1624
}

GH Injector Library/Error.h

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,16 @@
6161
#define INJ_ERR_LLEXW_FAILED 0x00000028 //LoadLibraryExW : win32 error : LoadLibraryExW failed loading the dll
6262
#define INJ_ERR_LDRLDLL_FAILED 0x00000029 //LdrLoadDll : NTSTATUS : LdrLoadDll failed loading the dll
6363
#define INJ_ERR_LDRPLDLL_FAILED 0x0000002A //LdrpLoadDll : NTSTATUS : LdrpLoadDll failed loading the dll
64-
#define INJ_ERR_CANT_GET_PEB 0x0000002B //__readgsqword or __readfsdword : - : reading the linear address of the PEB failed
65-
#define INJ_ERR_INVALID_PEB_DATA 0x0000002C //internal error : - : peb data required to erase/fake header or unlike the module from the peb wasn't findable
66-
#define INJ_ERR_UPDATE_PROTECTION_FAILED 0x0000002D //NtProtectVirtualMemory : NTSTATUS : updating the page protection of the pe header failed
67-
#define INJ_ERR_WOW64_NTDLL_MISSING 0x0000002E //internal error : - : can't resolve address of the wow64 ntdll
68-
#define INJ_ERR_INVALID_PATH_SEPERATOR 0x0000002F //internal error : - : can't find '\' in a path. '/' as seperators aren't supported.
64+
#define INJ_ERR_LDRPLDLLINTERNAL_FAILED 0x0000002B //LdrpLoadDllInternal : NTSTATUS : LdrpLoadDllInternal failed loading the dll
65+
#define INJ_ERR_CANT_GET_PEB 0x0000002C //__readgsqword or __readfsdword : - : reading the linear address of the PEB failed
66+
#define INJ_ERR_INVALID_PEB_DATA 0x0000002D //internal error : - : peb data required to erase/fake header or unlike the module from the peb wasn't findable
67+
#define INJ_ERR_UPDATE_PROTECTION_FAILED 0x0000002E //NtProtectVirtualMemory : NTSTATUS : updating the page protection of the pe header failed
68+
#define INJ_ERR_WOW64_NTDLL_MISSING 0x0000002F //internal error : - : can't resolve address of the wow64 ntdll
69+
#define INJ_ERR_INVALID_PATH_SEPERATOR 0x00000030 //internal error : - : can't find '\' in a path. '/' as seperators aren't supported
70+
#define INJ_ERR_LDRP_PREPROCESS_FAILED 0x00000031 //LdrpPreprocessDllName : NTSTATUS : preprocessing the dll name for LdrpLoadDll(Internal) failed
71+
#define INJ_ERR_INVALID_POINTER 0x00000032 //internal error : - : an invalid funtion pointer was passed to SetRawPrintCallback
72+
#define INJ_ERR_NOT_IMPLEMENTED 0x00000033 //internal error : - : the module was compiled without DEBUG_INFO being defined, check pch.h for more information if you want to redirect debug output
73+
#define INJ_ERR_KERNEL32_MISSING 0x00000034 //internal error : - : failed to resolve address of kernel32.dll (native)
6974

7075

7176
///////////////////
@@ -140,24 +145,25 @@
140145
#define SR_HT_ERR_RESUME_FAIL 0x10200009 //ResumeThread : win32 error : resuming the thread failed
141146
#define SR_HT_ERR_REMOTE_TIMEOUT 0x1020000A //internal error : - : execution time exceeded SR_REMOTE_TIMEOUT (can't be deallocated safely)
142147
#define SR_HT_ERR_REMOTE_PENDING_TIMEOUT 0x1020000B //internal error : - : execution time exceeded SR_REMOTE_TIMEOUT while pending (can be deallocated safely)
148+
#define SR_HT_ERR_RPM_FAIL 0x1020000C //ReadProcessMemory : win32 error : reading the results of the shellcode failed
143149

144150
////////////////////
145151
///SetWindowsHookEx
146-
//Source : error description
147-
148-
#define SR_SWHEX_ERR_CANT_QUERY_INFO_PATH 0x10300001 //internal error : can't resolve own module filepath
149-
#define SR_SWHEX_ERR_CANT_OPEN_INFO_TXT 0x10300002 //internal error : can't open swhex info file
150-
#define SR_SWHEX_ERR_VAE_FAIL 0x10300003 //VirtualAllocEx : win32 error
151-
#define SR_SWHEX_ERR_CNHEX_MISSING 0x10300004 //GetProcAddressEx : can't find pointer to CallNextHookEx
152-
#define SR_SWHEX_ERR_WPM_FAIL 0x10300005 //WriteProcessMemory : win32 error
153-
#define SR_SWHEX_ERR_WTSQUERY_FAIL 0x10300006 //WTSQueryUserToken : win32 error
154-
#define SR_SWHEX_ERR_DUP_TOKEN_FAIL 0x10300007 //DuplicateTokenEx : win32 error
155-
#define SR_SWHEX_ERR_GET_ADMIN_TOKEN_FAIL 0x10300008 //GetTokenInformation : win32 error
156-
#define SR_SWHEX_ERR_CANT_CREATE_PROCESS 0x10300009 //CreateProcessAsUserW : win32 error
157-
//CreateProcessW : win32 error
158-
#define SR_SWHEX_ERR_SWHEX_TIMEOUT 0x1030000A //WaitForSingleObject : win32 error
159-
#define SR_SWHEX_ERR_SWHEX_EXT_ERROR 0x1030000B //SM_EXE_FILENAME.exe : "GH Injector SM - XX.exe" error code, 0x30100001 - 0x30100006 (see below) or win32 exception
160-
#define SR_SWHEX_ERR_REMOTE_TIMEOUT 0x1030000C //internal error : execution time exceeded SR_REMOTE_TIMEOUT
152+
//Source : advanced error type : error description
153+
154+
#define SR_SWHEX_ERR_CANT_OPEN_INFO_TXT 0x10300001 //internal error : - : can't open swhex info file
155+
#define SR_SWHEX_ERR_CANT_ALLOC_MEM 0x10300002 //VirtualAllocEx : win32 error : memory allocation for the shellcode failed
156+
#define SR_SWHEX_ERR_WPM_FAIL 0x10300003 //WriteProcessMemory : win32 error : writing the shellcode into the target process' memory failed
157+
#define SR_SWHEX_ERR_WTSQUERY_FAIL 0x10300004 //WTSQueryUserToken : win32 error : failed to query the token for the target process user session
158+
#define SR_SWHEX_ERR_DUP_TOKEN_FAIL 0x10300005 //DuplicateTokenEx : win32 error : failed to duplicate the token for the target process user session
159+
#define SR_SWHEX_ERR_GET_ADMIN_TOKEN_FAIL 0x10300006 //GetTokenInformation : win32 error : failed to retrieve information from the token handle
160+
#define SR_SWHEX_ERR_CANT_CREATE_PROCESS 0x10300007 //CreateProcessAsUserW : win32 error : failed to launch SM_EXE_FILENAME.exe to execute shellcode
161+
//CreateProcessW : win32 error : failed to launch SM_EXE_FILENAME.exe to execute shellcode
162+
#define SR_SWHEX_ERR_SWHEX_TIMEOUT 0x10300008 //WaitForSingleObject : win32 error :
163+
#define SR_SWHEX_ERR_REMOTE_TIMEOUT 0x10300009 //internal error : - : execution time exceeded SR_REMOTE_TIMEOUT
164+
#define SR_SWHEX_ERR_RPM_FAIL 0x1030000A //ReadProcessMemory : win32 error : reading the results of the shellcode failed
165+
166+
#define SR_SWHEX_ERR_SWHEX_EXT_ERROR 0x1030000B //SM_EXE_FILENAME.exe : "GH Injector SM - XX.exe" error code, 0x30100001 - 0x30100006 (see below) or win32 exception
161167

162168
///////////////
163169
///QueueUserAPC
@@ -168,7 +174,8 @@
168174
#define SR_QUAPC_ERR_WPM_FAIL 0x10400003 //WriteProcessMemory : win32 error : writing the shellcode into the target process' memory failed
169175
#define SR_QUAPC_ERR_PROC_INFO_FAIL 0x10400004 //internal error : - : can't grab process information
170176
#define SR_QUAPC_ERR_NO_THREADS 0x10400005 //internal error : - : no threads to queue an apc to
171-
#define SR_QUAPC_ERR_REMOTE_TIMEOUT 0x10400006 //internal error : - : execution time exceeded SR_REMOTE_TIMEOUT (can be deallocated safely)
177+
#define SR_QUAPC_ERR_REMOTE_TIMEOUT 0x10400006 //internal error : - : execution time exceeded SR_REMOTE_TIMEOUT
178+
#define SR_QUAPC_ERR_RPM_FAIL 0x10400007 //WriteProcessMemory : win32 error : reading the results of the shellcode failed
172179

173180

174181

@@ -298,14 +305,4 @@ data.Line = __LINE__; \
298305
memset(data.szFileName, 0, sizeof(data.szFileName)); \
299306
memset(data.szFunctionName, 0, sizeof(data.szFunctionName)); \
300307
memcpy(data.szFileName, __FILENAMEW__, ((size_t)lstrlenW(__FILENAMEW__)) * 2); \
301-
memcpy(data.szFunctionName, __FUNCTIONW__, ((size_t)lstrlenW(__FUNCTIONW__)) * 2);
302-
303-
//#define DEBUG_INFO
304-
305-
#ifdef DEBUG_INFO
306-
#define LOG printf
307-
#else
308-
#define LOG
309-
#endif
310-
311-
//#define DUMP_SHELLCODE
308+
memcpy(data.szFunctionName, __FUNCTIONW__, ((size_t)lstrlenW(__FUNCTIONW__)) * 2);

GH Injector Library/GH Injector Library.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
<WarningLevel>Level4</WarningLevel>
151151
<ConformanceMode>true</ConformanceMode>
152152
<DebugInformationFormat>None</DebugInformationFormat>
153-
<TreatWarningAsError>false</TreatWarningAsError>
153+
<TreatWarningAsError>true</TreatWarningAsError>
154154
<PrecompiledHeader>Use</PrecompiledHeader>
155155
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
156156
<CallingConvention>FastCall</CallingConvention>

GH Injector Library/Handle Hijacking.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ 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");
15+
1416
return ntRet;
1517
}
1618

1719
auto * pHandleInfo = ReCa<SYSTEM_HANDLE_INFORMATION*>(pBuffer);
1820
Count = pHandleInfo->NumberOfHandles;
1921

22+
LOG("%d handles found\n", Count);
23+
2024
return ntRet;
2125
}
2226

@@ -64,7 +68,11 @@ std::vector<handle_data> FindProcessHandles(DWORD TargetPID, DWORD WantedHandleA
6468
std::vector<handle_data> Ret;
6569
DWORD OwnPID = GetCurrentProcessId();
6670

67-
for (auto i : EnumProcessHandles())
71+
auto handles = EnumProcessHandles();
72+
73+
LOG("%d process handles found\n", (DWORD)handles.size());
74+
75+
for (const auto & i : handles)
6876
{
6977
if ((i.GrantedAccess & WantedHandleAccess) != WantedHandleAccess)
7078
{
@@ -99,5 +107,7 @@ std::vector<handle_data> FindProcessHandles(DWORD TargetPID, DWORD WantedHandleA
99107
CloseHandle(hCurrentProc);
100108
}
101109

110+
LOG("%d handle(s) to target process found\n", (DWORD)Ret.size());
111+
102112
return Ret;
103113
}

GH Injector Library/Hook Scanner WOW64.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ bool ScanForHook_WOW64(HookInfo & Info, HANDLE hTargetProc, HANDLE hRefProcess)
1111
{
1212
Info.ErrorCode = HOOK_SCAN_ERR_GETPROCADDRESS_FAILED;
1313

14+
LOG("GetProcAddressEx_WOW64 failed\n");
15+
1416
return false;
1517
}
1618

@@ -20,6 +22,8 @@ bool ScanForHook_WOW64(HookInfo & Info, HANDLE hTargetProc, HANDLE hRefProcess)
2022
{
2123
Info.ErrorCode = HOOK_SCAN_ERR_READ_PROCESS_MEMORY_FAILED;
2224

25+
LOG("ReadProcessMemory failed: %08X\n", GetLastError());
26+
2327
return false;
2428
}
2529

@@ -28,6 +32,8 @@ bool ScanForHook_WOW64(HookInfo & Info, HANDLE hTargetProc, HANDLE hRefProcess)
2832
{
2933
Info.ErrorCode = HOOK_SCAN_ERR_READ_PROCESS_MEMORY_FAILED;
3034

35+
LOG("ReadProcessMemory failed: %08X\n", GetLastError());
36+
3137
return false;
3238
}
3339

0 commit comments

Comments
 (0)