Artifacts Generated: Process Open
Summary
Steals the primary access token from a target process and sets it as both the primary and impersonation token for the Apollo agent. Opens the target process, duplicates its token, and updates the agent’s identity context to operate under the stolen token’s privileges.- Needs Admin: False (depends on target process privileges)
- Version: 2
- Author: @djhohnstein
Arguments
- pid (Number, Required) - Process ID to steal token from
Usage
Detailed Summary
Agent Execution Flow
1. Parameter Processing and Validation
- Validates PID parameter is provided
- Supports JSON format with “pid” or “process_id” keys
- Supports raw integer PID format
- Validates PID is valid integer value
2. API Function Resolution
- Resolves
OpenProcessTokenfrom advapi32.dll - Resolves
DuplicateTokenExfrom advapi32.dll - Resolves
CloseHandlefrom kernel32.dll - Uses Apollo’s dynamic API resolution framework
3. Process Handle Acquisition
- Uses
Process.GetProcessById()to get process handle - Converts string parameter to integer PID
- Handles process not found or access denied exceptions
- Stores error message for failed handle acquisition
4. Process Open Artifact Generation
- Generates process open artifact when handle acquired successfully
- Uses target PID for artifact logging
- Provides intermediate response before token operations
5. Primary Token Extraction
- Calls
OpenProcessTokenwith required access levels - Requests Duplicate, AssignPrimary, and Query access
- Sets extracted token as agent’s primary identity
- Handles token extraction failures with Win32 error codes
6. Impersonation Token Creation
- Duplicates primary token for impersonation use
- Requests maximum allowed access on duplicated token
- Sets impersonation level to TokenImpersonationLevel.Impersonation
- Sets token type to 1 (TokenImpersonation)
- Updates agent’s impersonation identity
7. Identity Comparison and Reporting
- Captures old identity before token change
- Sets new impersonation identity
- Compares old and new identity claims
- Handles access denied exceptions when reading authentication type
- Enumerates claims for both old and new identities
8. Callback Update and Response
- Creates success response with impersonated user name
- Includes detailed claims comparison in response
- Updates callback context with new impersonation identity
- Provides callback update message for Mythic interface
9. Resource Cleanup
- Closes process token handle if opened
- Closes impersonation token handle if created
- Ensures proper resource cleanup regardless of success/failure
Token Access Levels and Permissions
Required Token Access
- Duplicate: Required to duplicate the token
- AssignPrimary: Required to use token as primary token
- Query: Required to read token information
Impersonation Token Access
- Requests maximum possible access on duplicated token
- Actual access depends on caller’s privileges and token security
Token Types and Levels
- Uses Impersonation level (not Identification or Delegation)
- Creates impersonation token type (not primary)
Identity Manager Integration
Primary Identity Management
- Sets stolen token as agent’s primary identity
- Affects agent’s base security context
Impersonation Identity Management
- Retrieves current impersonation identity before change
- Sets new impersonation identity with stolen token
- Retrieves new identity for comparison reporting
Error Handling
Process Handle Errors
- Handles process not found exceptions
- Handles access denied when opening process
- Handles invalid PID format exceptions
Token Operation Errors
- Uses Win32 error codes for detailed error reporting
- Handles token access denied scenarios
- Handles token duplication failures
Authentication Type Access Errors
- Handles access denied when reading authentication type
- Provides fallback error message in output
Parameter Processing
Command Line Formats
Display Parameters
- Shows target PID in task display
- Sets manual arguments for task representation
APIs Used
| API | Purpose | DLL |
|---|---|---|
Process.GetProcessById | Get process handle | System.Diagnostics |
OpenProcessToken | Extract process token | advapi32.dll |
DuplicateTokenEx | Duplicate token for impersonation | advapi32.dll |
CloseHandle | Close token handles | kernel32.dll |
GetLastWin32Error | Retrieve error codes | kernel32.dll |
MITRE ATT&CK Mapping
- T1134 - Access Token Manipulation
- T1528 - Steal Application Access Token
Security Considerations
- Token Theft: Steals authentication tokens from other processes
- Privilege Escalation: May gain higher privileges through stolen tokens
- Identity Impersonation: Changes agent’s security context
- Process Access: Requires ability to open target process
- Token Duplication: Creates new tokens for impersonation use
Limitations
- Process Access: Requires ability to open target process handle
- Token Access: Needs sufficient privileges to access process token
- Session Scope: Token theft limited to current session
- Architecture: Must match target process architecture
- Process State: Target process must be running and accessible
Error Conditions
- Invalid PID: Non-existent or invalid process ID
- Process Access Denied: Insufficient privileges to open target process
- Token Access Denied: Cannot access target process token
- Token Duplication Failed: Unable to duplicate token for impersonation
- Parameter Format Error: Invalid PID format or JSON structure
Best Practices
- Target Selection: Choose processes with desired privilege levels
- Error Handling: Monitor for access denied and privilege issues
- Resource Cleanup: Ensure proper handle cleanup on completion
- Identity Verification: Verify successful impersonation after token theft
- Privilege Awareness: Understand current vs target privilege levels