iilegacyyii/ThreadlessInject-BOF

The process handle `pHandle` is never closed resulting in a leaked handle.

JohnLaTwC opened this issue · 1 comments

The process handle pHandle is never closed resulting in a leaked handle.

    NTSTATUS status = pNtOpenProcess(&pHandle, PROCESS_ALL_ACCESS, &ObjectAttributes, &ClientId);
...

    // Locate memory hole for shellcode to reside in.
    UINT_PTR loaderAddress = findMemoryHole(pHandle, exportAddress, sizeof(shellcodeLoader) + shellcodeSize);
    if (loaderAddress == 0)
    {
        BeaconPrintf(CALLBACK_ERROR, "Unable to locate memory hole within 2G of export address");
+       CloseHandle(pHandle);   <<< add a call to closehandle here
        return;
    }

pHandle should also be closed in a cleanup routine or at any of these function return points.

BeaconPrintf(CALLBACK_ERROR, "Unable to locate memory hole within 2G of export address");

BeaconPrintf(CALLBACK_ERROR, "Unable to change page protections @ 0x%llx, status: 0x%llx", targetRegion, status);

BeaconPrintf(CALLBACK_ERROR, "Unable to write call opcode @ 0x%llx, status: 0x%llx", exportAddress, status);

BeaconPrintf(CALLBACK_ERROR, "Unable to change page protections @ 0x%llx, status: 0x%llx", loaderAddress, status);

BeaconPrintf(CALLBACK_ERROR, "Unable to write loader stub @ 0x%llx, status: 0x%llx", loaderAddress, status);

BeaconPrintf(CALLBACK_ERROR, "Unable to write payload @ 0x%llx, status: 0x%llx", loaderAddress + shellcodeSize, status);

BeaconPrintf(CALLBACK_ERROR, "Unable to change page protections @ 0x%llx, status: 0x%llx", loaderAddress, status);

BeaconOutput(CALLBACK_OUTPUT, "Injection complete. Payload will execute when the targeted process calls the export", 84);

Hi John, I've added a fix in the locations you mentioned. Thanks for raising this :)