Skip to content

Commit d234409

Browse files
committed
Land rapid7#8918, wp_admin_shell_upload multisite fix
2 parents 64dca2d + fde68ac commit d234409

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

lib/msf/core/exploit/http/wordpress/helpers.rb

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ module Msf::Exploit::Remote::HTTP::Wordpress::Helpers
1010
# @param pass [String] Password
1111
# @param redirect URL [String] to redirect after successful login
1212
# @return [Hash] The post data for vars_post Parameter
13-
def wordpress_helper_login_post_data(user, pass, redirect=nil)
13+
def wordpress_helper_login_post_data(user, pass, redirect = nil)
1414
post_data = {
15-
'log' => user.to_s,
16-
'pwd' => pass.to_s,
17-
'redirect_to' => redirect.to_s,
18-
'wp-submit' => 'Login'
15+
'log' => user.to_s,
16+
'pwd' => pass.to_s,
17+
'redirect_to' => redirect.to_s,
18+
'wp-submit' => 'Login'
1919
}
2020
post_data
2121
end
@@ -31,23 +31,23 @@ def wordpress_helper_login_post_data(user, pass, redirect=nil)
3131
# @return [String,nil] The location of the new comment/post, nil on error
3232
def wordpress_helper_post_comment(comment, comment_post_id, login_cookie, author, email, url)
3333
vars_post = {
34-
'comment' => comment,
35-
'submit' => 'Post+Comment',
36-
'comment_post_ID' => comment_post_id.to_s,
37-
'comment_parent' => '0'
34+
'comment' => comment,
35+
'submit' => 'Post+Comment',
36+
'comment_post_ID' => comment_post_id.to_s,
37+
'comment_parent' => '0'
3838
}
3939
vars_post.merge!({
40-
'author' => author,
41-
'email' => email,
42-
'url' => url,
40+
'author' => author,
41+
'email' => email,
42+
'url' => url
4343
}) unless login_cookie
4444

4545
options = {
46-
'uri' => normalize_uri(target_uri.path, 'wp-comments-post.php'),
47-
'method' => 'POST'
46+
'uri' => normalize_uri(target_uri.path, 'wp-comments-post.php'),
47+
'method' => 'POST'
4848
}
49-
options.merge!({'vars_post' => vars_post})
50-
options.merge!({'cookie' => login_cookie}) if login_cookie
49+
options.merge!({ 'vars_post' => vars_post })
50+
options.merge!({ 'cookie' => login_cookie }) if login_cookie
5151
res = send_request_cgi(options)
5252
if res && res.redirect? && res.redirection
5353
return wordpress_helper_parse_location_header(res)
@@ -65,7 +65,7 @@ def wordpress_helper_post_comment(comment, comment_post_id, login_cookie, author
6565
# @param comments_enabled [Boolean] If true try to find a post id with comments enabled, otherwise return the first found
6666
# @param login_cookie [String] A valid login cookie to perform the bruteforce as an authenticated user
6767
# @return [Integer,nil] The post id, nil when nothing found
68-
def wordpress_helper_bruteforce_valid_post_id(range, comments_enabled=false, login_cookie=nil)
68+
def wordpress_helper_bruteforce_valid_post_id(range, comments_enabled = false, login_cookie = nil)
6969
range.each { |id|
7070
vprint_status("Checking POST ID #{id}...") if (id % 100) == 0
7171
body = wordpress_helper_check_post_id(wordpress_url_post(id), comments_enabled, login_cookie)
@@ -81,15 +81,15 @@ def wordpress_helper_bruteforce_valid_post_id(range, comments_enabled=false, log
8181
# @param comments_enabled [Boolean] Check if comments are enabled on this post
8282
# @param login_cookie [String] A valid login cookie to perform the check as an authenticated user
8383
# @return [String,nil] the HTTP response body of the post, nil otherwise
84-
def wordpress_helper_check_post_id(uri, comments_enabled=false, login_cookie=nil)
84+
def wordpress_helper_check_post_id(uri, comments_enabled = false, login_cookie = nil)
8585
options = {
86-
'method' => 'GET',
87-
'uri' => uri
86+
'method' => 'GET',
87+
'uri' => uri
8888
}
89-
options.merge!({'cookie' => login_cookie}) if login_cookie
89+
options.merge!({ 'cookie' => login_cookie }) if login_cookie
9090
res = send_request_cgi(options)
9191
# post exists
92-
if res and res.code == 200
92+
if res && res.code == 200
9393
# also check if comments are enabled
9494
if comments_enabled
9595
if res.body =~ /form.*action.*wp-comments-post\.php/
@@ -123,8 +123,8 @@ def wordpress_helper_parse_location_header(res)
123123
#
124124
# @param cookie [String] A valid admin session cookie
125125
# @return [String,nil] The nonce, nil on error
126-
def wordpress_helper_get_plugin_upload_nonce(cookie)
127-
uri = normalize_uri(wordpress_url_backend, 'plugin-install.php')
126+
def wordpress_helper_get_plugin_upload_nonce(cookie, path = nil)
127+
uri = path || normalize_uri(wordpress_url_backend, 'plugin-install.php')
128128
options = {
129129
'method' => 'GET',
130130
'uri' => uri,
@@ -134,6 +134,9 @@ def wordpress_helper_get_plugin_upload_nonce(cookie)
134134
res = send_request_cgi(options)
135135
if res && res.code == 200
136136
return res.body.to_s[/id="_wpnonce" name="_wpnonce" value="([a-z0-9]+)"/i, 1]
137+
elsif res && res.redirect? && res.redirection
138+
path = wordpress_helper_parse_location_header(res)
139+
return wordpress_helper_get_plugin_upload_nonce(cookie, path)
137140
end
138141
end
139142
end

0 commit comments

Comments
 (0)