Removing oddly specific 'GetExplorerPid' function in favor of 'FindPidByName'.

This commit is contained in:
toneillcodes
2026-05-25 21:50:13 -04:00
parent ec116702ed
commit 3b3a2a7752
4 changed files with 15 additions and 19 deletions
+1 -17
View File
@@ -75,20 +75,4 @@ int my_wcsicmp(const wchar_t* s1, const wchar_t* s2) {
} while (c1 == c2);
return c1 - c2;
}
// Helper to find Explorer PID
DWORD GetExplorerPID() {
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe = { sizeof(pe) };
if (Process32First(hSnapshot, &pe)) {
do {
if (lstrcmpiW(pe.szExeFile, L"explorer.exe") == 0) {
CloseHandle(hSnapshot);
return pe.th32ProcessID;
}
} while (Process32Next(hSnapshot, &pe));
}
if (hSnapshot) CloseHandle(hSnapshot);
return 0;
}
}
-1
View File
@@ -11,6 +11,5 @@ int my_strlen_for(const char* s);
int my_strcmp(const char* s1, const char* s2);
int my_stricmp(const char* s1, const char* s2);
int my_wcsicmp(const wchar_t* s1, const wchar_t* s2);
DWORD GetExplorerPID();
#endif
+12
View File
@@ -242,6 +242,7 @@ c:\Users\Administrator\Desktop\module-stomping>
```
## Execution Steps
### Stomping in the Current Process
The `local-stomp.cpp` example follows this execution logic:
1. **Load Target DLL:** Use `LoadLibraryExA` with the `DONT_RESOLVE_DLL_REFERENCES` flag to map a "sacrificial" DLL into the process without executing its entry point.
@@ -250,6 +251,17 @@ The `local-stomp.cpp` example follows this execution logic:
4. **Write Payload:** Use `WriteProcessMemory` or `RtlCopyMemory` to stomp the payload over the legitimate instructions.
5. **Reprotect (Execute):** Revert the memory permissions back to Read-Execute (`RX`).
6. **Execution:** Trigger the shellcode using a thread execution API (e.g., `CreateThread` or `CreateRemoteThread`).
### Stomping in a Remote Process
The `remote-stomp.cpp` example follows this execution logic:
1. **Acquire Process Handle:** Open a handle to the target remote process via OpenProcess using the supplied Process ID (PID) with the required access rights.
2. **Locate Remote PEB:** Query the target process to find its remote Process Environment Block (PEB) address using internal utility routines.
3. **Parse Remote Modules:** Walk the remote process's InMemoryOrderModuleList to dynamically locate the base address of a loaded target module (e.g., KERNEL32.dll).
4. **Identify Section / Export Target:** Verify the boundaries of the executable .text section, and locate a specific target function address (e.g., FileTimeToSystemTime) within that module via manual Export Address Table (EAT) parsing.
5. **Reprotect (Write):** Call VirtualProtectEx to change the target function's memory permissions in the remote process from Read-Execute (RX) to Read-Write (RW).
6. **Write Payload:** Use WriteProcessMemory to stomp the shellcode payload directly over the legitimate instructions of the identified remote export.
7. **Reprotect (Execute):** Revert the remote memory permissions back to Read-Execute (RX) via VirtualProtectEx.
8. **Execution:** Trigger the payload within the target process context using a remote execution API (e.g., CreateRemoteThread) pointing directly to the stomped function address.
## OPSEC Considerations
+2 -1
View File
@@ -2,6 +2,7 @@
#include <stdio.h>
#include "..\includes\utils.h" // crt replacements
#include "..\includes\ps-utils.h" // process functions
int main(int argc, char* argv[]) {
if (argc < 2) {
@@ -33,7 +34,7 @@ int main(int argc, char* argv[]) {
PROCESS_INFORMATION pi = { 0 };
SIZE_T attributeSize = 0;
DWORD parentPid = GetExplorerPID();
DWORD parentPid = FindPidByName(L"explorer.exe");
if (parentPid == 0) return -1;
HANDLE hParent = OpenProcess(PROCESS_CREATE_PROCESS, FALSE, parentPid);