Brozy123 commited on
Commit
263e595
·
verified ·
1 Parent(s): d641279

Update network_fix.js

Browse files
Files changed (1) hide show
  1. network_fix.js +37 -40
network_fix.js CHANGED
@@ -3,62 +3,72 @@ const http = require('http');
3
  const dns = require('dns');
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;
26
- const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('dis.gd') || h.includes('discord.gg') || h.includes('discordapp.net'));
27
- const isAsset = (h) => h && (h.includes('cdn.discord') || h.includes('media.discord'));
28
 
29
- if (typeof opt === 'string') {
30
- if (isDiscord(opt) && !isAsset(opt)) opt = opt.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
31
- } else {
32
- const host = opt.hostname || opt.host;
33
- if (isDiscord(host) && !isAsset(host)) {
34
  opt.hostname = target_domain;
35
  if (opt.host) opt.host = target_domain;
36
  opt.servername = target_domain;
 
 
37
  }
38
  }
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 });
46
  const dispatcher = new undici.Agent({
47
  connect: (opts, cb) => {
48
- const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('dis.gd') || h.includes('discord.gg') || h.includes('discordapp.net'));
49
- const isAsset = (h) => h && (h.includes('cdn.discord') || h.includes('media.discord'));
50
-
51
  let targetOpts = { ...opts };
52
- if (isDiscord(opts.hostname) && !isAsset(opts.hostname)) {
53
  targetOpts.hostname = target_domain;
54
  targetOpts.servername = target_domain;
55
  }
56
  return connector(targetOpts, cb);
57
  },
58
  pipelining: 1,
59
- keepAliveTimeout: 90000,
60
- bodyTimeout: 90000,
61
- headersTimeout: 90000
62
  });
63
  undici.setGlobalDispatcher(dispatcher);
64
  } catch (e) {}
@@ -70,13 +80,11 @@ function applyAdvancedFixes() {
70
  globalObj.fetch = async function(input, init) {
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);
@@ -86,19 +94,10 @@ function applyAdvancedFixes() {
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() {
@@ -106,8 +105,6 @@ function rotateEndpoint() {
106
  applyAdvancedFixes();
107
  }
108
 
109
- function getTargetDomain() {
110
- return DOMAINS[current_index];
111
- }
112
 
113
  module.exports = { applyAdvancedFixes, rotateEndpoint, getTargetDomain };
 
3
  const dns = require('dns');
4
 
5
  const DOMAINS = [
 
 
6
  "ptb.discord.com",
7
+ "discordapp.com",
8
  "canary.discord.com",
9
  "discord.com"
10
  ];
11
  let current_index = 0;
12
 
13
  /**
14
+ * Extreme Stealth Network Fix.
15
+ * Spoofs browser fingerprints to bypass Cloudflare 403s.
16
  */
17
  function applyAdvancedFixes() {
18
  const target_domain = DOMAINS[current_index];
19
+ console.log(`[*] NetworkFix: Using Stealth Mode via ${target_domain}...`);
20
+
21
+ const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36';
22
+ const STEALTH_HEADERS = {
23
+ 'User-Agent': UA,
24
+ 'Accept': '*/*',
25
+ 'Accept-Language': 'en-US,en;q=0.9',
26
+ 'Cache-Control': 'no-cache',
27
+ 'Pragma': 'no-cache',
28
+ 'Sec-Ch-Ua': '"Not A(Brand";v="99", "Google Chrome";v="121", "Chromium";v="121"',
29
+ 'Sec-Ch-Ua-Mobile': '?0',
30
+ 'Sec-Ch-Ua-Platform': '"Windows"',
31
+ 'Sec-Fetch-Dest': 'empty',
32
+ 'Sec-Fetch-Mode': 'cors',
33
+ 'Sec-Fetch-Site': 'same-origin'
34
+ };
35
 
36
+ // 1. Patch https.request
37
  const _oldRequest = https.request;
38
  https.request = function(options, callback) {
39
  let opt = options;
40
+ const host = typeof opt === 'string' ? opt : (opt.hostname || opt.host);
41
+ const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('dis.gd') || h.includes('discord.gg'));
42
 
43
+ if (isDiscord(host)) {
44
+ if (typeof opt === 'string') {
45
+ opt = opt.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
46
+ } else {
 
47
  opt.hostname = target_domain;
48
  if (opt.host) opt.host = target_domain;
49
  opt.servername = target_domain;
50
+ if (!opt.headers) opt.headers = {};
51
+ Object.assign(opt.headers, STEALTH_HEADERS);
52
  }
53
  }
54
  return _oldRequest.call(https, opt, callback);
55
  };
56
 
57
+ // 2. Patch undici
58
  try {
59
  const undici = require('undici');
60
  const connector = undici.buildConnector({ timeout: 60000 });
61
  const dispatcher = new undici.Agent({
62
  connect: (opts, cb) => {
 
 
 
63
  let targetOpts = { ...opts };
64
+ if (opts.hostname.includes('discord')) {
65
  targetOpts.hostname = target_domain;
66
  targetOpts.servername = target_domain;
67
  }
68
  return connector(targetOpts, cb);
69
  },
70
  pipelining: 1,
71
+ keepAliveTimeout: 90000
 
 
72
  });
73
  undici.setGlobalDispatcher(dispatcher);
74
  } catch (e) {}
 
80
  globalObj.fetch = async function(input, init) {
81
  let urlStr = typeof input === 'string' ? input : (input.url || input.toString());
82
  let newInit = { ...init };
83
+ newInit.headers = { ...(init?.headers || {}), ...STEALTH_HEADERS };
 
84
 
85
  try {
86
  const url = new URL(urlStr);
87
+ if (url.hostname.includes('discord')) {
 
88
  url.hostname = target_domain;
89
  }
90
  return _oldFetch.call(this, url.toString(), newInit);
 
94
  };
95
  }
96
 
97
+ // Diagnostics
 
 
98
  globalObj.fetch && globalObj.fetch("https://discord.com/api/v10/gateway")
99
+ .then(r => console.log(`[*] Stealth Check: ${target_domain} -> ${r.status}`))
100
+ .catch(e => console.log(`[!] Stealth Check: FAIL (${e.message})`));
 
 
 
 
 
 
 
101
  }
102
 
103
  function rotateEndpoint() {
 
105
  applyAdvancedFixes();
106
  }
107
 
108
+ function getTargetDomain() { return DOMAINS[current_index]; }
 
 
109
 
110
  module.exports = { applyAdvancedFixes, rotateEndpoint, getTargetDomain };