dpapi-ng
DPAPI-NG (CNG "group protection"), in pure Rust. Decrypt Windows LAPS
(msLAPS-EncryptedPassword), gMSA and dMSA managed passwords off the wire, from Linux/macOS,
with no bcrypt.dll, no FFI, no Windows host in the loop.
Status
0.2.0-dev — actively developed. Part of the
icedracon Rust offensive AD ecosystem and dogfooded by
adhammer (the dump laps / dump gmsa commands).
What's new in 0.2.0-dev
The MS-GKDI structures (KeyIdentifier, GroupKeyEnvelope, the SP800-108 KDF, the L0/L1/L2
tree walk, the ISDKey::GetKey RPC) have moved out to the
ms-gkdi crate. This crate's gkdi, kdf and (rpc
feature-gated) rpc modules become thin pub use shims marked #[deprecated] — 0.1.x code
compiles unchanged, and ms_gkdi::GkdiError lifts into DpapiError via From so existing ?
call sites stay wired.
This is a coordinated no-yank release path: 0.1.1 stays live on crates.io for anyone pinned to
it, and new callers get the split cleanly on their next cargo update. dpapi-ng 0.2.x will
keep the shims through the deprecation window, then drop them in 0.3.0.
What it does
Windows LAPS, gMSA and dMSA managed passwords are all protected the same way: a CMS
EnvelopedData whose content key is wrapped under a KEK derived from a KDS root key that
lives on the domain controllers. The blob carries no key — only a key identifier: which root
key, and which node of its L0/L1/L2 tree. A principal allowed to read the secret asks a DC for
that node (GetKey over MS-GKDI) and derives downwards.
This crate does everything except the RPC call.
Usage
use ;
use GroupKeyEnvelope;
#
If the DC round-trip isn't your concern and you already have the L2 seed key, call
[decrypt_with_seed_key] directly; if you already know the exact KEK derivation your
environment uses, call [decrypt_with_kek] and skip the retry loop.
What is in here
cms::ProtectedBlob— the CMSEnvelopedData, itsKEKRecipientInfoand the AES-GCM content parameters, parsed on a small hand-written DER reader (der.rs, ~200 LOC) rather than a codegen'd ASN.1 stack.LapsBlob+laps_password_from_json— the Windows LAPS attribute header (update_timestampFILETIME + blob length) and the UTF-16LE JSON payload ({"n":"…","t":"…","p":"…"}) — extracted without a JSON dependency.decrypt/decrypt_with_seed_key/decrypt_with_kek/decrypt_content— the four entry points into the crypto: full envelope path, seed-key-known path, KEK-known path, and raw AES-256-GCM open with a pre-unwrapped CEK.gkdi/kdf/ (featurerpc)rpc— thin#[deprecated]re-export shims overms-gkdiso 0.1.x import paths keep compiling.
Transport is deliberately out of scope
GetKey is one MS-GKDI RPC call over \pipe\lsass with authentication and sealing, and every
project that needs this already has a DCE/RPC stack. Make the call (via dcerpc +
smb2-client + ntlmssp, or ms-gkdi::rpc if you'd rather not roll your own), hand the
response bytes to GroupKeyEnvelope::parse, and keep this crate free of a transport
dependency.
If you want the RPC caller re-exported anyway — because you're upgrading 0.1.x code that
already imported dpapi_ng::rpc::get_key — enable the rpc feature:
= { = "0.2", = ["rpc"] }
What works / what does not (this version)
- ✅ CMS
EnvelopedDataparser + AES key-unwrap + AES-256-GCM open, unit-tested end-to-end (build a real envelope, decrypt it, byte-compare). - ✅
LapsBlobheader split + LAPS JSON password extraction, validated against realmsLAPS-EncryptedPasswordattributes captured from a lab DC. - ✅ Multi-candidate seed-key → KEK derivation: because Windows has used more than one
derivation across versions,
decrypt_with_seed_keytries known candidates in order. This is safe rather than sloppy — AES key-wrap and AES-GCM are both authenticated, so a wrong KEK fails loudly instead of yielding plausible garbage. - ⚠
gkdi,kdf,rpcare#[deprecated]shims for the 0.2.x line only. New code should depend onms-gkdidirectly. - ⚠ Only the CNG group-protection profile is implemented — legacy DPAPI (
CryptProtectData, per-user master keys) is a different protocol and out of scope.
Example — inspect a captured blob
Prints the key identifier (root key, L0/L1/L2 node, KDF hash, secret algorithm, domain/forest) and the content parameters (nonce, tag length, wrapped-key + ciphertext sizes). Everything shown is derived without any key — this is public metadata.
Related icedracon crates
ms-gkdi— the MS-GKDI structures, KDF, tree walk andISDKey::GetKeyRPC that this crate's shims re-export.dcerpc— the RPC stack you'd normally use to make theGetKeycall (\pipe\lsass,PKT_PRIVACY).smb2-client+ntlmssp— the transport + auth layers underdcerpc.windows-sddl—Sid/Guidtypes you'll want on the LDAP side to resolve the principal that owns a LAPS-protected computer object.adhammer— the AD security-assessment toolkit whosedump laps/dump gmsacommands wire this all together end-to-end.
License
MIT © 2026 zevs.
Authorized-testing / research / education use only.