Expand description
Async WinRM (WS-Management) client for Rust.
Provides remote command execution on Windows hosts via the WinRM protocol
with NTLMv2, Basic, Kerberos, and Certificate authentication support.
§Architecture
The crate is structured in three layers:
-
WinrmClient– high-level async API that manages shell lifecycle, command execution, and output polling. Callers interact exclusively with this type and its associated config/credential structs. -
soap(internal) – builds WS-Management XML envelopes for Create, Execute, Receive, Signal, and Delete operations, and parses the corresponding responses. Envelope construction uses rawformat!strings rather than a full XML library to keep dependencies minimal. -
ntlm(internal) – implements theNTLMv2challenge/response handshake per MS-NLMP. OnlyNTLMv2is supported;NTLMv1is intentionally excluded.
HTTP transport is provided by reqwest with rustls-tls.
§Authentication methods
| Method | Enum variant | Notes |
|---|---|---|
| HTTP Basic | AuthMethod::Basic | Credentials sent base64-encoded per request. Use only over HTTPS. |
NTLMv2 | AuthMethod::Ntlm | Three-step handshake (negotiate / challenge / authenticate). Default. |
| Kerberos | AuthMethod::Kerberos | SPNEGO Negotiate via system Kerberos. Requires kerberos feature + kinit. |
| Certificate | AuthMethod::Certificate | TLS client certificate. Set client_cert_pem and client_key_pem on config. |
§Error handling
All fallible operations return Result<T, WinrmError>. The top-level
WinrmError enum wraps transport errors (reqwest::Error), SOAP faults
(SoapError), NTLM failures (NtlmError), and authentication
rejections. Errors are designed for programmatic matching via match and
for human-readable display via their Display impls.
§Shell reuse
For running multiple commands on the same host, use WinrmClient::open_shell
to create a Shell that persists across commands, avoiding the overhead of
shell creation and deletion per command.
§Cargo features
kerberos– Enables Kerberos authentication viacross-krb5.credssp– Experimental. EnablesCredSSPauthentication for double-hop delegation. Pulls inopensslas a C dependency (required because Microsoft’sCredSSPserver has proven incompatible withrustlsin-memory TLS — seesrc/auth/credssp.rs). The handshake is not yet fully validated end-to-end; treat as preview-quality and do not use in production.
§Re-exports
A few third-party types appear in this crate’s public API and are re-exported for convenience:
SecretString/ExposeSecretfrom thesecrecycrate — used for thepasswordfield ofWinrmCredentials.CancellationTokenfromtokio_util— used as a parameter to the*_with_cancelmethods ofWinrmClientso callers can cooperatively cancel in-flight operations.
§Example
use winrm_rs::{WinrmClient, WinrmConfig, WinrmCredentials};
let client = WinrmClient::new(
WinrmConfig::default(),
WinrmCredentials::new("administrator", "password", ""),
)?;
let output = client.run_powershell("win-server", "Get-Process | ConvertTo-Json").await?;
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));Structs§
- Cancellation
Token - A token which can be used to signal a cancellation request to one or more tasks.
- Command
Output - Collected output from a completed remote command.
- Needs
Credentials - Typestate marker: credentials have not yet been provided.
- Ntlm
Session - NTLM session state for message encryption/decryption after authentication.
- Ready
- Typestate marker: all required fields are set and
buildcan be called. - Receive
Output - Parsed output from a single WinRM Receive response.
- Shell
- A reusable WinRM shell session.
- Winrm
Client - Async WinRM (WS-Management) HTTP client.
- Winrm
Client Builder - Builder for
WinrmClientwith compile-time state tracking. - Winrm
Config - Configuration for a
WinrmClientconnection. - Winrm
Credentials - Credentials for WinRM authentication.
Enums§
- Auth
Method - Authentication method for the WinRM HTTP transport.
- Cred
SspError - Errors from the CredSSP authentication protocol (MS-CSSP).
- Encryption
Mode - Controls whether NTLM message encryption (sealing) is applied to SOAP bodies.
- Ntlm
Error - Errors from the NTLM authentication protocol layer.
- Soap
Error - Errors from SOAP envelope parsing or WS-Management fault responses.
- Winrm
Error - Errors that can occur during WinRM operations.
Constants§
- RESOURCE_
URI_ PSRP - PowerShell remoting plugin resource URI (the default PS configuration).
Traits§
- Expose
Secret - Expose a reference to an inner secret
Functions§
- encode_
powershell_ command - Encode a PowerShell script as UTF-16LE base64 for use with
-EncodedCommand.
Type Aliases§
- Secret
String - Secret string type.