Overview
Theexecutevbs 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.
Syntax
Parameters
| Parameter | Required | Description |
|---|---|---|
action | Yes | Must be executevbs |
computername | No | Target host(s), comma-separated |
eventname | No | Name for WMI event subscription. Default: “Debug” |
trigger | No | Seconds before script executes. Default: 10 |
timeout | No | Script kill timeout in seconds. Default: 12 |
amsi | No | Set to disable to bypass AMSI |
username | No | Username for authentication |
password | No | Password for authentication |
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:Method B: Download PowerShell Script and Execute
Download PowerShell from URL and execute via stdin:Method C: Download Binary and Execute
Download binary, save to disk, and execute: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 delay2
Create Event Filter
Sets up
__EventFilter to monitor for timer events3
Create Event Consumer
Creates
ActiveScriptEventConsumer with VBScript payload4
Bind Filter to Consumer
Creates
__FilterToConsumerBinding to link filter and consumer5
Wait for Execution
Waits for trigger time (default 10 seconds)
6
Cleanup
Removes timer, filter, consumer, and binding
WMI Event Subscription Details
WMI Event Subscription Details
The execution flow:
__IntervalTimerInstructionfires aftertriggerseconds__EventFiltermatches the timer eventActiveScriptEventConsumerexecutes VBScript- Script runs with
KillTimeoutoftimeoutseconds - All WMI objects are deleted after execution
Timing Parameters
- Default Timing
- Fast Execution
- Delayed Execution
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
- Local Execution
- Remote Execution
exec action for local commands.AMSI Evasion
Whenamsi=disable is specified:
1
Registry Modification
Sets
HKCU\Software\Microsoft\Windows Script\Settings\AmsiEnable to 02
VBScript Execution
VBScript runs with AMSI disabled
3
Registry Restoration
Original AMSI value is restored after cleanup
Detection Considerations
WMI Event Subscription Detection
WMI Event Subscription Detection
- 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
VBScript Execution Detection
VBScript Execution Detection
wscript.exeorcscript.exespawned byscrcons.exe- Parent process:
scrcons.exe(Script Event Consumer) - Event ID 4688: Process creation with suspicious parent
- ActiveScriptEventConsumer with encoded scripts
Network Detection
Network Detection
- WMI queries to
root\subscriptionnamespace - Creation of
__EventFilter,ActiveScriptEventConsumer,__FilterToConsumerBinding - Multiple WMI connections in succession
- DCOM traffic patterns consistent with WMI operations
AMSI Detection
AMSI Detection
- Registry modification to
AmsiEnablekey - 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
| Feature | executevbs | exec |
|---|---|---|
| Execution Method | WMI Event Subscription | Win32_Process.Create |
| Timing | Delayed (configurable) | Immediate |
| Payload Type | VBScript | Command line |
| Artifacts | Event subscriptions | Process creation |
| Complexity | Higher | Lower |
| Flexibility | Very high | Moderate |
| Detection Risk | Higher (event subs monitored) | Moderate |
| Use Case | Complex payloads, downloads | Simple commands |
Troubleshooting
Exception in Creating Timer Object
Exception in Creating Timer Object
Cause: WMI permissions or service issueSolution:
- Verify WMI service is running
- Check admin privileges
- Test with local WMI query first
- Verify
root\cimv2namespace access
Exception in Setting Event Filter
Exception in Setting Event Filter
Cause: Subscription namespace access deniedSolution:
- Ensure admin rights on target
- Check
root\subscriptionnamespace permissions - Verify WMI filter quota not exceeded
- Try different event name
Script Doesn't Execute
Script Doesn't Execute
Cause: Timeout too short or script errorSolution:
- Increase
timeoutparameter - Test VBScript locally first
- Check for syntax errors
- Verify URLs are accessible from target
AMSI Evasion Failed
AMSI Evasion Failed
Cause: Insufficient privileges or EDR blockingSolution:
- Verify admin context
- Check for EDR protecting registry
- Try alternative AMSI bypass
- Test registry modification manually
Related Actions
exec
Simpler command execution method
upload
Upload files before VBS execution
query
Verify event subscriptions
ps
Check for script execution
Additional Resources
Check for Existing Event Subscriptions
Check for Existing Event Subscriptions
Manual Cleanup (if needed)
Manual Cleanup (if needed)