Skip to main content

Overview

The query action executes WMI queries to enumerate system information both locally and remotely. WMI provides access to extensive system data including processes, services, hardware, network configuration, and security settings through a SQL-like query language (WQL).
WMI queries are one of the stealthiest enumeration methods on Windows as they generate minimal suspicious activity and are commonly used by legitimate system administration tools.

Syntax

Parameters

WQL queries use double quotes internally, so when passing to SharpWMI, use escaped quotes: query=""select * from win32_service""

WMI Namespaces

Common WMI namespaces for enumeration:

Usage Examples

Basic Queries

Security Enumeration

Detects installed antivirus products on Windows 7-10.
Identifies third-party firewall products.
Checks Windows Defender protection status.

Process Enumeration

Lists all running processes with full command lines.
Find specific processes (useful for detecting shells).
Note: GetOwner() method calls require alternative approaches in WQL.

User and Group Enumeration

Lists local user accounts and their properties.
Enumerates local security groups.
Lists members of the local Administrators group.

Network Enumeration

Shows established TCP connections (similar to netstat). State=5 means ESTABLISHED.
Lists network adapter configurations.
Enumerates network shares. Type=0 is disk drive, Type=1 is print queue.

Software and Updates

Lists installed software (can be slow on some systems).
Shows installed Windows updates.
Lists programs that run at startup.

Service Enumeration

Lists all running services.
Finds auto-start services that aren’t running.
Identifies services running with SYSTEM privileges.

Scheduled Tasks

Lists scheduled tasks (legacy scheduled jobs only).

System Information

Gets OS version and details.
Hardware and domain information.
BIOS details (useful for VM detection).

Persistence Detection

Detects WMI-based persistence mechanisms.

Remote vs Local Usage

Advantages:
  • No network traffic
  • Works without admin privileges for most queries
  • No authentication required
  • Faster execution
Use Cases:
  • Post-exploitation enumeration
  • System reconnaissance after initial access
  • Service/software enumeration

Detection Considerations

While WMI queries are common in enterprise environments, certain patterns can indicate malicious activity.
  • Unusual WMI queries from non-administrative tools
  • Queries against SecurityCenter2 namespace
  • Bulk queries across multiple systems
  • Queries for process command lines
  • Event subscription enumeration
  • Queries originating from user workstations
  • Event ID 5857: WMI activity
  • Event ID 5860: Registration of temporary event consumers
  • Event ID 5861: Registration of permanent event consumers
  • Sysmon Event ID 19: WMI event filter activity
  • Sysmon Event ID 20: WMI consumer activity
  • Sysmon Event ID 21: WMI consumer binding
  • DCOM traffic on port 135
  • Dynamic RPC ports (49152-65535)
  • Multiple WMI connections from single source
  • WMI traffic from unusual source IPs

Best Practices

Query Optimization

  • Use WHERE clauses to filter results
  • Select specific properties instead of *
  • Avoid Win32_Product if possible (slow)
  • Test queries locally before remote execution

Operational Security

  • Blend in with legitimate admin activity
  • Use standard WMI namespaces when possible
  • Avoid bulk queries during business hours
  • Limit query frequency to avoid detection

Troubleshooting

Cause: Insufficient privileges or wrong credentialsSolution:
  • Verify credentials with username/password parameters
  • Ensure user is admin on target system
  • Check UAC remote restrictions
Cause: Syntax error in WQL querySolution:
  • Test query with wmic.exe first: wmic /node:target process list
  • Verify WMI class exists in namespace
  • Check for proper quote escaping
Cause: Namespace doesn’t exist on target systemSolution:
  • Verify namespace exists: wmic /namespace:\\root path __NAMESPACE
  • Use default root\cimv2 for most queries
  • Some namespaces only exist on certain Windows versions

loggedon

Enumerate logged-on users (specialized query)

ps

List processes with owner info

firewall

Enumerate firewall rules

getenv

Query environment variables