@@ -28,8 +28,8 @@ static BYTE MonikaPayload_NO_CRASH[] = {
2828 0x48 , 0x83 , 0xEC , 0x28 , // sub rsp, 0x28 (MessageBoxA Strictly requires 32-byte aligned stack)
2929 0xE8 , 0x00 , 0x00 , 0x00 , 0x00 , // call $+5 (self-relative)
3030 0x5A , // pop rdx
31- 0x48 , 0x83 , 0xC2 , 0x3C , // add rdx, 0x3C (adjust rdx to point to "JUST Monika!")
32- 0x48 , 0x31 , 0xC9 , // xor rcx, rcx (HWND = NULL)
31+ 0x48 , 0x83 , 0xC2 , 0x43 , // add rdx, 0x43 (adjust rdx to point to "JUST Monika!")
32+ 0x48 , 0xB9 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // mov rcx, 0
3333 0x4C , 0x8B , 0xC2 , // mov r8, rdx (R8 = address of "JUST Monika!")
3434 0x49 , 0x83 , 0xC0 , 0x0d , // add r8, 0x0d (adjust R8 to point to "ALERT")
3535 0x4D , 0x31 , 0xC9 , // xor r9, r9 (uType = MB_OK)
@@ -89,6 +89,7 @@ static BYTE Gidget_Shellcode[] = {
8989DWORD GetProcessIdByName (const char * processName);
9090DWORD GetMainThreadId (DWORD processId);
9191LPVOID InjectShellcode (HANDLE hProcess, UINT8 *buf, UINT64 bufsize);
92+ HWND GetTargetWindowHandleByPID (DWORD processId);
9293
9394// Function to hijack the main thread and set its RIP to the injected MonikaPayload
9495static UINT8 HijackMainThread (HANDLE hProcess, DWORD mainThreadId, LPVOID remotePayloadMemory)
@@ -166,6 +167,10 @@ static void GetTargetMsgBoxA_Routine(HANDLE hProcess)
166167
167168__declspec (dllexport) UINT8 injectX64Gal(char *targetEXE)
168169{
170+ // Update Gidget_Shellcode with function addresses
171+ *(UINT64 *)(Gidget_Shellcode + 20 ) = (UINT64)LoadLibraryA;
172+ *(UINT64 *)(Gidget_Shellcode + 45 ) = (UINT64)GetProcAddress;
173+
169174 // Get the PID of the target process
170175 DWORD processId = GetProcessIdByName (targetEXE);
171176 if (!processId)
@@ -196,8 +201,20 @@ __declspec(dllexport) UINT8 injectX64Gal(char *targetEXE)
196201 GetTargetMsgBoxA_Routine (hProcess);
197202
198203 // Update MonikaPayload with target MessageBoxA address
199- *(UINT64 *)(MonikaPayload_NO_CRASH + 55 ) = *(UINT64 *)(Gidget_Shellcode + sizeof (Gidget_Shellcode) - 8 );
204+ *(UINT64 *)(MonikaPayload_NO_CRASH + 62 ) = *(UINT64 *)(Gidget_Shellcode + sizeof (Gidget_Shellcode) - 8 );
200205
206+ // Get Target Window Handle
207+ HWND targetHwnd = GetTargetWindowHandleByPID (processId);
208+ if (!targetHwnd)
209+ {
210+ printf (" Failed to get target window handle\n " );
211+ return -1 ;
212+ }
213+ printf (" Target window handle: 0x%p\n " , targetHwnd);
214+
215+ // Update MonikaPayload with target window handle
216+ *(UINT64 *)(MonikaPayload_NO_CRASH + 42 ) = (UINT64)targetHwnd;
217+
201218 // Inject MonikaPayload into the target process and get the address of the remote memory
202219 LPVOID remoteMemory = InjectShellcode (hProcess, MonikaPayload_NO_CRASH, sizeof (MonikaPayload_NO_CRASH));
203220 if (!remoteMemory)
0 commit comments