Skip to main content

Overview

The executevbs action executes VBScript payloads through WMI event subscriptions using ActiveScriptEventConsumer. This provides a flexible method for remote code execution with support for downloading scripts, executing commands, and delayed triggers.
This action creates WMI event subscriptions that persist until cleaned up. SharpWMI automatically removes artifacts after execution, but failed operations may leave traces.

Syntax

Parameters

Script Specification Methods

SharpWMI offers 8 different methods to specify VBScript payloads:

Method A: Execute Command via VBScript

Execute an OS command through preset VBScript template:
The VBScript template:

Method B: Download PowerShell Script and Execute

Download PowerShell from URL and execute via stdin:
The VBScript downloads the script and pipes it to PowerShell’s stdin.

Method C: Download Binary and Execute

Download binary, save to disk, and execute:
Format: url="SOURCE_URL,TARGET_PATH"

Method D: Download Binary and Execute Custom Command

Download binary and execute with custom parameters:

Method E: Execute VBScript from File

Read VBScript from file and execute:

Method F: Execute Inline VBScript

Execute VBScript code directly:

Method G: Execute Base64-Encoded VBScript

Base64-decode and execute VBScript:

Method H: Execute Base64-Encoded Script from File

Read base64-encoded VBScript from file:

Usage Examples

Basic VBScript Execution

Download and Execute Scenarios

Advanced VBScript Usage

How It Works

1

Create Timer Object

Creates __IntervalTimerInstruction to trigger after specified delay
2

Create Event Filter

Sets up __EventFilter to monitor for timer events
3

Create Event Consumer

Creates ActiveScriptEventConsumer with VBScript payload
4

Bind Filter to Consumer

Creates __FilterToConsumerBinding to link filter and consumer
5

Wait for Execution

Waits for trigger time (default 10 seconds)
6

Cleanup

Removes timer, filter, consumer, and binding
The execution flow:
  1. __IntervalTimerInstruction fires after trigger seconds
  2. __EventFilter matches the timer event
  3. ActiveScriptEventConsumer executes VBScript
  4. Script runs with KillTimeout of timeout seconds
  5. All WMI objects are deleted after execution
This leaves minimal artifacts compared to persistent WMI backdoors.

Timing Parameters

Script executes 10 seconds after subscription creation.
timeout should always be greater than trigger to allow the script to execute before being killed.

Operational Scenarios

Scenario 1: Stealthy Beacon Deployment

Scenario 2: Credential Harvesting

Scenario 3: Custom VBScript Payload

Scenario 4: Multiple Target Execution

Remote vs Local Usage

Note: Local execution via WMI event subscriptions is uncommon. Use exec action for local commands.

AMSI Evasion

When amsi=disable is specified:
1

Registry Modification

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

VBScript Execution

VBScript runs with AMSI disabled
3

Registry Restoration

Original AMSI value is restored after cleanup

Detection Considerations

WMI event subscriptions are a high-fidelity indicator of malicious activity and are heavily monitored.
  • Event ID 5858: WMI permanent event subscription
  • Event ID 5859: WMI event filter activity
  • Event ID 5861: WMI event consumer registration
  • Sysmon Event ID 19: WMI event filter activity
  • Sysmon Event ID 20: WMI event consumer activity
  • Sysmon Event ID 21: WMI event consumer to filter binding
  • wscript.exe or cscript.exe spawned by scrcons.exe
  • Parent process: scrcons.exe (Script Event Consumer)
  • Event ID 4688: Process creation with suspicious parent
  • ActiveScriptEventConsumer with encoded scripts
  • WMI queries to root\subscription namespace
  • Creation of __EventFilter, ActiveScriptEventConsumer, __FilterToConsumerBinding
  • Multiple WMI connections in succession
  • DCOM traffic patterns consistent with WMI operations
  • Registry modification to AmsiEnable key
  • Event ID 4657: Registry value modification
  • Temporary AMSI bypass in user context

Best Practices

Event Naming

  • Use legitimate-sounding event names
  • Avoid obvious names like “Backdoor” or “Shell”
  • Use Windows Update, Maintenance, Debug
  • Randomize names across operations

Timing Strategy

  • Use delays to avoid immediate detection
  • Allow time to disconnect before execution
  • Set appropriate timeout values
  • Don’t use excessively long delays

Payload Delivery

  • Use HTTPS for downloads when possible
  • Host payloads on legitimate-looking domains
  • Use URL shorteners or redirectors
  • Verify downloads with checksums in VBScript

Cleanup

  • Let SharpWMI handle automatic cleanup
  • Verify subscriptions are removed
  • Check for orphaned event consumers
  • Monitor for failed cleanup operations

Comparison with exec Action

Troubleshooting

Cause: WMI permissions or service issueSolution:
  • Verify WMI service is running
  • Check admin privileges
  • Test with local WMI query first
  • Verify root\cimv2 namespace access
Cause: Subscription namespace access deniedSolution:
  • Ensure admin rights on target
  • Check root\subscription namespace permissions
  • Verify WMI filter quota not exceeded
  • Try different event name
Cause: Timeout too short or script errorSolution:
  • Increase timeout parameter
  • Test VBScript locally first
  • Check for syntax errors
  • Verify URLs are accessible from target
Cause: Insufficient privileges or EDR blockingSolution:
  • Verify admin context
  • Check for EDR protecting registry
  • Try alternative AMSI bypass
  • Test registry modification manually

exec

Simpler command execution method

upload

Upload files before VBS execution

query

Verify event subscriptions

ps

Check for script execution

Additional Resources