Decrypt LAPSv2 (msLAPS-EncryptedPassword) passwords from Active Directory via GKDI/RPC.
# Password
python3 laps_decrypt.py -u USER -p PASSWORD -d domain.local -dc DC_IP
# Pass-the-hash
python3 laps_decrypt.py -u USER -H NTHASH -d domain.local -dc DC_IP| Flag | Description |
|---|---|
-u |
Username |
-p |
Password |
-H |
NT Hash (pass-the-hash) |
-d |
Domain |
-dc |
Domain Controller IP |
-ou |
Target OU (full DN) |
-t |
Target a specific machine |
-o |
Export results to JSON |
--debug |
Verbose output |
pip install impacket ldap3 pyasn1 pyasn1-modulesLAPSv2 chiffre le mot de passe administrateur local de chaque machine avec une chaîne cryptographique complète basée sur GKDI (Group Key Distribution Service) et DPAPI-NG. Voici chaque étape.
L'attribut AD msLAPS-EncryptedPassword contient un blob binaire structuré ainsi :
EncryptedPasswordBlob
└── Blob (CMS / RFC 5652 EnvelopedData)
├── RecipientInfo (KEKRecipientInfo)
│ ├── KeyIdentifier
│ │ ├── RootKeyId (GUID 16 bytes)
│ │ ├── L0Index (int32)
│ │ ├── L1Index (int32)
│ │ └── L2Index (int32)
│ └── EncryptedKey (CEK wrappée, 40 bytes)
└── EncryptedContentInfo
├── Algorithm AES-256-GCM
├── IV / Nonce (12 bytes)
└── Ciphertext + Tag (N bytes + 16 bytes GCM tag)
Les indices L0 / L1 / L2 définissent la position dans l'arbre de clés GKDI.
GKDI organise les clés en arbre à 3 niveaux basé sur le temps :
RootKey (256 bits, stockée dans AD)
│
└── L0 seed (KDF du RootKey avec L0Index)
│
└── L1 seed (KDF du L0 seed avec L1Index)
│
└── L2 seed (KDF du L1 seed avec L2Index)
│
└── KEK (Key Encryption Key, 256 bits)
Chaque niveau dérive 512 bits via SP800-108, puis les split en deux moitiés de 256 bits (gauche / droite). La moitié utilisée dépend de la parité de l'index.
La fonction de dérivation utilisée à chaque niveau est définie par le NIST SP800-108 en mode compteur :
K(i) = HMAC-SHA512(K_parent, i || Label || 0x00 || Context || L)
Où :
i= compteur 32 bits (little-endian), incrémenté à chaque blocLabel= identifiant du niveau ("GKID"+ suffixe selon L0/L1/L2)Context= GUID du RootKey + indices L0/L1/L2 encodésL= longueur de sortie souhaitée en bits (512 → 2 blocs de 256)
La sortie de 512 bits est split :
output[0:256] → clé "gauche" (utilisée si index pair)
output[256:512] → clé "droite" (utilisée si index impair)
On répète ce processus pour L0 → L1 → L2, donnant la KEK finale.
Le client ne calcule pas lui-même l'arbre. Il appelle le DC via RPC MS-GKDI :
GkdiGetKey(
target_sd = Security Descriptor de la machine (SID),
l0 = L0Index du blob,
l1 = L1Index du blob,
l2 = L2Index du blob,
root_key_id= RootKeyId du blob
)
→ GroupKeyEnvelope (contient les seeds nécessaires)
Le DC vérifie que le compte appelant a le droit de lire la clé (via le target_sd). Si le SID de la machine est absent du blob, on utilise S-1-1-0 (Everyone).
Une fois la KEK dérivée, on déchiffre la CEK (Content Encryption Key) avec RFC 3394 AES Key Unwrap :
CEK = AES_KeyUnwrap(KEK, EncryptedKey)
AES Key Wrap utilise 6 tours d'AES-256 sur des blocs de 64 bits avec une valeur initiale 0xA6A6A6A6A6A6A6A6. Le résultat est la CEK de 256 bits qui chiffre réellement le mot de passe.
Le mot de passe est chiffré en AES-256-GCM (mode authentifié) :
Plaintext = AES-256-GCM-Decrypt(
key = CEK (256 bits),
nonce = IV (12 bytes du blob),
ct = Ciphertext[:-16],
tag = Ciphertext[-16:]
)
Le GCM tag (16 derniers bytes) assure l'intégrité — si le tag est invalide, le déchiffrement échoue.
Le résultat déchiffré est encodé UTF-16LE et contient un objet JSON :
{
"n": "Administrator",
"p": "G3n3r@tedP@ssw0rd!",
"t": "133500000000000000"
}n= nom du compte localp= mot de passe en clairt= timestamp d'expiration (Windows FILETIME)
AD blob
→ parse KeyIdentifier (RootKeyId, L0, L1, L2) + WrappedCEK + IV + Ciphertext
→ RPC GkdiGetKey(DC) → GroupKeyEnvelope
→ SP800-108 HMAC-SHA512 (x3 niveaux) → KEK
→ AES KeyUnwrap(KEK, WrappedCEK) → CEK
→ AES-256-GCM(CEK, IV, Ciphertext) → JSON → password
mooder1