Advertisement
Guest User

Bobarian Chat Overlay PoC 0.2.1

a guest
Feb 20th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. import com.sun.net.httpserver.HttpServer;
  2.  
  3. import java.io.*;
  4. import java.net.InetSocketAddress;
  5. import java.net.URL;
  6. import java.net.URLConnection;
  7.  
  8. public class OverlayServer {
  9.  
  10.     private static final int PORT = 8357;
  11.  
  12.     public static void main(final String[] args) throws IOException {
  13.         final HttpServer srv = HttpServer.create(new InetSocketAddress("localhost", PORT), 0);
  14.         srv.createContext("/", ex -> {
  15.             // Request original file from StreamLabs
  16.             final String path = ex.getRequestURI().toString();
  17.             final URLConnection slConn = new URL("https://streamlabs.com" + path).openConnection();
  18.             // StreamLabs doesn't like the Java User Agent, so gotta get rid of it
  19.             slConn.setRequestProperty("User-agent", "");
  20.             final BufferedReader slReader = new BufferedReader(new InputStreamReader(slConn.getInputStream()));
  21.  
  22.             ex.sendResponseHeaders(200, 0);
  23.             final PrintWriter writer = new PrintWriter(ex.getResponseBody());
  24.             slReader.lines().forEach(line -> {
  25.                 // Replace all eventual references to streamlabs with localhost
  26.                 // This is necessary to circumvent the Same-Origin Policy
  27.                 line = line.replaceAll("https://streamlabs.com", "http://localhost:" + PORT);
  28.                 // If we are requesting the chat overlay, insert custom JavaScript
  29.                 if (path.startsWith("/widgets/chat-box/")) {
  30.                     // Obviously our actual JS is gonna be more complicated
  31.                     // A Proof of Concept JS file can be found at http://pastebin.com/XyNaxPVR
  32.                     line = line.replace("</body>", "<script>alert('Hello World!');</script></body>");
  33.                 }
  34.                 writer.print(line);
  35.             });
  36.             writer.flush();
  37.             writer.close();
  38.             ex.close();
  39.         });
  40.         srv.start();
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement