Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ExplorerPatcher/TwinUIPatches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,16 @@ BOOL Moment2PatchHardwareConfirmator(HMODULE hHardwareConfirmator, PBYTE pSearch
// Execution
DWORD dwOldProtect = 0;
SIZE_T totalSize = sizeof(shellcode) + 5;
// Validate writeAt is within the expected module bounds to prevent privilege escalation
// via memory corruption vulnerabilities redirecting shellcode injection into privileged processes
MODULEINFO modInfo = {};
if (writeAt == nullptr ||
!GetModuleInformation(GetCurrentProcess(), (HMODULE)hHardwareConfirmator, &modInfo, sizeof(modInfo)) ||
writeAt < (PBYTE)modInfo.lpBaseOfDll ||
writeAt + totalSize > (PBYTE)modInfo.lpBaseOfDll + modInfo.SizeOfImage)
{
return FALSE;
}
if (!VirtualProtect(writeAt, totalSize, PAGE_EXECUTE_READWRITE, &dwOldProtect)) return FALSE;
memcpy(writeAt, shellcode, sizeof(shellcode));
PBYTE jmpLoc = writeAt + sizeof(shellcode);
Expand Down