MCPcopy Create free account
hub / github.com/dobin/RedEdr / TestProcessSpawnWithSectionMapping

Function TestProcessSpawnWithSectionMapping

RedTest/redtest.cpp:608–794  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

606// =============================================================================
607
608void TestProcessSpawnWithSectionMapping() {
609 printf("\n=== TEST 5: Process Spawn with Section Mapping Injection ===\n\n");
610
611 // Load NT API functions
612 HMODULE hNtdll = GetModuleHandleA("ntdll.dll");
613 if (!hNtdll) {
614 printf("[!] Failed to get ntdll.dll handle\n");
615 return;
616 }
617
618 pNtCreateSection NtCreateSection = (pNtCreateSection)GetProcAddress(hNtdll, "NtCreateSection");
619 pNtMapViewOfSection NtMapViewOfSection = (pNtMapViewOfSection)GetProcAddress(hNtdll, "NtMapViewOfSection");
620 pNtUnmapViewOfSection NtUnmapViewOfSection = (pNtUnmapViewOfSection)GetProcAddress(hNtdll, "NtUnmapViewOfSection");
621
622 if (!NtCreateSection || !NtMapViewOfSection || !NtUnmapViewOfSection) {
623 printf("[!] Failed to resolve NT API functions\n");
624 return;
625 }
626
627 printf("[Main] NT API functions resolved successfully\n");
628
629 STARTUPINFOA si = { 0 };
630 PROCESS_INFORMATION pi = { 0 };
631 si.cb = sizeof(si);
632
633 printf("[Main] Spawning child process (notepad.exe) in suspended state...\n");
634 if (!CreateProcessA(
635 "C:\\Windows\\System32\\notepad.exe",
636 NULL,
637 NULL,
638 NULL,
639 FALSE,
640 CREATE_SUSPENDED,
641 NULL,
642 NULL,
643 &si,
644 &pi)) {
645 printf("[!] CreateProcess failed: %lu\n", GetLastError());
646 return;
647 }
648
649 printf("[Main] Process created - PID: %lu, TID: %lu\n", pi.dwProcessId, pi.dwThreadId);
650
651 // Create a memory section
652 HANDLE hSection = NULL;
653 SIZE_T shellcodeSize = sizeof(g_dummyShellcode);
654 LARGE_INTEGER sectionSize = { 0 };
655 sectionSize.QuadPart = shellcodeSize;
656
657 NTSTATUS status = NtCreateSection(
658 &hSection,
659 SECTION_ALL_ACCESS,
660 NULL,
661 &sectionSize,
662 PAGE_EXECUTE_READWRITE,
663 SEC_COMMIT,
664 NULL
665 );

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected