Untitled conversation
- User
const execSync = require('child_process').execSync; const checkAndInstall = (pkg) => { try { require.resolve(pkg); console.log(`Package "${pkg}" is already installed.`); } catch (e) { console.log(`Installing package "${pkg}"...`); execSync(`npm install ${pkg}`, { stdio: 'inherit' }); console.log(`Package "${pkg}" installed.`); } }; const packages = [ 'https', 'http-proxy', 'url', 'path', 'fs', 'os', 'express', 'body-parser', 'cors', 'axios', 'geoip-lite', 'child_process', 'dgram', 'express-basic-auth', 'os-utils', 'node-os-utils', 'gradient-string', 'helmet', 'express-rate-limit' ]; packages.forEach(checkAndInstall); (async () => { const https = require('https'); const httpProxy = require('http-proxy'); const url = require('url'); const path = require('path'); const fs = require('fs'); const os = require('os'); const express = require('express'); const bodyParser = require('body-parser'); const cors = require('cors'); const { EventEmitter } = require('events'); const axios = require('axios'); const geoip = require('geoip-lite'); const exec = require('child_process').exec; const { spawn } = require('child_process'); const dgram = require('dgram'); const basicAuth = require('express-basic-auth'); const osu = require('os-utils'); const { netstat } = require('node-os-utils'); const mem = require('node-os-utils').mem; const gradient = (await import('gradient-string')).default; const helmet = require('helmet'); const keepAliveAgent = new https.Agent({ keepAlive: true, maxSockets: 100, maxFreeSockets: 10, }); axios.defaults.httpsAgent = keepAliveAgent; let logMessages = []; const originalLog = console.log; console.log = (...args) => { originalLog(...args); logMessages.push(args.join(' ')); }; const synFloodTracker = {}; const MAX_SYN_REQUESTS = 10; const SYN_BLOCK_TIME_MS = 60000; // Rate Limiting Configurations const rateLimitConfigurations = {}; const MAX_REQUESTS_PER_MINUTE = 100; const BLOCK_TIME_MS = 60000; // DNS attack prevention configurations const dnsWhitelist = ['8.8.8.8', '1.1.1.1']; const MAX_DNS_REQUESTS_PER_MINUTE = 50; const dnsRateLimitConfigurations = {}; // UDP Rate Limiting Configurations const udpRateLimitConfigurations = {}; const MAX_UDP_REQUESTS_PER_MINUTE = 100; const UDP_BLOCK_TIME_MS = 60000; // Network Usage Limiting Configurations const networkUsage = {}; const MAX_BYTES_PER_MINUTE = 1024 * 1024; const NETWORK_BLOCK_TIME_MS = 60000; // Cloud Server IP Ranges const cloudServerIpRanges = ['35.', '52.', '169.', '198.', '199.', '200.', '216.', '47.']; // Path to configuration file const configPath = path.resolve(__dirname, './config/main.json'); // Read configuration from file const readConfig = () => { try { const data = fs.readFileSync(configPath, 'utf8'); const config = JSON.parse(data); if (!config.allowedCountries) { config.allowedCountries = []; } return config; } catch (err) { console.error(gradient.morning('Error reading main.json:'), err); return { allowedCountries: [] }; } }; // Write configuration to file const writeConfig = (config) => { try { fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf8'); console.log(gradient.morning('Configuration updated.')); console.clear(); } catch (err) { console.error(gradient.morning('Error writing to Config:'), err); } }; let config = readConfig(); // Initial configuration load const configApp = express(); const CONFIG_PORT = 6969; const port = process.argv[2] || 443; // Declare port here for global access // Use Helmet for security configApp.use(helmet()); // Middleware configApp.set('view engine', 'ejs'); configApp.use(bodyParser.urlencoded({ extended: true })); configApp.use(express.static('public')); // Authentication Middleware configApp.use('/config', basicAuth({ users: { [config.username]: config.password }, challenge: true, realm: 'Config Area' })); // Configuration Route configApp.get('/config', (req, res) => { config = readConfig(); res.render('config', { config }); }); // Process Configuration Changes configApp.post('/config', (req, res) => { const { ip, port, loginurl, cdn, username, password, countries, icmpBlock } = req.body; const newConfig = { ip, port: parseInt(port), loginurl, cdn, username, password, allowedCountries: Array.isArray(countries) ? countries : (countries ? [countries] : []), icmpBlock: icmpBlock === 'on' }; writeConfig(newConfig); applyICMPSettings(newConfig.icmpBlock); // Apply the ICMP settings res.redirect('/config'); }); configApp.get('/logs', (req, res) => { res.json({ logs: logMessages }); }); // Stats Endpoint configApp.get('/stats', async (req, res) => { try { const freeMemory = os.freemem(); const totalMemory = os.totalmem(); const usedMemory = totalMemory - freeMemory; const memoryUsagePercent = ((usedMemory) / totalMemory) * 100; osu.cpuUsage(async (cpuPercentage) => { const network = await netstat.inOut(); res.json({ memoryUsage: { free: freeMemory, total: totalMemory, usedPercent: memoryUsagePercent.toFixed(2), }, cpuUsage: (cpuPercentage * 100).toFixed(2), network: { inputMb: network.inputMb, outputMb: network.outputMb } }); }); } catch (error) { console.error('Error fetching system statistics:', error); res.json({ error: 'Unable to fetch system statistics' }); } }); configApp.post('/restart', (req, res) => { console.log('Restarting server...'); res.send('Server restarting...'); process.exit(1); }); const isSynFlood = (ip) => { const now = Date.now(); if (!synFloodTracker[ip]) { synFloodTracker[ip] = { count: 1, timestamp: now }; return false; } const timePassed = now - synFloodTracker[ip].timestamp; if (timePassed > SYN_BLOCK_TIME_MS) { synFloodTracker[ip] = { count: 1, timestamp: now }; return false; } else { synFloodTracker[ip].count++; if (synFloodTracker[ip].count > MAX_SYN_REQUESTS) { console.log(gradient.fruit(`SYN flood detected from IP: ${ip}`)); logBlockedIP(ip, 'SYN Flood'); return true; } } return false; }; // Function to log blocked IPs const logBlockedIP = (ip, protocol = 'TCP') => { fs.appendFile('blocked_ips.log', `${new Date().toISOString()} - Blocked IP: ${ip} [${protocol}]\n`, (err) => { if (err) console.error(gradient.morning('Error logging blocked IP:'), err); }); }; // Function to normalize IP addresses const normalizeIp = (ip) => { if (ip.startsWith("::ffff:")) { return ip.substring(7); } if (ip === "::1") { return "127.0.0.1"; } return ip; }; // Function to check if IP is from cloud/server ranges const isCloudOrServerIp = (ip) => { return cloudServerIpRanges.some((range) => ip.startsWith(range)); }; // Helper function to check GeoIP blocking const isBlockedGeoIp = (ip) => { const geo = geoip.lookup(ip); if (geo && !config.allowedCountries.includes(geo.country)) { return true; } return false; }; // Start UI Server configApp.listen(CONFIG_PORT, () => { // console.log(gradient.cristal('ADMIN DASHBOARD IS ONLINE')); }); // Function to apply ICMP block setting function applyICMPSettings(isBlockEnabled) { try { if (isBlockEnabled) { blockICMP(); } else { unblockICMP(); } } catch (error) { console.error('Error applying ICMP settings:', error.message); } } // Logic to Block/Unblock ICMP function blockICMP() { console.log('Enabling ICMP blocking.'); execSync('netsh advfirewall firewall add rule name="Block ICMP" protocol=icmpv4:8,any dir=in action=block', { shell: true }); } function unblockICMP() { console.log('Disabling ICMP blocking.'); execSync('netsh advfirewall firewall delete rule name="Block ICMP"', { shell: true }); } // Start Server Function const startServer = async () => { const proxy = httpProxy.createProxyServer({}); const pk = fs.readFileSync(path.join(__dirname, 'server.key')); const pc = fs.readFileSync(path.join(__dirname, 'server.crt')); const optss = { key: pk, cert: pc }; const trustedIPs = ['127.0.0.1']; EventEmitter.defaultMaxListeners = 100; const packet = `server|${config.ip}\nport|${config.port}\ntype|1\n#maint|Server is currently initializing or re-syncing with sub servers. Please try again in a minute.\n\n\nloginurl|${config.loginurl}\nbeta_server|127.0.0.1\nbeta_port|17091\nbeta_type|1\nbeta2_server|127.0.0.1\nbeta2_port|17099\nbeta2_type|1\nmeta|${Math.floor(Date.now() / 1000)}\nRTENDMARKERBS1001`; const server = https.createServer(optss, function (req, res) { let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; const normalizedIp = normalizeIp(ip); const hostHeader = req.headers.host; // Set keepAliveTimeout and headersTimeout server.keepAliveTimeout = 30 * 1000; server.headersTimeout = 30 * 1000; console.log(gradient.passion(`[REQUEST] IP: ${normalizedIp}`)); if (isSynFlood(ip)) { console.log(gradient.fruit(`SYN flood detected from IP: ${normalizedIp}`)); logBlockedIP(normalizedIp, 'SYN Flood'); req.socket.end(); req.socket.destroy(); return; } // Rate Limiting Logic if (!rateLimitConfigurations[normalizedIp]) { rateLimitConfigurations[normalizedIp] = { count: 1, timestamp: Date.now() }; } else { const currentTime = Date.now(); const timePassed = currentTime - rateLimitConfigurations[normalizedIp].timestamp; // Reset the count if more than 1 minute has passed if (timePassed > BLOCK_TIME_MS) { rateLimitConfigurations[normalizedIp] = { count: 1, timestamp: currentTime }; } else { rateLimitConfigurations[normalizedIp].count++; } // Check if the limit is reached if (rateLimitConfigurations[normalizedIp].count > MAX_REQUESTS_PER_MINUTE) { console.log(gradient.summer(`Rate limit exceeded for IP: ${normalizedIp}`)); logBlockedIP(normalizedIp, 'TCP'); res.statusCode = 429; res.end('Too many requests. Your connection is being throttled.'); return; } } // DNS attack protection const isSuspiciousDNSRequest = (ip, requestUrl) => { if (!requestUrl.toLowerCase().includes('dns')) return false; if (!dnsWhitelist.includes(ip)) { const now = Date.now(); if (!dnsRateLimitConfigurations[ip]) { dnsRateLimitConfigurations[ip] = { count: 1, timestamp: now }; } else { const timePassed = now - dnsRateLimitConfigurations[ip].timestamp; if (timePassed > BLOCK_TIME_MS) { dnsRateLimitConfigurations[ip] = { count: 1, timestamp: now }; } else { dnsRateLimitConfigurations[ip].count++; } if (dnsRateLimitConfigurations[ip].count > MAX_DNS_REQUESTS_PER_MINUTE) { return true; } } } return false; }; if (isSuspiciousDNSRequest(normalizedIp, req.url)) { console.log(gradient.summer(`DNS DDoS detected from IP: ${normalizedIp}`)); logBlockedIP(normalizedIp, 'TCP-DNS'); res.statusCode = 403; res.end('Forbidden: DNS DDoS attack detected.'); return; } // Network Usage Limiting for TCP const requestBytes = Buffer.byteLength(req.url); const isNetworkUsageLimited = (ip, bytes) => { const now = Date.now(); if (!networkUsage[ip]) { networkUsage[ip] = { sent: bytes, received: bytes, timestamp: now }; return false; } else { const timePassed = now - networkUsage[ip].timestamp; if (timePassed > NETWORK_BLOCK_TIME_MS) { networkUsage[ip] = { sent: bytes, received: bytes, timestamp: now }; return false; } else { networkUsage[ip].sent += bytes; networkUsage[ip].received += bytes; if (networkUsage[ip].sent > MAX_BYTES_PER_MINUTE || networkUsage[ip].received > MAX_BYTES_PER_MINUTE) { return true; } } } return false; }; if (isNetworkUsageLimited(normalizedIp, requestBytes)) { console.log(gradient.summer(`Network usage limit exceeded for IP: ${normalizedIp} (TCP)`)); logBlockedIP(normalizedIp, 'TCP-NETWORK'); res.statusCode = 429; res.end('Too many requests. Your connection is being throttled.'); return; } // Check for cloud or server IP range if (!trustedIPs.includes(normalizedIp) && isCloudOrServerIp(normalizedIp)) { console.log(gradient.summer(`Blocking cloud/server IP: ${normalizedIp}`)); logBlockedIP(normalizedIp, 'TCP-Cloud'); res.statusCode = 403; res.end('Forbidden: Access from cloud/server IP is blocked.'); return; } // Check for GeoIP block if (isBlockedGeoIp(normalizedIp)) { console.log(gradient.summer(`Blocking access from IP: ${normalizedIp} (GeoIP Block)`)); logBlockedIP(normalizedIp, 'TCP-GeoIP'); res.statusCode = 403; res.end('Forbidden: Access from your location is blocked.'); return; } const parsedUrl = url.parse(req.url); const pathname = `.${parsedUrl.pathname}`; const ext = path.parse(pathname).ext; console.log(gradient.atlas(`Connection Request from: ${normalizedIp} URL: ${req.url} Method: ${req.method}`)); const map = { '.ico': 'image/x-icon', '.html': 'text/html', '.js': 'text/javascript', '.json': 'application/json', '.css': 'text/css', '.png': 'image/png', '.jpg': 'image/jpeg', '.wav': 'audio/wav', '.mp3': 'audio/mpeg', '.svg': 'image/svg+xml', '.pdf': 'application/pdf', '.doc': 'application/msword' }; const allowedUserAgents = [ 'UbiServices_SDK_2022.Release.9_PC64_ansi_static', 'UbiServices_SDK_2022.Release.9_PC32_ansi_static', 'UbiServices_SDK_2022.Release.9_ANDROID64_static', 'UbiServices_SDK_2022.Release.9_ANDROID32_static', 'UbiServices_SDK_2022.Release.9_IOS64', 'UbiServices_SDK_2022.Release.9_IOS32', 'UbiServices_SDK_2022.Release.9_MAC64', 'UbiServices_SDK_2022.Release.9_MAC32', ]; const IdentitasHost = [ 'www.growtopia1.com', 'www.growtopia2.com' ]; const userAgent = req.headers['user-agent']; // Handle /growtopia/server_data.php if (req.url === "/growtopia/server_data.php" && req.method === 'POST') { if (!IdentitasHost.includes(hostHeader) || !allowedUserAgents.includes(userAgent)) { console.log(gradient.summer(`Anomaly : ${req.url}`)); res.statusCode = 200; res.end(` server|${normalizedIp} port|${Math.floor(Date.now() / 69)} type|1 #maint|Server is currently initializing or re-syncing with sub servers. Please try again in a minute. loginurl|http-king.com beta_server|${normalizedIp} beta_port|${Math.floor(Date.now() / 69)} beta_type|1 beta2_server|${normalizedIp} beta2_port|${Math.floor(Date.now() / 69)} beta2_type|1 meta|69-SCP-PROTECTION RTENDMARKERBS1001 `); return; } let body = ''; req.on('data', chunk => { body += chunk.toString(); }); req.on('end', () => { const params = new URLSearchParams(body); const version = params.get('version'); const platform = params.get('platform'); const protocol = params.get('protocol'); if (version !== '4.69' || platform !== '0' || protocol !== '210') { console.log(gradient.summer('Anomaly [PARAM]')); res.statusCode = 200; res.end(` server|${normalizedIp} port|${Math.floor(Date.now() / 69)} type|1 #maint|Server is currently initializing or re-syncing with sub servers. Please try again in a minute. loginurl|http-king.com beta_server|${normalizedIp} beta_port|${Math.floor(Date.now() / 69)} beta_type|1 beta2_server|${normalizedIp} beta2_port|${Math.floor(Date.now() / 69)} beta2_type|1 meta|69-SCP-PROTECTION RTENDMARKERBS1001 `); return; } console.log(gradient.atlas(`Secure request from IP: ${normalizedIp} with valid [PARAM]`)); res.write(packet, function (err) { if (err) console.log(gradient.summer(err)); }); res.end(); }); return; // Ensure exiting after handling /server_data.php } // Handle /cache and /0098 if (req.url.indexOf("/cache") !== -1 || req.url.indexOf("/0098") !== -1) { if (req.method !== 'GET' || !allowedUserAgents.includes(userAgent)) { console.log(gradient.summer(`Blocked: Invalid method or User-Agent for ${req.url}`)); // res.statusCode = 200; //res.end('Hello world'); req.socket.destroy(); return; } console.log(gradient.atlas(`[CACHE-SPEED] Connection from: ${normalizedIp}\n Downloading assets: ${req.url}`)); fs.exists(pathname, function (exist) { if (!exist) { res.statusCode = 301; res.setHeader('Location', `https://ubistatic-a.akamaihd.net/${config.cdn}${req.url}`); res.end(); return; } fs.readFile(pathname, function (err, data) { if (err) { res.statusCode = 404; res.end(`error`); } else { res.setHeader('Content-type', map[ext] || 'text/plain'); res.end(data); } }); }); return; } // Block all other requests console.log(gradient.summer(`🛡 [PROTECTION] Blocked request: ${req.method} ${req.url} from IP: ${normalizedIp}`)); logBlockedIP(normalizedIp, 'TCP-Other'); //res.statusCode = 403; req.socket.destroy(); //res.end('Hello world'); }); server.listen(port, () => { console.log(gradient.cristal(`Server is running on port ${port}`)); }); // UDP Server Setup const udpServer = dgram.createSocket('udp4'); const UDP_PORT = 53; udpServer.on('error', (err) => { console.error(`UDP server error:\n${err.stack}`); udpServer.close(); }); udpServer.on('message', (msg, rinfo) => { const ip = rinfo.address; const normalizedIp = normalizeIp(ip); console.log(gradient.fruit(`UDP request from IP: ${normalizedIp}, Port: ${rinfo.port}`)); // UDP Rate Limiting const isUdpRateLimited = (ip) => { const now = Date.now(); if (!udpRateLimitConfigurations[ip]) { udpRateLimitConfigurations[ip] = { count: 1, timestamp: now }; return false; } else { const timePassed = now - udpRateLimitConfigurations[ip].timestamp; if (timePassed > UDP_BLOCK_TIME_MS) { udpRateLimitConfigurations[ip] = { count: 1, timestamp: now }; return false; } else { udpRateLimitConfigurations[ip].count++; if (udpRateLimitConfigurations[ip].count > MAX_UDP_REQUESTS_PER_MINUTE) { return true; } } } return false; }; if (isUdpRateLimited(normalizedIp)) { console.log(gradient.summer(`UDP Rate limit exceeded for IP: ${normalizedIp}`)); logBlockedIP(normalizedIp, 'UDP'); return; } // GeoIP Blocking if (isBlockedGeoIp(normalizedIp)) { console.log(gradient.summer(`Blocking UDP access from IP: ${normalizedIp} (GeoIP Block)`)); logBlockedIP(normalizedIp, 'UDP-GeoIP'); return; } // Network Usage Limiting for UDP const messageBytes = msg.length; if (isNetworkUsageLimited(normalizedIp, messageBytes)) { console.log(gradient.summer(`Network usage limit exceeded for IP: ${normalizedIp} (UDP)`)); logBlockedIP(normalizedIp, 'UDP-NETWORK'); return; } // DNS handling logic const externalDns = '8.8.8.8'; const externalDnsPort = 53; const externalClient = dgram.createSocket('udp4'); externalClient.send(msg, 0, msg.length, externalDnsPort, externalDns, (error) => { if (error) { console.error(`Error forwarding UDP request: ${error}`); externalClient.close(); } }); externalClient.on('message', (response) => { udpServer.send(response, 0, response.length, rinfo.port, rinfo.address, (err) => { if (err) { console.error(`Error sending UDP response: ${err}`); } externalClient.close(); }); }); // Timeouts to prevent hanging externalClient.on('error', (err) => { console.error(`External DNS client error: ${err}`); externalClient.close(); }); // Set a timeout for the external DNS response externalClient.setTimeout(5000, () => { console.error(`External DNS request timed out for IP: ${normalizedIp}`); externalClient.close(); }); }); udpServer.on('listening', () => { const address = udpServer.address(); console.log(gradient.morning(`UDP Server listening on ${address.address}:${address.port}`)); }); udpServer.bind(UDP_PORT); }; applyICMPSettings(config.icmpBlock); startServer(); configApp.post('/shutdown', (req, res) => { res.send('Server is shutting down...'); shutdown(); }); const shutdown = () => { console.log('Shutting down the server...'); // Stop the server from accepting new connections server.close(() => { console.log('HTTP server closed.'); // Close the UDP server udpServer.close(() => { console.log('UDP server closed.'); // Exit the process process.exit(0); }); }); // Ensure shutdown if connections remain setTimeout(() => { console.error('Forced shutdown due to open connections.'); process.exit(1); }, 5000).unref(); }; // Capture abort signals process.on('SIGINT', shutdown); process.on('SIGTERM', shutdown); console.log(''); console.log(gradient.vice('========================================================')); console.log(gradient.vice(`- CONFIGURATION LOADS : `)); console.log(gradient.vice(`[🎮] Login URL : ${config.loginurl}`)); console.log(gradient.vice(`[🔰] HTTP(s) Port ${port}`)); console.log(gradient.vice(`[@] ANTI-SCAN : ENABLED`)); console.log(gradient.vice(`[@] OPERATION SYSTEM : WINDOWS`)); console.log(gradient.vice(`[@] HTTP KING VERSION : 4.0.0`)); console.log(gradient.cristal(`[🥇] SUBSCRIPTION : AVIATUM PREMIUM`)); console.log(gradient.cristal(`[✅] LAST HTTP UPDATE : 21/10/2024`)); console.log(gradient.passion(`[💻] ADMIN DASHBOARD : http://localhost:${CONFIG_PORT}/config`)); console.log(gradient.vice('========================================================')); console.log(''); console.log(gradient.pastel(` ░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓██████▓▒░ ░▒▓█▓▒▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒▒▓███▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓████████▓▒░ ░▒▓██▓▒░ ░▒▓█▓▒░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░ `)); })(); - Assistant
- User
add it to my code, give me the snippet where to put the code
- Assistant
- User
when i add the anti debug and i run "node script.js" it says im debugging it but im not
- Assistant
- User
when i run node script.js it says on-production environment detected. Exiting...
- Assistant
The message "Non-production environment detected. Exiting..." appears because the script checks the
NODE_ENVenvironment variable and expects it to be set to "production". If it's not, the check will terminate the script. - User
can you make the anti debug more easy to use and secured
- Assistant