Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add JE3 spoofing to api requests #1114

Closed
wants to merge 5 commits into from

Conversation

TheDevYellowy
Copy link
Contributor

Hopefully this works, to be honest I coded it in 2 1/2 hours and didn't test it at all

@aiko-chan-ai
Copy link
Owner

i wish it could be implemented directly instead of using golang binary

@TheDevYellowy
Copy link
Contributor Author

I could try converting the golang code into js code after some sleep

@aiko-chan-ai
Copy link
Owner

nodejs is very limited in changing ciphers (openssl) ;-;

@TheDevYellowy
Copy link
Contributor Author

;-;

@aiko-chan-ai
Copy link
Owner

@marioparaschiv
Copy link

marioparaschiv commented Apr 2, 2024

i wish it could be implemented directly instead of using golang binary

Unfortunately, Node.js is really annoying when it comes to this. See: #1003 (comment)

I think this might be the only option that is viable.

@marioparaschiv
Copy link

marioparaschiv commented Apr 2, 2024

Also, User-Agent is very important. If you are mimicking a Chrome JA3, the User-Agent must match otherwise the hash will be different. Ensure you are using the same ciphers that the actual User-Agent uses.

If we are going to use the desktop client's User-Agent and WebSocket properties, we should fetch the latest client build number like so:

async getLatestClientNumber() {
    const BUILD_NUMBER_STRING = 'build_number:"';
    const BUILD_NUMBER_LENGTH = 6;

    this.logger.info('Getting latest client build number to avoid account suspensions...');

    const doc = await fetch('https://discord.com/app').then(r => r.text());
    const scripts = doc.match(/\/assets\/[0-9]{1,5}.*?.js/gmi);

    if (!scripts?.length) {
        this.logger.error('Failed to get latest build number.');
        return process.exit(-1);
    }

    // Reverse the script collection as the script containing the build number is usually at the end.
    for (const script of scripts.reverse()) {
        try {
            const js = await fetch('https://discord.com' + script, {
                headers: {
                    Origin: 'https://discord.com/',
                    Referer: 'https://discord.com/app',
                    'User-Agent': config.userAgent
                }
            }).then(r => r.text());

            const idx = js.indexOf(BUILD_NUMBER_STRING);
            if (idx === -1) continue;

            const build = js.slice(idx + BUILD_NUMBER_STRING.length, (idx + BUILD_NUMBER_STRING.length) + BUILD_NUMBER_LENGTH);
            const buildNumber = Number(build);

            if (Number.isNaN(buildNumber)) {
                throw new Error(`Expected build number to be a number. Got NaN. String: ${build}`);
            }

            config.userProperties["client_build_number"] = Number(build);
            this.logger.success('Fetched latest client build number.');

            break;
        } catch (error) {
            this.logger.error('Failed to make request while getting latest build number:', error);
        }
    }
}

@marioparaschiv
Copy link

A useful resource I found for checking your JA3: https://check.ja3.zone/

@TheDevYellowy
Copy link
Contributor Author

TheDevYellowy commented Apr 3, 2024

yeah, I found that just messing around and switching up the cypher order changed the ja3

const patched = async function () {
  const shuffled = [];
  while (ciphers.length > 0) {
    let i = Math.round(Math.random() * ciphers.length);
    if (ciphers[i] !== undefined) {
      shuffled.push(ciphers[i]);
      ciphers.splice(i, 1);
    }
  }

  https.get(url, { ciphers: shuffled.join(":"), agent: false }, (res) => {
    var d = "";
    res.on("data", (chunk) => {
      d += chunk;
    });

    res.on("end", () => {
      const data = JSON.parse(d);
      console.log(
        `${JSON.stringify(data, null, 2)}`
      );
    });
  });
};

but this would require me to re-write some of the api because of using https instead of fetch which I can do

@TheDevYellowy
Copy link
Contributor Author

I'm going to close this and do some more research on everything

@aiko-chan-ai
Copy link
Owner

Gl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants