Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.sun.net.httpserver.HttpServer;
- import java.io.*;
- import java.net.InetSocketAddress;
- import java.net.URL;
- import java.net.URLConnection;
- public class OverlayServer {
- private static final int PORT = 8357;
- public static void main(final String[] args) throws IOException {
- final HttpServer srv = HttpServer.create(new InetSocketAddress("localhost", PORT), 0);
- srv.createContext("/", ex -> {
- // Request original file from StreamLabs
- final String path = ex.getRequestURI().toString();
- final URLConnection slConn = new URL("https://streamlabs.com" + path).openConnection();
- // StreamLabs doesn't like the Java User Agent, so gotta get rid of it
- slConn.setRequestProperty("User-agent", "");
- final BufferedReader slReader = new BufferedReader(new InputStreamReader(slConn.getInputStream()));
- ex.sendResponseHeaders(200, 0);
- final PrintWriter writer = new PrintWriter(ex.getResponseBody());
- slReader.lines().forEach(line -> {
- // Replace all eventual references to streamlabs with localhost
- // This is necessary to circumvent the Same-Origin Policy
- line = line.replaceAll("https://streamlabs.com", "http://localhost:" + PORT);
- // If we are requesting the chat overlay, insert custom JavaScript
- if (path.startsWith("/widgets/chat-box/")) {
- // Obviously our actual JS is gonna be more complicated
- // A Proof of Concept JS file can be found at http://pastebin.com/XyNaxPVR
- line = line.replace("</body>", "<script>alert('Hello World!');</script></body>");
- }
- writer.print(line);
- });
- writer.flush();
- writer.close();
- ex.close();
- });
- srv.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement