Beispiel #1
0
def get_implant_type_prompt_prefix(implant_id):
    if "," in str(implant_id):
        return ""
    implant = get_hostdetails(implant_id)
    pivot = implant[15]
    pivot_original = pivot
    if pivot_original.startswith("PS"):
        pivot = "PS"
    elif pivot_original.startswith("C#"):
        pivot = "C#"
    elif pivot_original.startswith("Python"):
        pivot = "PY"
    if "Daisy" in pivot_original:
        pivot = pivot + ";D"
    if "Proxy" in pivot_original:
        pivot = pivot + ";P"
    return pivot
def commandloop(implant_id, user):
    while (True):
        try:
            implant_id_orig = implant_id
            t = tabCompleter()
            t.createListCompleter(COMMANDS)
            readline.set_completer_delims('\t')
            readline.parse_and_bind("tab: complete")
            readline.set_completer(t.listCompleter)
            if ("-" in implant_id) or ("all" in implant_id) or (","
                                                                in implant_id):
                print(Colours.GREEN)
                command = input("%s> " % (implant_id))
            else:
                hostname = get_hostdetails(implant_id)
                if hostname[15] == 'Python':
                    t.createListCompleter(UXCOMMANDS)
                    readline.set_completer_delims('\t')
                    readline.parse_and_bind("tab: complete")
                    readline.set_completer(t.listCompleter)
                if hostname[15] == 'C#':
                    t.createListCompleter(SHARPCOMMANDS)
                    readline.set_completer_delims('\t')
                    readline.parse_and_bind("tab: complete")
                    readline.set_completer(t.listCompleter)
                print(Colours.GREEN)
                print("%s\\%s @ %s (PID:%s)" %
                      (hostname[11], hostname[2], hostname[3], hostname[8]))
                command = input("%s> " % (implant_id))

            # if "all" run through all implants get_implants()
            if implant_id == "all":
                if command == "back":
                    startup(user)
                implant_split = get_implants()
                if implant_split:
                    for implant_id in implant_split:
                        runcommand(command, implant_id[1])

            # if "seperated list" against single uri
            elif "," in implant_id:
                implant_split = implant_id.split(",")
                for implant_id in implant_split:
                    implant_id = get_randomuri(implant_id)
                    runcommand(command, implant_id)

            # if "range" against single uri
            elif "-" in implant_id:
                implant_split = implant_id.split("-")
                for implant_id in range(int(implant_split[0]),
                                        int(implant_split[1]) + 1):
                    try:
                        implant_id = get_randomuri(implant_id)
                        runcommand(command, implant_id)
                    except Exception:
                        print("Unknown ImplantID")

            # else run against single uri
            else:
                implant_id = get_randomuri(implant_id)
                runcommand(command, implant_id)

            # then run back around
            commandloop(
                implant_id_orig, user
            )  # is this required for a while loop? looks like it would lead to a stackoverflow anyway?

        except Exception:
            print(Colours.RED)
            print(
                "Error running against the selected implant ID, ensure you have typed the correct information"
            )
            print(Colours.END)
            # traceback.print_exc()
            # print ("Error: %s" % e)
            time.sleep(1)
            startup(user, user)
Beispiel #3
0
def commandloop(implant_id, user):
    while (True):
        try:
            style = Style.from_dict({
                '': '#80d130',
            })
            session = PromptSession(history=FileHistory('%s/.implant-history' %
                                                        ROOTDIR),
                                    auto_suggest=AutoSuggestFromHistory(),
                                    style=style)
            implant_id_orig = implant_id
            if ("-" in implant_id) or ("all" in implant_id) or (","
                                                                in implant_id):
                print(Colours.GREEN)
                prompt_commands = COMMANDS
                command = session.prompt("%s> " % implant_id,
                                         completer=FirstWordFuzzyWordCompleter(
                                             prompt_commands, WORD=True))
            else:
                hostname = get_hostdetails(implant_id)
                if not hostname:
                    startup(
                        user,
                        "Unrecognised implant id or command: %s" % implant_id)
                prompt_commands = COMMANDS
                if hostname[15] == 'Python':
                    prompt_commands = UXCOMMANDS
                if hostname[15] == 'C#':
                    prompt_commands = SHARPCOMMANDS
                print(Colours.GREEN)
                print("%s\\%s @ %s (PID:%s)" %
                      (hostname[11], hostname[2], hostname[3], hostname[8]))
                command = session.prompt(
                    "%s %s> " %
                    (get_implant_type_prompt_prefix(implant_id), implant_id),
                    completer=FirstWordFuzzyWordCompleter(prompt_commands,
                                                          WORD=True))

            # if "all" run through all implants get_implants()
            if implant_id == "all":
                if command == "back":
                    startup(user)
                allcommands = command
                if "\n" in command:
                    ri = input(
                        "Do you want to run commands seperately? (Y/n) ")
                implant_split = get_implants()
                if implant_split:
                    for implant_id in implant_split:
                        # if "\n" in command run each command individually or ask the question if thats what they want to do
                        if "\n" in allcommands:
                            if ri.lower() == "y" or ri == "":
                                commands = allcommands.split('\n')
                                for command in commands:
                                    runcommand(command, implant_id[1],
                                               implant_id_orig)
                            else:
                                runcommand(command, implant_id[1],
                                           implant_id_orig)
                        else:
                            runcommand(command, implant_id[1], implant_id_orig)

            # if "seperated list" against single uri
            elif "," in implant_id:
                allcommands = command
                if "\n" in command:
                    ri = input(
                        "Do you want to run commands seperately? (Y/n) ")
                implant_split = implant_id.split(",")
                for implant_id in implant_split:
                    implant_id = get_randomuri(implant_id)
                    # if "\n" in command run each command individually or ask the question if thats what they want to do
                    if "\n" in allcommands:
                        if ri.lower() == "y" or ri == "":
                            commands = allcommands.split('\n')
                            for command in commands:
                                runcommand(command, implant_id,
                                           implant_id_orig)
                        else:
                            runcommand(command, implant_id, implant_id_orig)
                    else:
                        runcommand(command, implant_id, implant_id_orig)

            # if "range" against single uri
            elif "-" in implant_id:
                allcommands = command
                if "\n" in command:
                    ri = input(
                        "Do you want to run commands seperately? (Y/n) ")
                implant_split = implant_id.split("-")
                for implant_id in range(int(implant_split[0]),
                                        int(implant_split[1]) + 1):
                    try:
                        implant_id = get_randomuri(implant_id)
                        # if "\n" in command run each command individually or ask the question if thats what they want to do
                        if "\n" in allcommands:
                            if ri.lower() == "y" or ri == "":
                                commands = allcommands.split('\n')
                                for command in commands:
                                    runcommand(command, implant_id,
                                               implant_id_orig)
                            else:
                                runcommand(command, implant_id,
                                           implant_id_orig)
                        else:
                            runcommand(command, implant_id, implant_id_orig)
                    except Exception:
                        print("Unknown ImplantID")

            # else run against single uri
            else:
                allcommands = command
                if "\n" in command:
                    ri = input(
                        "Do you want to run commands seperately? (Y/n) ")
                implant_id = get_randomuri(implant_id)
                # if "\n" in command run each command individually or ask the question if thats what they want to do
                if "\n" in allcommands:
                    if ri.lower() == "y" or ri == "":
                        commands = allcommands.split('\n')
                        for command in commands:
                            runcommand(command, implant_id, implant_id_orig)
                    else:
                        runcommand(command, implant_id, implant_id_orig)
                else:
                    runcommand(command, implant_id, implant_id_orig)

            # then run back around
            commandloop(implant_id_orig, user)

        except KeyboardInterrupt:
            commandloop(implant_id_orig, user)
        except EOFError:
            new_c2_message("%s logged off." % user)
            sys.exit(0)
        except Exception as e:
            print(Colours.RED)
            print(
                "Error running against the selected implant ID, ensure you have typed the correct information"
            )
            print(Colours.GREEN)
            traceback.print_exc()
            print("Error: %s" % e)
            time.sleep(1)
            startup(user, user)