Skip to content

Commit 06be54d

Browse files
committed
Small Manual Mapping improvement, updated shells, added function to dump shells into txt file (define DUMP_SHELLCODE in Error.h (bottom)), deleted a dumb line by mambda in the symbol parser
1 parent 63f4684 commit 06be54d

8 files changed

+112
-7
lines changed

GH Injector Library/Error.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,6 @@ memcpy(data.szFunctionName, __FUNCTIONW__, ((size_t)lstrlenW(__FUNCTIONW__)) * 2
301301
#define LOG printf
302302
#else
303303
#define LOG
304-
#endif
304+
#endif
305+
306+
//#define DUMP_SHELLCODE

GH Injector Library/Injection Generic.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ DWORD InjectionShell_End();
1212

1313
DWORD InjectDLL(const wchar_t * szDllFile, HANDLE hTargetProc, INJECTION_MODE Mode, LAUNCH_METHOD Method, DWORD Flags, HINSTANCE & hOut, DWORD Timeout, ERROR_DATA & error_data)
1414
{
15+
#if !defined(_WIN64) && defined (DUMP_SHELLCODE)
16+
auto length = ReCa<BYTE*>(InjectionShell_End) - ReCa<BYTE*>(InjectionShell);
17+
DumpShellcode(ReCa<BYTE*>(InjectionShell), length, L"InjectionShell_WOW64");
18+
#endif
19+
1520
LOG("InjectDll called\n");
1621

1722
if (Mode == INJECTION_MODE::IM_ManualMap)

GH Injector Library/Manual Mapping.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ DWORD ManualMapping_Shell_End();
1212

1313
DWORD MMAP_NATIVE::ManualMap(const wchar_t * szDllFile, HANDLE hTargetProc, LAUNCH_METHOD Method, DWORD Flags, HINSTANCE & hOut, DWORD Timeout, ERROR_DATA & error_data)
1414
{
15+
#if !defined(_WIN64) && defined (DUMP_SHELLCODE)
16+
auto length = ReCa<BYTE*>(ManualMapping_Shell_End) - ReCa<BYTE*>(ManualMapping_Shell);
17+
DumpShellcode(ReCa<BYTE*>(ManualMapping_Shell), length, L"ManualMapping_Shell_WOW64");
18+
#endif
19+
1520
LOG("Begin ManualMap\n");
1621

1722
MANUAL_MAPPING_DATA data{ 0 };

GH Injector Library/Symbol Parser.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ bool SYMBOL_PARSER::VerifyExistingPdb(const GUID & guid)
112112
streams.insert({ i, numbers });
113113
}
114114

115-
auto pdb_info_stream = streams.at(1);
116-
auto pdb_info_page_index = pdb_info_stream.at(0);
115+
auto pdb_info_page_index = streams.at(1).at(0);
117116

118117
auto * stream_data = ReCa<GUID_StreamData*>(pdb_raw + (size_t)(pdb_info_page_index) * pPDBHeader->page_size);
119118

GH Injector Library/Tools.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,63 @@ std::wstring LaunchMethodToString(LAUNCH_METHOD method)
242242
}
243243

244244
return std::wstring(L"bruh moment");
245+
}
246+
247+
void DumpShellcode(BYTE * start, int length, const wchar_t * szShellname)
248+
{
249+
wchar_t Shellcodename[] = L"Shellcodes.txt";
250+
251+
wchar_t FullPath[MAX_PATH]{ 0 };
252+
StringCbCopyW(FullPath, sizeof(FullPath), g_RootPathW.c_str());
253+
StringCbCatW(FullPath, sizeof(FullPath), Shellcodename);
254+
255+
std::wofstream shellcodes(FullPath, std::ios_base::out | std::ios_base::app);
256+
if (!shellcodes.good())
257+
{
258+
LOG("Failed to open/create shellcodename.txt file:\n%ls\n", FullPath);
259+
260+
return;
261+
}
262+
263+
shellcodes << L"inline unsigned char " << szShellname << L"[] =\n";
264+
shellcodes << L"{";
265+
266+
int row_length = 500;
267+
int char_count = 6 * length - 2 + (length / row_length + 1) * 2 + 1;
268+
wchar_t * array_out = new wchar_t[char_count]();
269+
270+
if (!array_out)
271+
{
272+
LOG("Failed to allocate buffer for shellcode data\n");
273+
274+
shellcodes.close();
275+
}
276+
277+
int idx = 0;
278+
279+
for (auto i = 0; i < length; ++i)
280+
{
281+
if (!(i % row_length))
282+
{
283+
array_out[idx++] = '\n';
284+
array_out[idx++] = '\t';
285+
}
286+
287+
swprintf_s(&array_out[idx], char_count - idx, L"0x%02X", start[i]);
288+
289+
idx += 4;
290+
291+
if (i == length - 1)
292+
{
293+
break;
294+
}
295+
296+
array_out[idx++] = ',';
297+
array_out[idx++] = ' ';
298+
}
299+
300+
shellcodes << array_out;
301+
shellcodes << L"\n};\n\n";
302+
303+
shellcodes.close();
245304
}

GH Injector Library/Tools.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,10 @@ void ErrorLog(ERROR_INFO * info);
134134
// info (ERROR_INFO*):
135135
/// A pointer to an ERROR_INFO structure which contains information about what went wrong.
136136
//
137-
//Returnvalue (void)
137+
//Returnvalue (void)
138+
139+
#if !defined(_WIN64) && defined(DUMP_SHELLCODE)
140+
141+
void DumpShellcode(BYTE * start, int length, const wchar_t * szShellname);
142+
143+
#endif

GH Injector Library/WOW64 Shells.h

+20-3
Large diffs are not rendered by default.

GH Injector Library/main.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22

33
#include "Tools.h"
44

5+
#if !defined(_WIN64) && defined (DUMP_SHELLCODE)
6+
#include "Manual Mapping.h"
7+
#include "Injection Internal.h"
8+
#endif
9+
510
BOOL WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, void * pReserved)
611
{
712
UNREFERENCED_PARAMETER(pReserved);
813

914
if (dwReason == DLL_PROCESS_ATTACH)
1015
{
1116

17+
#if !defined(_WIN64) && defined (DUMP_SHELLCODE)
18+
HINSTANCE dummy_instance{ 0 };
19+
ERROR_DATA dummy_data{ 0 };
20+
InjectDLL(nullptr, nullptr, INJECTION_MODE::IM_LoadLibraryExW, LAUNCH_METHOD::LM_NtCreateThreadEx, NULL, dummy_instance, 0, dummy_data);
21+
MMAP_NATIVE::ManualMap(nullptr, nullptr, LAUNCH_METHOD::LM_NtCreateThreadEx, NULL, dummy_instance, 0, dummy_data);
22+
#endif
23+
1224
#ifdef DEBUG_INFO
1325
AllocConsole();
1426

0 commit comments

Comments
 (0)