Newer
Older
WSSSnoop / script.js
0xRoM on 6 Jul 2023 6 KB Initial commit
  1. var dataSendUsed = false;
  2. var checkSend = false;
  3.  
  4. function clearPage(){
  5. $('#cswsh-output').empty();
  6. $('html, body').scrollTop($(document).height());
  7. }
  8.  
  9. function startSnooping(){
  10. $('#startSnoop').hide();
  11. $('#stopSnoop').show();
  12. $('.sendBar').show();
  13. $('#wssSendText').focus();
  14. writeToScreen("Start snooping: " + $("#cswshURL").val());
  15. checkCSWSH();
  16. checkSend = true;
  17. checkDataSend();
  18. }
  19.  
  20. function stopSnooping(){
  21. $('#startSnoop').show();
  22. $('#stopSnoop').hide();
  23. $('.sendBar').hide();
  24. websocket.close();
  25. checkSend = false
  26. writeToScreen("Stop snooping");
  27. }
  28.  
  29. function checkCSWSH(){
  30. var wsUri = $("#cswshURL").val();
  31. statusWaiting();
  32. websocket = new WebSocket(wsUri);
  33. websocket.onopen = function(evt) { onOpen(evt) };
  34. websocket.onclose = function(evt) { onClose(evt) };
  35. websocket.onmessage = function(evt) { onMessage(evt) };
  36. websocket.onerror = function(evt) { onError(evt) };
  37. }
  38.  
  39. function onOpen(evt){
  40. writeToScreen('<span class="timestamp">'+getTimestamp()+'</span> '+"CONNECTED");
  41. statusConnected()
  42. //doSend("origin policy unchecked!");
  43. }
  44.  
  45. function onClose(evt){
  46. writeToScreen('<span class="timestamp">'+getTimestamp()+'</span> '+"DISCONNECTED");
  47. statusOffline()
  48. if( $('#stopSnoop').css('display') != 'none' ){
  49. checkCSWSH()
  50. }
  51. }
  52.  
  53. function onMessage(evt) {
  54. var encodedData = encodeToHtmlEntities(evt.data);
  55. writeToScreen('<span class="timestamp">'+getTimestamp()+'</span> '+'<span style="color: #A7E734;">RECV:</span><span> ' + encodedData + '</span>');
  56.  
  57. var recvValue = encodedData.trim();
  58. if (dataSendUsed) {
  59. sendToInjectPHP(recvValue);
  60. }
  61. var sendValue = getSendValueForRecv(recvValue);
  62. if (sendValue) {
  63. doSendAuto(sendValue);
  64. }
  65. }
  66.  
  67. // Function to get the corresponding "send" value for a "recv" value
  68. function getSendValueForRecv(recvValue) {
  69. var valueTable = document.getElementById("valueTable");
  70. var rows = valueTable.getElementsByTagName("tr");
  71. for (var i = 0; i < rows.length; i++) {
  72. var cells = rows[i].getElementsByTagName("td");
  73. if (cells.length === 3 && cells[0].innerText.trim() === recvValue) {
  74. return cells[1].innerText.trim();
  75. }
  76. }
  77. return null;
  78. }
  79.  
  80. function onError(evt){
  81. writeToScreen('<span class="timestamp">'+getTimestamp()+'</span> '+'<span style="color: red;">ERROR:</span> ' + encodeToHtmlEntities(evt.data));
  82. }
  83.  
  84. function doSend(message){
  85. writeToScreen('<span class="timestamp">'+getTimestamp()+'</span> '+"SENT: " + encodeToHtmlEntities(message));
  86. websocket.send(message);
  87. }
  88.  
  89. function doSendAuto(message){
  90. writeToScreen('<span class="timestamp">'+getTimestamp()+'</span> '+'<span style="color: #bd34e7;">AUTO:</span><span> ' + encodeToHtmlEntities(message));
  91. websocket.send(message);
  92. }
  93.  
  94. function doSendPayload(message){
  95. writeToScreen('<span class="timestamp">'+getTimestamp()+'</span> '+'<span style="color: #e734bd;">INJT:</span><span> ' + encodeToHtmlEntities(message));
  96. websocket.send(message);
  97. }
  98.  
  99. var sentData = null;
  100. function checkDataSend() {
  101. if(checkSend == true){
  102. $.ajax({
  103. url: "/data_send",
  104. method: "GET",
  105. dataType: "text",
  106. async:false,
  107. contentType: "text",
  108. beforeSend: function( xhr ) {
  109. xhr.overrideMimeType( "text/plain; charset=x-user-defined" );
  110. },
  111. success: function (data) {
  112. if (data && data !== sentData) {
  113. console.log(data);
  114. doSendPayload(data);
  115. sentData = data;
  116. dataSendUsed = true; // Set the variable to true if data_send is used
  117. //sendToInjectPHP(recvValue); // Call sendToInjectPHP unconditionally
  118. }
  119. }
  120. });
  121. // Check again after a delay
  122. setTimeout(checkDataSend, 2000);
  123. }
  124. return false;
  125. }
  126.  
  127. function sendToInjectPHP(data) {
  128. if (dataSendUsed) {
  129. dataSendUsed = false;
  130. var url = "/inject.php?response=" + encodeURIComponent(data);
  131.  
  132. $.ajax({
  133. url: url,
  134. method: "GET",
  135. dataType: "text",
  136. contentType: "text",
  137. beforeSend: function( xhr ) {
  138. xhr.overrideMimeType( "text/plain; charset=x-user-defined" );
  139. },
  140. success: function (response) {
  141. // Handle success if necessary
  142. }
  143.  
  144. });
  145. }
  146. }
  147.  
  148.  
  149.  
  150. function writeToScreen(message){
  151. output = document.getElementById("cswsh-output");
  152. var pre = document.createElement("div");
  153. pre.style.wordWrap = "break-word";
  154. pre.innerHTML = message;
  155. output.appendChild(pre);
  156. $('html, body').scrollTop($(document).height());
  157. }
  158.  
  159. $("#wssCommand").submit(function(e) {
  160. doSend( $('#wssSendText').val() );
  161. $('#wssSendText').val("");
  162. $('#wssSendText').focus();
  163. e.preventDefault();
  164. });
  165.  
  166. function statusConnected(){
  167. $('#status').html("Connected");
  168. $('#status').css("color","lightgreen");
  169. }
  170. function statusOffline(){
  171. $('#status').html("Offline");
  172. $('#status').css("color","red");
  173. }
  174. function statusWaiting(){
  175. $('#status').html("Waiting...");
  176. $('#status').css("color","yellow");
  177. }
  178.  
  179. // Function to store recv and send values
  180. function storeValues() {
  181. var recvValue = document.getElementById("recvInput").value;
  182. var sendValue = document.getElementById("sendInput").value;
  183.  
  184. if (recvValue && sendValue) {
  185. var newRow = document.createElement("tr");
  186. newRow.innerHTML =
  187. "<td>" +
  188. recvValue +
  189. "</td><td>" +
  190. sendValue +
  191. '</td><td><a class="removeButton" onclick="removeRow(this)">[x]</a></td>';
  192. document.getElementById("valueTableBody").appendChild(newRow);
  193.  
  194. // Clear input fields
  195. document.getElementById("recvInput").value = "";
  196. document.getElementById("sendInput").value = "";
  197. }
  198. }
  199.  
  200. // Function to remove a row from the table
  201. function removeRow(button) {
  202. var row = button.parentNode.parentNode;
  203. row.parentNode.removeChild(row);
  204. }
  205.  
  206. function encodeToHtmlEntities(str) {
  207. var encodedStr = "";
  208. for (var i = 0; i < str.length; i++) {
  209. var charCode = str.charCodeAt(i);
  210. if (charCode > 127 || /[&<>"'`]/.test(str[i])) {
  211. encodedStr += "&#" + charCode + ";";
  212. } else {
  213. encodedStr += str.charAt(i);
  214. }
  215. }
  216. return encodedStr;
  217. }
  218.  
  219. function getTimestamp() {
  220. var now = new Date();
  221. var day = now.getDate();
  222. var month = now.getMonth() + 1; // Adding 1 because months are zero-based
  223. var hours = now.getHours();
  224. var minutes = now.getMinutes();
  225.  
  226. // Pad single digits with leading zeros
  227. day = day < 10 ? '0' + day : day;
  228. month = month < 10 ? '0' + month : month;
  229. hours = hours < 10 ? '0' + hours : hours;
  230. minutes = minutes < 10 ? '0' + minutes : minutes;
  231.  
  232. var timestamp = '[' + day + '/' + month + ' ' + hours + ':' + minutes + ']';
  233. return timestamp;
  234. }
  235.  
  236. //setTimeout(checkDataSend(), 1000);
Buy Me A Coffee