Artifacts Generated: Process Create
Summary
Executes binaries with specified arguments using proper command-line parsing and PATH resolution. Captures output in real-time and manages process lifecycle with cancellation support.- Needs Admin: False
- Version: 2
- Author: @djhohnstein
Arguments
- executable (String) - Path or name of executable to run
- arguments (String, Optional) - Command-line arguments for the executable
Usage
Detailed Summary
Agent Execution Flow
1. Parameter Processing
- Deserializes executable and arguments parameters
- Combines executable and arguments into single command line
- Supports both JSON and space-separated parameter formats
2. Command Line Parsing
- Uses Windows
CommandLineToArgvWAPI for proper command-line parsing - Handles quoted arguments and special characters correctly
- Properly frees allocated memory using
LocalFree - Returns null on parsing failure
3. Process Creation and Configuration
- Separates application path from arguments
- Creates process using Apollo’s process manager
- Registers event handlers for output, error, and exit events
- Enables real-time output capture
4. Process Execution and Monitoring
- Starts the process and checks for success
- Creates process creation artifact with PID and command line
- Monitors process execution with 500ms polling intervals
- Supports cancellation through cancellation token
5. Output Handling
- Captures both stdout and stderr output
- Streams output in real-time as intermediate responses
- Filters empty output to reduce noise
6. Process Cleanup
- Handles normal process exit through event handler
- Kills process if still running when task is cancelled
- Ensures proper task completion in all scenarios
API Function Resolution
Required APIs
- Resolves
CommandLineToArgvWfrom Shell32 for command parsing - Resolves
LocalFreefrom Kernel32 for memory cleanup - Uses Apollo’s dynamic API resolution framework
Process Manager Integration
The command leverages Apollo’s process manager which handles:- PATH Resolution: Automatic executable location via %PATH%
- Process Creation: Platform-appropriate process spawning
- Output Redirection: Capture of stdout and stderr streams
- Process Lifecycle: Management of process state and cleanup
Command Line Parsing Features
Windows-Style Parsing
- Quoted Arguments: Properly handles
"argument with spaces" - Escape Sequences: Processes backslash escaping
- Special Characters: Handles pipes, redirects, and other shell characters
- Empty Arguments: Preserves empty quoted strings
PATH Resolution
- Executable Search: Uses Windows PATH environment variable
- File Extensions: Automatically appends .exe, .cmd, .bat as needed
- Current Directory: Searches current working directory first
- Full Paths: Supports absolute paths bypassing PATH search
Data Structures
RunParameters
Real-Time Output Features
Output Streaming
- Immediate Display: Output appears as it’s generated
- Bidirectional Capture: Both stdout and stderr streams
- Event-Driven: Uses event handlers for efficient processing
- Non-Blocking: Doesn’t wait for process completion to show output
Process Monitoring
- Status Tracking: Monitors process execution state
- Exit Detection: Detects process termination
- Cancellation Support: Can interrupt long-running processes
- Resource Management: Proper cleanup on all exit paths
APIs Used
| API | Purpose | DLL |
|---|---|---|
CommandLineToArgvW | Parse command line into arguments | shell32.dll |
LocalFree | Free memory allocated by Windows | kernel32.dll |
Marshal.PtrToStringUni | Convert Unicode pointer to string | mscorlib.dll |
Marshal.ReadIntPtr | Read pointer from memory | mscorlib.dll |
MITRE ATT&CK Mapping
- T1106 - Native API
- T1218 - Signed Binary Proxy Execution
- T1553 - Subvert Trust Controls
Security Considerations
- Code Execution: Direct execution of arbitrary binaries
- Output Exposure: Command output transmitted back to operator
- Process Artifacts: Creates process creation events in system logs
- PATH Exploitation: May execute unintended binaries via PATH manipulation
Limitations
- Subject to execution policies and security software
- Requires executable to exist and be accessible
- Output capture depends on proper stream redirection
- Long-running processes may impact agent performance
- Some console applications may not work properly
- Binary execution subject to user permissions
Error Conditions
- File Not Found: Executable not found in PATH or specified location
- Access Denied: Insufficient permissions to execute binary
- Command Parse Error:
CommandLineToArgvWfails to parse command line - Process Start Failure: Process creation fails with Win32 error
- Memory Allocation: Failed to allocate memory for argument parsing