Skip to main content

Overview

The exec action creates and executes processes on local and remote systems using the Win32_Process.Create WMI method. It supports command execution with optional output retrieval and AMSI evasion capabilities.
The exec action is one of the most powerful features in SharpWMI, enabling direct code execution on remote systems through native Windows management infrastructure.

Syntax

The exec action can also be invoked using action=execute or action=create aliases.

Parameters

Usage Examples

Basic Process Creation

Command Output Retrieval

Capture and display command output:

Example Output

Command Output Mechanism

When result=true is specified, SharpWMI uses a clever technique to retrieve command output:
1

Command Wrapping

The command is wrapped in PowerShell that captures output and XOR-encodes it
2

Environment Variable Storage

Encoded output is stored in a WMI environment variable with a random name
3

Output Retrieval

SharpWMI queries the environment variable and decodes the output
4

Cleanup

Environment variables are automatically deleted after retrieval
The output retrieval mechanism:
  1. Creates a random XOR key
  2. Wraps your command in PowerShell: $o=(COMMAND | Out-String).Trim()
  3. XOR-encodes the output
  4. Stores in environment variable via Set-WmiInstance -Class Win32_Environment
  5. Retrieves and decodes the output
  6. Cleans up the environment variable
This technique was contributed by Evi1cg (@Ridter).

AMSI Evasion

When amsi=disable is specified (requires result=true), SharpWMI:
1

Registry Modification

Sets HKCU\Software\Microsoft\Windows Script\Settings\AmsiEnable to 0
2

Command Execution

Executes your command with AMSI disabled
3

Registry Restoration

Restores original AMSI registry value
AMSI evasion requires administrative privileges and may be detected by EDR solutions. The registry modification is temporary and cleaned up after execution.
AMSI evasion code contributed by Steven Flores (0xthirteen) from SharpMove.

Operational Scenarios

Scenario 1: Initial Access and Beacon Deployment

Scenario 2: Credential Harvesting

Scenario 3: Lateral Movement

Scenario 4: Domain Reconnaissance

Scenario 5: Persistence Mechanisms

Remote vs Local Usage

When to use:
  • Post-exploitation on compromised system
  • Testing commands before remote execution
  • Local privilege escalation
Advantages:
  • No network traffic
  • No authentication required
  • Faster execution

Command Line Best Practices

Quote Handling

Use proper escaping for complex commands:

Encoded Commands

Base64 encode complex PowerShell:

Detection Considerations

Win32_Process.Create is a high-fidelity indicator of remote code execution and is heavily monitored in mature environments.
  • Event ID 4688: Process creation events
  • Event ID 4648: Logon with explicit credentials
  • Sysmon Event ID 1: Process creation
  • Parent process: wmiprvse.exe (WMI Provider Host)
  • Unusual process trees (wmiprvse.exe → cmd.exe → powershell.exe)
  • Event ID 5857: WMI activity
  • Event ID 5860-5861: WMI event consumers
  • Sysmon Event ID 19-21: WMI activity
  • Registry modifications for AMSI evasion
  • Creation/deletion of environment variables
  • DCOM traffic on port 135
  • Dynamic RPC connections
  • Multiple WMI connections from single source
  • WMI traffic to sensitive systems (DCs, servers)
  • Suspicious command-line arguments
  • Base64 encoded commands
  • Web requests in command line
  • Credential dumping tools (mimikatz, etc.)
  • PowerShell download cradles

Best Practices

Operational Security

  • Use AMSI evasion when executing PowerShell
  • Avoid obvious malicious command lines
  • Use encoded commands when possible
  • Clean up created processes/files
  • Limit use of result=true (creates artifacts)

Execution Strategy

  • Test commands locally before remote execution
  • Use short-lived processes
  • Consider process names that blend in
  • Stage payloads via upload action first
  • Monitor for command failures

Error Handling

  • Check return values (0 = success)
  • Verify process started successfully
  • Handle timeout scenarios
  • Account for AV/EDR blocking

Credential Management

  • Use minimal necessary privileges
  • Rotate credentials between operations
  • Avoid reusing domain admin credentials
  • Monitor for lockouts

Return Values

The Creation of process returned value indicates success or failure:

Troubleshooting

Cause: Insufficient privileges or security restrictionsSolution:
  • Verify admin credentials
  • Check UAC remote restrictions
  • Ensure user is in local Administrators group
  • Try with domain admin account
Cause: Executable or file path doesn’t existSolution:
  • Verify path exists on target system
  • Use full paths instead of relative
  • Upload executable first with upload action
  • Check for typos in command
Cause: Process doesn’t generate stdout or requires admin contextSolution:
  • Verify command produces output when run locally
  • Check if process requires elevated privileges
  • Try without result=true first
  • Increase timeout if process is slow
Cause: Insufficient privileges or EDR blockingSolution:
  • Ensure you have admin rights
  • Verify registry modification succeeded
  • Try alternative AMSI bypass methods
  • Check for EDR blocking registry changes

executevbs

Execute VBScript via WMI event subscriptions

upload

Upload files before execution

ps

Verify process creation

terminate

Kill created processes