Brozy123 commited on
Commit
d641279
·
verified ·
1 Parent(s): 32dd50f

Update network_fix.js

Browse files
Files changed (1) hide show
  1. network_fix.js +25 -48
network_fix.js CHANGED
@@ -4,43 +4,22 @@ const dns = require('dns');
4
 
5
  const DOMAINS = [
6
  "discordapp.com",
7
- "discord.com",
8
  "ptb.discord.com",
9
- "canary.discord.com"
 
10
  ];
11
  let current_index = 0;
12
 
13
  /**
14
- * Minimal Network Fix.
15
- * Attempts direct connection first, then rotates.
16
  */
17
  function applyAdvancedFixes() {
18
- console.log("[*] NetworkFix: Running in Minimal Recovery Mode...");
19
-
20
- // Connectivity Diagnostic
21
- ["google.com", "discord.com", "discordapp.com"].forEach(d => {
22
- dns.resolve4(d, (err, addrs) => {
23
- console.log(`[*] DNS Test: ${d} -> ${err ? 'FAILED (' + err.code + ')' : addrs[0]}`);
24
- });
25
- });
26
-
27
- // WebSocket Test
28
- try {
29
- const WebSocket = require('ws');
30
- const testWs = new WebSocket(`wss://gateway.discord.gg`);
31
- testWs.on('open', () => {
32
- console.log("[*] WS Test: Initialized successfully");
33
- testWs.close();
34
- });
35
- testWs.on('error', (e) => {
36
- console.log(`[!] WS Test: Failed (${e.message})`);
37
- });
38
- } catch (e) {}
39
-
40
  const target_domain = DOMAINS[current_index];
41
  console.log(`[*] NetworkFix: Forcing traffic through ${target_domain}...`);
42
 
43
- // Patch https.request to hijack all Discord-related domains
44
  const _oldRequest = https.request;
45
  https.request = function(options, callback) {
46
  let opt = options;
@@ -60,10 +39,7 @@ function applyAdvancedFixes() {
60
  return _oldRequest.call(https, opt, callback);
61
  };
62
 
63
- const options = { keepAlive: true, timeout: 60000 };
64
- https.globalAgent = new https.Agent(options);
65
- http.globalAgent = new http.Agent(options);
66
-
67
  try {
68
  const undici = require('undici');
69
  const connector = undici.buildConnector({ timeout: 60000 });
@@ -85,11 +61,9 @@ function applyAdvancedFixes() {
85
  headersTimeout: 90000
86
  });
87
  undici.setGlobalDispatcher(dispatcher);
88
- } catch (e) {
89
- console.log("[!] NetworkFix: undici dispatcher not set:", e.message);
90
- }
91
 
92
- // Patch global fetch if it exists (Node 18+)
93
  const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
94
  if (globalObj.fetch) {
95
  const _oldFetch = globalObj.fetch;
@@ -97,23 +71,12 @@ function applyAdvancedFixes() {
97
  let urlStr = typeof input === 'string' ? input : (input.url || input.toString());
98
  let newInit = { ...init };
99
  if (!newInit.headers) newInit.headers = {};
100
-
101
- // Spoof User-Agent
102
- 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';
103
- if (newInit.headers instanceof Headers) {
104
- newInit.headers.set('User-Agent', UA);
105
- } else if (Array.isArray(newInit.headers)) {
106
- newInit.headers.push(['User-Agent', UA]);
107
- } else {
108
- newInit.headers['User-Agent'] = UA;
109
- }
110
 
111
  try {
112
  const url = new URL(urlStr);
113
  const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('discordapp.net') || h.includes('dis.gd') || h.includes('discord.gg'));
114
- const isAsset = (h) => h && (h.includes('cdn.discord') || h.includes('media.discord'));
115
-
116
- if (isDiscord(url.hostname) && !isAsset(url.hostname)) {
117
  url.hostname = target_domain;
118
  }
119
  return _oldFetch.call(this, url.toString(), newInit);
@@ -122,6 +85,20 @@ function applyAdvancedFixes() {
122
  }
123
  };
124
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  }
126
 
127
  function rotateEndpoint() {
 
4
 
5
  const DOMAINS = [
6
  "discordapp.com",
7
+ "discord.gg",
8
  "ptb.discord.com",
9
+ "canary.discord.com",
10
+ "discord.com"
11
  ];
12
  let current_index = 0;
13
 
14
  /**
15
+ * Advanced Network Fix.
16
+ * Handles domain rotation and stealth hijacking.
17
  */
18
  function applyAdvancedFixes() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  const target_domain = DOMAINS[current_index];
20
  console.log(`[*] NetworkFix: Forcing traffic through ${target_domain}...`);
21
 
22
+ // 1. Patch https.request (Legacy/Gateway)
23
  const _oldRequest = https.request;
24
  https.request = function(options, callback) {
25
  let opt = options;
 
39
  return _oldRequest.call(https, opt, callback);
40
  };
41
 
42
+ // 2. Patch undici (Modern REST)
 
 
 
43
  try {
44
  const undici = require('undici');
45
  const connector = undici.buildConnector({ timeout: 60000 });
 
61
  headersTimeout: 90000
62
  });
63
  undici.setGlobalDispatcher(dispatcher);
64
+ } catch (e) {}
 
 
65
 
66
+ // 3. Patch global fetch
67
  const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
68
  if (globalObj.fetch) {
69
  const _oldFetch = globalObj.fetch;
 
71
  let urlStr = typeof input === 'string' ? input : (input.url || input.toString());
72
  let newInit = { ...init };
73
  if (!newInit.headers) newInit.headers = {};
74
+ newInit.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
 
 
 
 
 
 
 
 
 
75
 
76
  try {
77
  const url = new URL(urlStr);
78
  const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('discordapp.net') || h.includes('dis.gd') || h.includes('discord.gg'));
79
+ if (isDiscord(url.hostname)) {
 
 
80
  url.hostname = target_domain;
81
  }
82
  return _oldFetch.call(this, url.toString(), newInit);
 
85
  }
86
  };
87
  }
88
+
89
+ // 4. Run Diagnostics AFTER patches
90
+ dns.resolve4("google.com", (err, addrs) => console.log(`[*] DNS Check: google.com -> ${err ? 'FAIL' : addrs[0]}`));
91
+
92
+ globalObj.fetch && globalObj.fetch("https://discord.com/api/v10/gateway")
93
+ .then(r => console.log(`[*] REST Check: ${target_domain} -> ${r.status}`))
94
+ .catch(e => console.log(`[!] REST Check: ${target_domain} -> FAIL (${e.message})`));
95
+
96
+ try {
97
+ const WebSocket = require('ws');
98
+ const testWs = new WebSocket(`wss://gateway.discord.gg`);
99
+ testWs.on('open', () => { console.log("[*] WS Check: SUCCESS"); testWs.close(); });
100
+ testWs.on('error', (e) => console.log(`[!] WS Check: FAIL (${e.message})`));
101
+ } catch (e) {}
102
  }
103
 
104
  function rotateEndpoint() {