Skip to content

Instantly share code, notes, and snippets.

@diamondburned
Last active March 14, 2023 21:02
Show Gist options
  • Save diamondburned/ba02d3a2d2f0e9700c832b5684f7634b to your computer and use it in GitHub Desktop.
Save diamondburned/ba02d3a2d2f0e9700c832b5684f7634b to your computer and use it in GitHub Desktop.
Discord Websocket injector

Script snippet for use with TamperMonkey.

// ==UserScript==
// @name WS hack
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over Discord!
// @author You
// @match https://discord.com/*
// @grant none
// @run-at document-start
// @require https://cdnjs.cloudflare.com/ajax/libs/pako/1.0.11/pako.min.js
// ==/UserScript==
(function() {
'use strict';
function newInflator() {
return new pako.Inflate({to: "string", raw: false});
};
const nativeWebSocket = window.WebSocket;
window.WebSocket = function(url, ...args) {
console.log("INTERJECTED WS: " + url);
const socket = new nativeWebSocket(url, ...args);
if (!url.includes("gateway.discord.gg")) return socket;
let inflator = newInflator();
socket.addEventListener("message", (ev) => {
inflator.push(ev.data, 2);
console.log("EVENT", JSON.parse(inflator.result));
});
return socket;
};
})();
@NaN-i
Copy link

NaN-i commented Mar 14, 2023

This is currently not working. Have tried multiple ways to intercept WebSocket...

@diamondburned
Copy link
Author

Indeed, this doesn't work anymore. I haven't poked around the code base enough to figure out how to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment