What is SharpWMI?
SharpWMI is a C# implementation of various WMI functionality that provides offensive security practitioners with a native toolkit for Windows Management Instrumentation operations. It enables local and remote WMI queries, remote process creation, VBScript execution, file uploads, and system enumeration—all through the Windows Management Instrumentation interface.Understanding WMI
Windows Management Instrumentation (WMI) is Microsoft’s implementation of Web-Based Enterprise Management (WBEM), providing a standardized infrastructure for managing and monitoring Windows systems.Remote Execution
Execute processes and scripts on remote systems via Win32_Process
System Enumeration
Query system information, services, processes, and configurations
Event Subscriptions
Create WMI event subscriptions for delayed or triggered execution
File Operations
Upload files using WMI class properties as a data channel
WMI Attack Surface
Key Capabilities
- Execution
- Enumeration
- File Operations
- Process Management
Remote Code Execution:
- Direct process creation via Win32_Process
- VBScript execution through event subscriptions
- Command output retrieval
- MSI installation support
- AMSI evasion capabilities
Available Actions
SharpWMI provides the following actions organized by category:Enumeration Actions
query
Execute WMI queries for system enumeration
loggedon
Enumerate logged-on users on remote systems
ps
List running processes with owner information
firewall
Enumerate firewall rules and ports
Execution Actions
exec
Create remote processes via WMI
executevbs
Execute VBScript through WMI event subscriptions
install
Install MSI files remotely
File and Process Actions
Environment Variable Actions
getenv
Retrieve environment variables
setenv
Set environment variable values
delenv
Delete environment variables
Basic Usage Patterns
Local Enumeration
Query the local system without requiring alternate credentials:Remote Enumeration
Query remote systems with optional credentials:Remote Execution
Execute commands on remote systems:Common Arguments
All remote actions support the following common arguments:- Targeting
- Authentication
- Execution Options
Target Specification:
| Argument | Description |
|---|---|
computername=HOST | Target single remote host |
computername=HOST1,HOST2,... | Target multiple hosts (comma-separated) |
| (omit computername) | Target localhost |
Typical Workflows
Domain Reconnaissance
Domain Reconnaissance
Remote Execution Chain
Remote Execution Chain
Credential Harvesting
Credential Harvesting
Stealthy Enumeration
Stealthy Enumeration
Detection Considerations
Host-Based Detection
Host-Based Detection
Windows Event Logs:
- Event ID 4688: Process creation (Win32_Process.Create)
- Event ID 5857-5861: WMI activity
- Event ID 5858: WMI permanent event subscriptions (executevbs action)
- Sysmon Event ID 19-21: WMI event consumer creation
- AMSI evasion modifies
HKCU\Software\Microsoft\Windows Script\Settings - WMI event subscriptions persist in WMI repository
Network Detection
Network Detection
- DCOM traffic on port 135 (RPC endpoint mapper)
- Dynamic RPC ports for WMI communication
- SMB traffic if using network shares
- Unusual WMI query patterns
WMI-Specific Indicators
WMI-Specific Indicators
- Creation of suspicious WMI classes (file upload)
- ActiveScriptEventConsumer with VBScript payloads
- Win32_Process creation from remote systems
- Bulk WMI queries across multiple systems
- WMI registry modifications for AMSI
Defensive Measures
Defensive Measures
- Monitor WMI event log (Microsoft-Windows-WMI-Activity/Operational)
- Enable Sysmon with WMI activity rules
- Alert on WMI event subscription creation
- Monitor Win32_Process.Create invocations
- Restrict WMI access via GPO/firewall rules
- Implement WMI query auditing
AMSI Evasion
SharpWMI includes AMSI evasion capabilities for execution actions:AMSI evasion works by modifying the registry key
HKCU\Software\Microsoft\Windows Script\Settings\AmsiEnable to disable AMSI for VBScript and PowerShell. The original value is restored after execution.exec(withresult=true)executevbsuploadinstall
Prerequisites
Execution Requirements
Execution Requirements
- Windows operating system
- .NET Framework 3.5 or later
- Appropriate network access to target systems
Privilege Requirements
Privilege Requirements
Local Operations:
- Standard user privileges for local queries
- Administrator for some system queries
- Local administrator on target system
- WMI permissions on target
- Network access to RPC/DCOM ports
Network Requirements
Network Requirements
- Port 135 (RPC endpoint mapper)
- Dynamic RPC ports (49152-65535 by default)
- Port 445 (SMB) may be used for authentication
Technical Background
Win32_Process.Create vs Event Subscriptions
Win32_Process.Create vs Event Subscriptions
Win32_Process.Create:
- Direct synchronous execution
- Immediate process creation
- Limited to command-line arguments
- Used by
execaction
- Asynchronous delayed execution
- Supports VBScript payloads
- Can persist across reboots (if not cleaned up)
- More complex detection footprint
- Used by
executevbsaction
File Upload Mechanism
File Upload Mechanism
SharpWMI uploads files by:
- Creating a temporary WMI class with a string property
- Storing base64-encoded file bytes in the property
- Using PowerShell on the target to read from WMI and write to disk
- Cleaning up the temporary WMI class
Command Output Retrieval
Command Output Retrieval
When using
result=true with the exec action:- SharpWMI creates an environment variable with encoded command output
- The command is wrapped in PowerShell to capture output
- Output is XOR-encoded and stored in a WMI environment variable
- SharpWMI retrieves and decodes the output
- Environment variable is cleaned up
Authors and Credits
| Contribution | Author |
|---|---|
| Original SharpWMI implementation | Will Schroeder @harmj0y |
| WMI code-exec output idea | Evi1cg @Ridter |
| AMSI evasion code (from SharpMove) | Steven Flores 0xthirteen |
| Enhancements, VBS flexibility, file upload | Mariusz B. / mgeeky @mariuszbit |
| Install MSI files feature | Justin Bui @slyd0g |
Next Steps
Compilation Guide
Build SharpWMI from source
Usage Examples
Practical usage scenarios and examples
WMI Queries
Execute WMI queries for enumeration
Remote Execution
Create remote processes
License
SharpWMI is licensed under the BSD 3-Clause license.SharpWMI is part of the GhostPack suite of offensive security tools created by @harmj0y.