Skip to content

Impacket wmiquery.py

Back to the category index / Back to the command index

Connects to a WMI namespace, runs WQL queries, and displays the properties of returned objects.

ItemDetails
Implementationexamples/wmiquery.py
CategoryRemote execution / WMI / services
Size219 lines
DistributionInstalled as a script through scripts=examples/*.py in setup.py

Run python examples/wmiquery.py -h for the current option definitions.

ArgumentDescription
target[[domain/]username[:password]@]
-namespaceNamespace name (default: //./root/cimv2)
-fileFile containing commands for the WQL shell
-debugEnable debug output
-tsAdd a timestamp to each log message
-com-versionDCOM version in MAJOR_VERSION:MINOR_VERSION format, for example 5.7
-hashesNTLM hashes in LMHASH:NTHASH format
-no-passDo not prompt for a password (useful with -k)
-kUse Kerberos authentication. Look for matching credentials in the ccache file named by KRB5CCNAME; if none are valid, use those specified on the command line
-aesKeyAES key for Kerberos authentication (128 or 256 bits)
-dc-ipDomain controller IP address; if omitted, use the domain name (FQDN) from the target parameter
-rpc-auth-levelRPC authentication level: default, integrity (RPC_C_AUTHN_LEVEL_PKT_INTEGRITY), or privacy (RPC_C_AUTHN_LEVEL_PKT_PRIVACY); for example, the CIM path “root/MSCluster” requires privacy by default (choices: integrity, privacy, default)

The tool creates a DCOM connection and logs into the specified namespace (default: root\cimv2). It passes each WQL query to ExecQuery, retrieves objects from the enumerator, displays property names, types, and values, and repeats until it receives the end-of-enumeration status. The RPC authentication level can be set to integrity or privacy.

A WMI query resembles SQL, but selects WMI class instances or metadata with WQL. This command proceeds through DCOM connection, namespace login, ExecQuery, and enumeration. The namespace defines the scope of classes the query can reference. The same WQL query can return different results, or fail to find a class, in another namespace.

ExecQuery returns a COM enumerator rather than an array of all results. The client calls Next in batches, reads each object’s property set, and treats the HRESULT that marks the end of enumeration as normal termination. Property values may be scalars, arrays, NULL, or embedded objects, so display should retain types and missing values.

-file runs multiple queries in sequence over the same authenticated DCOM/WMI session. A syntax error in one query need not break the entire connection. The RPC authentication level controls packet integrity or privacy, a separate layer from WMI authorization. Releasing query objects and enumerators also matters during long batches.

SymbolLocationWhere to trace its responsibility
module-level entry1Parses arguments and runs at the top level
ModuleMain names used
impacket.exampleslogger
impacket.examples.utilsparse_target
impacketversion
impacket.dcerpc.v5.dtypesNULL
impacket.dcerpc.v5.dcomwmi
impacket.dcerpc.v5.dcomrtCOMVERSION, DCOMConnection
impacket.dcerpc.v5.rpcrtRPC_C_AUTHN_LEVEL_PKT_INTEGRITY, RPC_C_AUTHN_LEVEL_PKT_PRIVACY

Output, side effects, and required privileges

Section titled “Output, side effects, and required privileges”
  • The tool primarily makes queries and authentication attempts. Frequent runs can affect audit logs, account lockouts, and target load.
  • On failure, use protocol status codes to determine whether name resolution, connection, authentication, service state, or permissions caused the stop.

The code depends on dcerpc.v5.dcomrt, dcom.wmi, and rpcrt. The top-level CLI currently handles orchestration; if adding reusable features, separate query execution and display into a class or functions.