@@ -90,20 +90,26 @@ DWORD GetProcessIdByName(const char* processName);
9090DWORD GetMainThreadId (DWORD processId);
9191LPVOID InjectShellcode (HANDLE hProcess, UINT8 *buf, UINT64 bufsize);
9292HWND GetTargetWindowHandleByPID (DWORD processId);
93+ void DrawImageOnWindow (HWND hwnd, const char * imageFile);
9394
9495// Function to hijack the main thread and set its RIP to the injected MonikaPayload
95- static UINT8 HijackMainThread (HANDLE hProcess, DWORD mainThreadId , LPVOID remotePayloadMemory)
96+ static UINT8 HijackMainThread (HANDLE hProcess, HANDLE hThread , LPVOID remotePayloadMemory)
9697{
97- HANDLE hThread = OpenThread (THREAD_ALL_ACCESS, FALSE , mainThreadId);
98- if (!hThread)
98+ if (!hProcess)
9999 {
100- printf (" Failed to open main thread with TID %lu\n " , mainThreadId);
100+ printf (" Invalid process handle\n " );
101+ return -1 ;
102+ }
103+ if (!hThread)
104+ {
105+ printf (" Invalid thread handle\n " );
106+ return -1 ;
107+ }
108+ if (!remotePayloadMemory)
109+ {
110+ printf (" Invalid remote memory address\n " );
101111 return -1 ;
102112 }
103-
104- // Suspend the thread and get its context
105- SuspendThread (hThread);
106- printf (" Suspended main thread with TID %lu\n " , mainThreadId);
107113
108114 CONTEXT ctx;
109115 ctx.ContextFlags = CONTEXT_FULL;
@@ -122,20 +128,13 @@ static UINT8 HijackMainThread(HANDLE hProcess, DWORD mainThreadId, LPVOID remote
122128
123129 // Update the thread context
124130 SetThreadContext (hThread, &ctx);
131+ return 0 ;
125132 }
126133 else
127134 {
128135 printf (" Failed to get thread context\n " );
129- ResumeThread (hThread);
130- CloseHandle (hThread);
131136 return -1 ;
132137 }
133-
134- // Resume the thread
135- ResumeThread (hThread);
136- printf (" Resumed main thread with TID %lu\n " , mainThreadId);
137- CloseHandle (hThread);
138- return 0 ;
139138}
140139
141140static void GetTargetMsgBoxA_Routine (HANDLE hProcess)
@@ -165,7 +164,7 @@ static void GetTargetMsgBoxA_Routine(HANDLE hProcess)
165164 printf (" MessageBoxA Address in Target: 0x%p\n " , *(UINT64 *)((UINT64)Gidget_Shellcode + sizeof (Gidget_Shellcode) - 8 ));
166165}
167166
168- __declspec (dllexport) UINT8 injectX64Gal(char *targetEXE)
167+ __declspec (dllexport) UINT8 injectX64Gal(char *targetEXE, const char *bmp_path )
169168{
170169 // Update Gidget_Shellcode with function addresses
171170 *(UINT64 *)(Gidget_Shellcode + 20 ) = (UINT64)LoadLibraryA;
@@ -223,13 +222,31 @@ __declspec(dllexport) UINT8 injectX64Gal(char *targetEXE)
223222 return -1 ;
224223 }
225224 printf (" MonikaPayload injected successfully.\n " );
225+
226+ // open main thread
227+ HANDLE hThread = OpenThread (THREAD_ALL_ACCESS, FALSE , mainThreadId);
228+ if (!hThread)
229+ {
230+ printf (" Failed to open main thread with TID %lu\n " , mainThreadId);
231+ return -1 ;
232+ }
233+ SuspendThread (hThread);
234+ printf (" Main thread suspended.\n " );
235+
236+ // Replace Target Window content with image
237+ DrawImageOnWindow (targetHwnd, bmp_path);
226238
227239 // Hijack the main thread
228- if (HijackMainThread (hProcess, mainThreadId , remoteMemory) == 0 )
240+ if (HijackMainThread (hProcess, hThread , remoteMemory) == 0 )
229241 printf (" Main thread hijacked successfully.\n " );
230242 else
231243 printf (" Failed to hijack main thread.\n " );
244+
245+ // Resume the main thread
246+ ResumeThread (hThread);
247+ printf (" Main thread resumed.\n " );
232248
249+ CloseHandle (hThread);
233250 CloseHandle (hProcess);
234251}
235252}
0 commit comments