Exemplo n.º 1
0
    def PayloadMenu(self, payload, showTitle=True):
        """
        Main menu for interacting with a specific payload.

        payload = the payload object we're interacting with
        showTitle = whether to show the main Veil title menu

        Returns the output of OutputMenu() (the full path of the source file or compiled .exe)
        """

        comp = completers.PayloadCompleter(self.payload)
        readline.set_completer_delims(' \t\n;')
        readline.parse_and_bind("tab: complete")
        readline.set_completer(comp.complete)

        # show the title if specified
        if showTitle:
            messages.title()

        print " Payload: " + helpers.color(payload.language + "/" +
                                           payload.shortname) + " loaded"

        self.PayloadInfo(payload, showTitle=False, showInfo=False)
        messages.helpmsg(self.payloadCommands, showTitle=False)

        choice = ""
        while choice == "":

            while True:

                choice = raw_input(" [>] Please enter a command: ").strip()

                if choice != "":

                    parts = choice.strip().split()
                    # display help menu for the payload
                    if parts[0] == "info":
                        self.PayloadInfo(payload)
                        choice = ""
                    if parts[0] == "help":
                        if len(parts) > 1:
                            if parts[1] == "crypters" or parts[
                                    1] == "[crypters]":
                                messages.helpCrypters()
                        else:
                            messages.helpmsg(self.payloadCommands)
                        choice = ""
                    # head back to the main menu
                    if parts[0] == "main" or parts[0] == "back":
                        #finished = True
                        return ""
                        #self.MainMenu()
                    if parts[0] == "exit":
                        raise KeyboardInterrupt

                    # Update Veil via git
                    if parts[0] == "update":
                        self.UpdateVeil()

                    # set specific options
                    if parts[0] == "set":

                        # catch the case of no value being supplied
                        if len(parts) == 1:
                            print helpers.color(
                                " [!] ERROR: no value supplied\n",
                                warning=True)

                        else:

                            option = parts[1]
                            value = "".join(parts[2:])

                            #### VALIDATION ####

                            # validate LHOST
                            if option == "LHOST":
                                hostParts = value.split(".")

                                if len(hostParts) > 1:

                                    # if the last chunk is a number, assume it's an IP address
                                    if hostParts[-1].isdigit():
                                        # do a regex IP validation
                                        if not re.match(
                                                r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$",
                                                value):
                                            print helpers.color(
                                                "\n [!] ERROR: Bad IP address specified.\n",
                                                warning=True)
                                        else:
                                            try:
                                                payload.required_options[
                                                    option][0] = value
                                            except KeyError:
                                                print helpers.color(
                                                    "\n [!] ERROR: Specify LHOST value in the following screen.\n",
                                                    warning=True)
                                            except AttributeError:
                                                print helpers.color(
                                                    "\n [!] ERROR: Specify LHOST value in the following screen.\n",
                                                    warning=True)

                                    # assume we've been passed a domain name
                                    else:
                                        if helpers.isValidHostname(value):
                                            pass
                                        else:
                                            print helpers.color(
                                                "\n [!] ERROR: Bad hostname specified.\n",
                                                warning=True)

                                else:
                                    print helpers.color(
                                        "\n [!] ERROR: Bad IP address or hostname specified.\n",
                                        warning=True)

                            # validate LPORT
                            elif option == "LPORT":
                                try:
                                    if int(value) <= 0 or int(value) >= 65535:
                                        print helpers.color(
                                            "\n [!] ERROR: Bad port number specified.\n",
                                            warning=True)
                                    else:
                                        try:
                                            payload.required_options[option][
                                                0] = value
                                        except KeyError:
                                            print helpers.color(
                                                "\n [!] ERROR: Specify LPORT value in the following screen.\n",
                                                warning=True)
                                        except AttributeError:
                                            print helpers.color(
                                                "\n [!] ERROR: Specify LPORT value in the following screen.\n",
                                                warning=True)
                                except ValueError:
                                    print helpers.color(
                                        "\n [!] ERROR: Bad port number specified.\n",
                                        warning=True)

                            # set the specific option value if not validation done
                            else:
                                try:
                                    payload.required_options[option][0] = value
                                except:
                                    print helpers.color(
                                        " [!] ERROR: Invalid value specified.\n",
                                        warning=True)
                                    cmd = ""

                    # generate the payload
                    if parts[0] == "generate":

                        # make sure all required options are filled in first
                        if self.ValidatePayload(payload):

                            #finished = True
                            # actually generate the payload code
                            payloadCode = payload.generate()

                            # ensure we got some code back
                            if payloadCode != "":
                                # call the output menu
                                return self.OutputMenu(payload, payloadCode)

                        else:
                            print helpers.color(
                                "\n [!] WARNING: not all required options filled\n",
                                warning=True)
Exemplo n.º 2
0
    def PayloadMenu(self, payload, showTitle=True, args=None):
        """
        Main menu for interacting with a specific payload.

        payload = the payload object we're interacting with
        showTitle = whether to show the main Veil title menu

        Returns the output of OutputMenu() (the full path of the source file or compiled .exe)
        """

        comp = completers.PayloadCompleter(self.payloadCommands, self.payload)
        readline.set_completer_delims(' \t\n;')
        readline.parse_and_bind("tab: complete")
        readline.set_completer(comp.complete)

        # show the title if specified
        if showTitle:
            if settings.TERMINAL_CLEAR != "false": messages.title()

        # extract the payload class name from the instantiated object
        # YES, I know this is a giant hack :(
        # basically need to find "payloads" in the path name, then build
        # everything as appropriate
        payloadname = "/".join(
            str(
                str(payload.__class__)
                [str(payload.__class__).find("payloads"):]).split(".")
            [0].split("/")[1:])
        print "\n Payload: " + helpers.color(payloadname) + " loaded\n"

        self.PayloadInfo(payload, showTitle=False, showInfo=False)
        messages.helpmsg(self.payloadCommands, showTitle=False)

        choice = ""
        while choice == "":

            while True:

                choice = raw_input(" [%s>>]: " % payloadname).strip()

                if choice != "":

                    parts = choice.strip().split()
                    cmd = parts[0].lower()

                    # display help menu for the payload
                    if cmd == "info":
                        self.PayloadInfo(payload)
                        choice = ""
                    if cmd == "help":
                        messages.helpmsg(self.payloadCommands)
                        choice = ""
                    # head back to the main menu
                    if cmd == "main" or cmd == "back" or cmd == "home":
                        #finished = True
                        return ""
                        #self.MainMenu()
                    if cmd == "exit" or cmd == "end" or cmd == "quit":
                        raise KeyboardInterrupt
                    # Update Veil via git
                    if cmd == "update":
                        self.UpdateVeil()
                    # set specific options
                    if cmd == "set":

                        # catch the case of no value being supplied
                        if len(parts) == 1:
                            print helpers.color(
                                " [!] ERROR: no value supplied\n",
                                warning=True)

                        else:

                            option = parts[1].upper()
                            value = "".join(parts[2:])

                            #### VALIDATION ####

                            # validate LHOST
                            if option == "LHOST":
                                if '.' in value:
                                    hostParts = value.split(".")

                                    if len(hostParts) > 1:

                                        # if the last chunk is a number, assume it's an IP address
                                        if hostParts[-1].isdigit():
                                            # do a regex IP validation
                                            if not re.match(
                                                    r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$",
                                                    value):
                                                print helpers.color(
                                                    "\n [!] ERROR: Bad IP address specified.\n",
                                                    warning=True)
                                            else:
                                                try:
                                                    payload.required_options[
                                                        option][0] = value
                                                    print " [i] %s => %s" % (
                                                        option, value)
                                                except KeyError:
                                                    print helpers.color(
                                                        "\n [!] ERROR #1: Specify LHOST value in the following screen.\n",
                                                        warning=True)
                                                except AttributeError:
                                                    print helpers.color(
                                                        "\n [!] ERROR #2: Specify LHOST value in the following screen.\n",
                                                        warning=True)

                                        # assume we've been passed a domain name
                                        else:
                                            if helpers.isValidHostname(value):
                                                payload.required_options[
                                                    option][0] = value
                                                print " [i] %s => %s" % (
                                                    option, value)
                                            else:
                                                print helpers.color(
                                                    "\n [!] ERROR: Bad hostname specified.\n",
                                                    warning=True)

                                    else:
                                        print helpers.color(
                                            "\n [!] ERROR: Bad IP address or hostname specified.\n",
                                            warning=True)

                                elif ':' in value:
                                    try:
                                        socket.inet_pton(
                                            socket.AF_INET6, value)
                                        payload.required_options[option][
                                            0] = value
                                        print " [i] %s => %s" % (option, value)
                                    except socket.error:
                                        print helpers.color(
                                            "\n [!] ERROR: Bad IP address or hostname specified.\n",
                                            warning=True)
                                        value = ""

                                else:
                                    print helpers.color(
                                        "\n [!] ERROR: Bad IP address or hostname specified.\n",
                                        warning=True)
                                    value = ""

                            # validate LPORT
                            elif option == "LPORT":
                                try:
                                    if int(value) <= 0 or int(value) >= 65535:
                                        print helpers.color(
                                            "\n [!] ERROR: Bad port number specified.\n",
                                            warning=True)
                                    else:
                                        try:
                                            payload.required_options[option][
                                                0] = value
                                            print " [i] %s => %s" % (option,
                                                                     value)
                                        except KeyError:
                                            print helpers.color(
                                                "\n [!] ERROR: Specify LPORT value in the following screen.\n",
                                                warning=True)
                                        except AttributeError:
                                            print helpers.color(
                                                "\n [!] ERROR: Specify LPORT value in the following screen.\n",
                                                warning=True)
                                except ValueError:
                                    print helpers.color(
                                        "\n [!] ERROR: Bad port number specified.\n",
                                        warning=True)

                            # set the specific option value if not validation done
                            else:
                                try:
                                    payload.required_options[option][0] = value
                                    print " [*] %s => %s" % (option, value)
                                except:
                                    print helpers.color(
                                        " [!] ERROR: Invalid value specified.\n",
                                        warning=True)
                                    cmd = ""

                    # generate the payload
                    if cmd == "generate" or cmd == "gen" or cmd == "run" or cmd == "go" or cmd == "do" or cmd == "make":

                        # make sure all required options are filled in first
                        if self.ValidatePayload(payload):

                            #finished = True
                            # actually generate the payload code
                            payloadCode = payload.generate()

                            # ensure we got some code back
                            if payloadCode != "":
                                # call the output menu
                                return self.OutputMenu(payload,
                                                       payloadCode,
                                                       args=args)

                        else:
                            print helpers.color(
                                "\n [!] WARNING: not all required options filled\n",
                                warning=True)
                    if cmd == "options":
                        # if required options were specified, output them
                        if hasattr(self.payload, 'required_options'):
                            self.PayloadOptions(self.payload)