Brozy123 commited on
Commit
6b21eb3
·
verified ·
1 Parent(s): 7dc7be2

Update network_fix.js

Browse files
Files changed (1) hide show
  1. network_fix.js +72 -28
network_fix.js CHANGED
@@ -3,10 +3,10 @@ const http = require('http');
3
  const dns = require('dns');
4
 
5
  const DOMAINS = [
6
- "discord.com",
7
  "ptb.discord.com",
8
  "canary.discord.com",
9
- "discordapp.com"
 
10
  ];
11
  let current_index = 0;
12
 
@@ -25,35 +25,79 @@ function applyAdvancedFixes() {
25
  });
26
 
27
  const target_domain = DOMAINS[current_index];
28
-
29
- // REST API Test using standard https module for more detail
30
- const req = https.get(`https://${target_domain}/api/v10/gateway`, (res) => {
31
- console.log(`[*] REST Test: ${target_domain} -> ${res.statusCode}`);
32
- });
33
-
34
- req.on('error', (e) => {
35
- console.log(`[!] REST Test: ${target_domain} -> FAILED (${e.code || e.message})`);
36
- });
37
-
38
- req.end();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
- // Hijacker - Only active if we have a rotated domain
41
- if (current_index > 0) {
42
- console.log(`[*] NetworkFix: Hijacker Active -> ${target_domain}`);
43
- const _oldRequest = https.request;
44
- https.request = function(options, callback) {
45
- let opt = options;
46
- const host = typeof opt === 'string' ? opt : (opt.hostname || opt.host);
47
- if (host && host.includes('discord.com')) {
48
- if (typeof opt === 'string') {
49
- opt = opt.replace('discord.com', target_domain);
50
- } else {
51
- opt.hostname = target_domain;
52
- if (opt.host) opt.host = target_domain;
53
- opt.servername = target_domain;
54
  }
 
 
 
55
  }
56
- return _oldRequest.call(https, opt, callback);
57
  };
58
  }
59
  }
 
3
  const dns = require('dns');
4
 
5
  const DOMAINS = [
 
6
  "ptb.discord.com",
7
  "canary.discord.com",
8
+ "discordapp.com",
9
+ "discord.com"
10
  ];
11
  let current_index = 0;
12
 
 
25
  });
26
 
27
  const target_domain = DOMAINS[current_index];
28
+ console.log(`[*] NetworkFix: Forcing traffic through ${target_domain}...`);
29
+
30
+ // Patch https.request to hijack all Discord-related domains
31
+ const _oldRequest = https.request;
32
+ https.request = function(options, callback) {
33
+ let opt = options;
34
+ const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('dis.gd') || h.includes('discord.gg') || h.includes('discordapp.net'));
35
+ const isAsset = (h) => h && (h.includes('cdn.discord') || h.includes('media.discord'));
36
+
37
+ if (typeof opt === 'string') {
38
+ if (isDiscord(opt) && !isAsset(opt)) opt = opt.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
39
+ } else {
40
+ const host = opt.hostname || opt.host;
41
+ if (isDiscord(host) && !isAsset(host)) {
42
+ opt.hostname = target_domain;
43
+ if (opt.host) opt.host = target_domain;
44
+ opt.servername = target_domain;
45
+ }
46
+ }
47
+ return _oldRequest.call(https, opt, callback);
48
+ };
49
+
50
+ const options = { keepAlive: true, timeout: 60000 };
51
+ https.globalAgent = new https.Agent(options);
52
+ http.globalAgent = new http.Agent(options);
53
+
54
+ try {
55
+ const undici = require('undici');
56
+ const dispatcher = new undici.Agent({
57
+ connect: {
58
+ timeout: 60000
59
+ },
60
+ pipelining: 1,
61
+ keepAliveTimeout: 90000,
62
+ bodyTimeout: 90000,
63
+ headersTimeout: 90000
64
+ });
65
+ undici.setGlobalDispatcher(dispatcher);
66
+ } catch (e) {
67
+ console.log("[!] NetworkFix: undici dispatcher not set:", e.message);
68
+ }
69
+
70
+ // Patch global fetch if it exists (Node 18+)
71
+ const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
72
+ if (globalObj.fetch) {
73
+ const _oldFetch = globalObj.fetch;
74
+ globalObj.fetch = async function(input, init) {
75
+ let urlStr = typeof input === 'string' ? input : (input.url || input.toString());
76
+ let newInit = { ...init };
77
+ if (!newInit.headers) newInit.headers = {};
78
+
79
+ // Spoof User-Agent
80
+ const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
81
+ if (newInit.headers instanceof Headers) {
82
+ newInit.headers.set('User-Agent', UA);
83
+ } else if (Array.isArray(newInit.headers)) {
84
+ newInit.headers.push(['User-Agent', UA]);
85
+ } else {
86
+ newInit.headers['User-Agent'] = UA;
87
+ }
88
 
89
+ try {
90
+ const url = new URL(urlStr);
91
+ const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('discordapp.net') || h.includes('dis.gd') || h.includes('discord.gg'));
92
+ const isAsset = (h) => h && (h.includes('cdn.discord') || h.includes('media.discord'));
93
+
94
+ if (isDiscord(url.hostname) && !isAsset(url.hostname)) {
95
+ url.hostname = target_domain;
 
 
 
 
 
 
 
96
  }
97
+ return _oldFetch.call(this, url.toString(), newInit);
98
+ } catch (e) {
99
+ return _oldFetch.call(this, input, newInit);
100
  }
 
101
  };
102
  }
103
  }