Repository navigation
InstrCallback: follow indirect/direct NtCreateUserProcess children and inherited targets - #256
Open
doomedraven wants to merge 1 commit into
Open
doomedraven wants to merge 1 commit into
doomedraven wants to merge 1 commit into
Conversation
…d inherited targets When x64 NtCreateUserProcess succeeds via direct or indirect syscall, inspect the preserved user-stack arguments ([Rsp+0x48] ProcessParameters and [Rsp+0x58] AttributeList) using QueryMemoryRange pre-validation without SEH faults or loader-lock APIs: - Snapshot SystemProcessInformation via VirtualAlloc to discover newly created child PIDs/TIDs, emit a structured NtCreateUserProcess log record (ImagePathName, CommandLine, ProcessId, ThreadId, and CIG flag), and invoke ProcessMessage when Microsoft-only CIG is not set on the child. - Inspect PS_ATTRIBUTE_HANDLE_LIST (PsAttributeHandleList) to register and follow foreign target process/thread handles inherited across CIG-hardened relay child stages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends x64
InstrumentationCallback(CAPE/InstrCallback.c) to track child processes spawned via direct or indirectNtCreateUserProcesssyscalls and pivot across CIG-hardened relay child stages viaPS_ATTRIBUTE_HANDLE_LIST(companion to #255 for loaders such asMaldev-Academy/WhisperLoader):Post-syscall x64 stack parameter inspection (
HandleSyscallCreateUserProcess):KiSystemCall64clobbers volatile registers (RCX,RDX,R8,R9,R10,R11) before returning toInstrHook, the caller's user stack atContext->Rsp(TEB + 0x2e0) remains intact:[Context->Rsp + 0x48]holdsPRTL_USER_PROCESS_PARAMETERS ProcessParameters(ImagePathName,CommandLine) and[Context->Rsp + 0x58]holdsPPS_ATTRIBUTE_LIST AttributeList.ProcessParameters,UNICODE_STRING, andPS_ATTRIBUTE_LISTpointers viaIsReadableRangeNoFault(QueryMemoryRange/VirtualQuery) with zero__try / __exceptpage-fault probing and zero loader-lock API calls (s_pNtQuerySystemInformationis pre-resolved inNirvanaInit()beforeInstrHookis registered).Direct/indirect
NtCreateUserProcesschild discovery & logging:NT_SUCCESS(ReturnValue), snapshotsSystemProcessInformationinto aVirtualAllocbuffer (avoiding heap locks), matches newly created children (InheritedFromUniqueProcessId == GetCurrentProcessId(), deduplicated in spinlock-guardedg_syscall_followed_children), emits a structuredNtCreateUserProcessrecord (ImagePathName,CommandLine,ProcessId,ThreadId,BlockNonMicrosoftBinaries), re-armshook_disable()afterloq(), and callsProcessMessage(child_pid, child_tid)wheneverPROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALWAYS_ONis not set on the child.CIG relay bypass via
PS_ATTRIBUTE_HANDLE_LIST(PsAttributeHandleList):Writer/Flipper) and hands down open handles to the remoteTP_POOLtarget viaPS_ATTRIBUTE_HANDLE_LIST,HandleSyscallCreateUserProcessresolves foreign process and thread handles (pid_from_process_handle/pid_from_thread_handle), registers process handles withOpenProcessHandler, and invokesProcessMessage(target_pid, 0)(deduplicated ing_syscall_followed_targets) socapemonattaches directly to the target host process before the relay child stages deliver and trigger the payload.See #255 (
## Hard User-Mode Limits) for the OS-enforced boundaries on CIG-protected relay children and CIG/ACG-protected target hosts.Are these related?
Yes — unlike the coupled
NDEBUGcase where build flags alter macro semantics across translation units, child discovery (SystemProcessInformation) andPS_ATTRIBUTE_HANDLE_LISTtarget following share a single validated pass over theNtCreateUserProcessstack frame ([Rsp + 0x48]/[Rsp + 0x58]) insideCAPE/InstrCallback.c.Verification
Win32/x64) are unverified beyond source inspection.CAPE/InstrCallback.c,ntapi.h, andlookup.cand compiled undergcc -O1 -g -Wall -Wextra -Werror -fshort-wchar -D_WIN64:-fsanitize=address,undefined): passed all 4 suites coveringWhisperLoaderGrandparentCIG +PS_ATTRIBUTE_HANDLE_LISTframes, non-CIG child following and deduplication,STATUS_INFO_LENGTH_MISMATCHbuffer growth, and malformed/unmapped/underflowingTotalLengthinputs (0warnings,0leaks/UB).-fsanitize=thread): passed 8-thread concurrent child/target deduplication stress (0warnings).Series
Builds cleanly on latest
upstream/capemon(616de99). Companion to #255 (feat/tnc-and-tp-direct-injection, zero shared files) and merges cleanly onCAPE/InstrCallback.cwith open PRs (#207, #209, #210, #213, #215, #243, #251, #253, #254).