def MainMenu(self, showMessage=True, args=None):
        """
        Main interactive menu for payload generation.

        showMessage = reset the screen and show the greeting message [default=True]
        oneRun = only run generation once, returning the path to the compiled executable
            used when invoking the framework from an external source
        """

        self.outputFileName = ""
        cmd = ""

        try:
            while cmd == "" and self.outputFileName == "":

                # set out tab completion for the appropriate modules on each run
                # as other modules sometimes reset this
                comp = completers.MainMenuCompleter(self.commands, self.payloads)
                readline.set_completer_delims(" \t\n;")
                readline.parse_and_bind("tab: complete")
                readline.set_completer(comp.complete)

                if showMessage:
                    # print the title, where we are, and number of payloads loaded
                    if settings.TERMINAL_CLEAR != "false":
                        messages.title()
                    print " Main Menu\n"
                    print "\t" + helpers.color(str(len(self.payloads))) + " payloads loaded\n"
                    messages.helpmsg(self.commands, showTitle=False)
                    showTitle = False

                cmd = raw_input(" [menu>>]: ").strip()

                # handle our tab completed commands
                if cmd.startswith("help"):
                    if settings.TERMINAL_CLEAR != "false":
                        messages.title()
                    cmd = ""
                    showMessage = False

                elif cmd.startswith("use"):

                    if len(cmd.split()) == 1:
                        if settings.TERMINAL_CLEAR != "false":
                            messages.title()
                        self.ListPayloads()
                        showMessage = False
                        cmd = ""

                    elif len(cmd.split()) == 2:

                        # pull out the payload/number to use
                        p = cmd.split()[1]

                        # if we're choosing the payload by numbers
                        if p.isdigit() and 0 < int(p) <= len(self.payloads):
                            x = 1
                            for (name, pay) in self.payloads:
                                # if the entered number matches the payload #, use that payload
                                if int(p) == x:
                                    self.payload = pay
                                    self.payloadname = name
                                    self.outputFileName = self.PayloadMenu(self.payload, args=args)
                                x += 1

                        # else choosing the payload by name
                        else:
                            for (payloadName, pay) in self.payloads:
                                # if we find the payload specified, kick off the payload menu
                                if payloadName == p:
                                    self.payload = pay
                                    self.payloadname = payloadName
                                    self.outputFileName = self.PayloadMenu(self.payload, args=args)

                        cmd = ""
                        if settings.TERMINAL_CLEAR != "false":
                            showMessage = True

                    # error catchings if not of form [use BLAH]
                    else:
                        cmd = ""
                        showMessage = False

                elif cmd.startswith("update"):
                    self.UpdateVeil()
                    if settings.TERMINAL_CLEAR != "false":
                        showMessage = True
                    cmd = ""

                elif cmd.startswith("checkvt"):
                    self.CheckVT()
                    if settings.TERMINAL_CLEAR != "false":
                        showMessage = True
                    cmd = ""

                # clean payload folders
                if cmd.startswith("clean"):
                    self.CleanPayloads()
                    if settings.TERMINAL_CLEAR != "false":
                        showMessage = True
                    cmd = ""

                elif cmd.startswith("info"):

                    if len(cmd.split()) == 1:
                        if settings.TERMINAL_CLEAR != "false":
                            showMessage = True
                        cmd = ""

                    elif len(cmd.split()) == 2:

                        # pull out the payload/number to use
                        p = cmd.split()[1]

                        # if we're choosing the payload by numbers
                        if p.isdigit() and 0 < int(p) <= len(self.payloads):
                            x = 1
                            for (name, pay) in self.payloads:
                                # if the entered number matches the payload #, use that payload
                                if int(p) == x:
                                    self.payload = pay
                                    self.payloadname = name
                                    self.PayloadInfo(self.payload)
                                x += 1

                        # else choosing the payload by name
                        else:
                            for (payloadName, pay) in self.payloads:
                                # if we find the payload specified, kick off the payload menu
                                if payloadName == p:
                                    self.payload = pay
                                    self.payloadname = payloadName
                                    self.PayloadInfo(self.payload)

                        cmd = ""
                        showMessage = False

                    # error catchings if not of form [use BLAH]
                    else:
                        cmd = ""
                        showMessage = False

                elif cmd.startswith("list") or cmd.startswith("ls"):

                    if len(cmd.split()) == 1:
                        if settings.TERMINAL_CLEAR != "false":
                            messages.title()
                        self.ListPayloads()

                    cmd = ""
                    showMessage = False

                elif cmd.startswith("exit") or cmd.startswith("q"):
                    if self.oneRun:
                        # if we're being invoked from external code, just return
                        # an empty string on an exit/quit instead of killing everything
                        return ""
                    else:
                        print helpers.color("\n [!] Exiting...\n", warning=True)
                        sys.exit()

                # select a payload by just the number
                elif cmd.isdigit() and 0 < int(cmd) <= len(self.payloads):
                    x = 1
                    for (name, pay) in self.payloads:
                        # if the entered number matches the payload #, use that payload
                        if int(cmd) == x:
                            self.payload = pay
                            self.payloadname = name
                            self.outputFileName = self.PayloadMenu(self.payload, args=args)
                        x += 1
                    cmd = ""
                    if settings.TERMINAL_CLEAR != "false":
                        showMessage = True

                # if nothing is entered
                else:
                    cmd = ""
                    showMessage = False

                # if we're looping forever on the main menu (Veil.py behavior)
                # reset the output filname to nothing so we don't break the while
                if not self.oneRun:
                    self.outputFileName = ""

            return self.outputFileName

        # catch any ctrl + c interrupts
        except KeyboardInterrupt:
            if self.oneRun:
                # if we're being invoked from external code, just return
                # an empty string on an exit/quit instead of killing everything
                return ""
            else:
                print helpers.color("\n\n [!] Exiting...\n", warning=True)
                sys.exit()
Example #2
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)
    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)
Example #4
0
    def MainMenu(self, showMessage=True):
        """
        Main interactive menu for payload generation.

        showMessage = reset the screen and show the greeting message [default=True]
        oneRun = only run generation once, returning the path to the compiled executable
        	used when invoking the framework from an external source
        """

        self.outputFileName = ""
        cmd = ""

        try:
            while cmd == "" and self.outputFileName == "":

                # set out tab completion for the appropriate modules on each run
                # as other modules sometimes reset this
                comp = completers.MainMenuCompleter(self.commands,
                                                    self.payloads)
                readline.set_completer_delims(' \t\n;')
                readline.parse_and_bind("tab: complete")
                readline.set_completer(comp.complete)

                if showMessage:
                    # print the title, where we are, and number of payloads loaded
                    messages.title()
                    print " Main Menu\n"
                    print "\t" + helpers.color(str(len(
                        self.payloads))) + " payloads loaded\n"
                    messages.helpmsg(self.commands, showTitle=False)

                cmd = raw_input(' [>] Please enter a command: ').strip()

                # handle our tab completed commands
                if cmd.startswith("help"):
                    #messages.helpmsg(self.commands)
                    messages.title()
                    self.commands
                    cmd = ""
                    showMessage = False

                elif cmd.startswith("use"):

                    if len(cmd.split()) == 1:
                        messages.title()
                        self.ListAllPayloads()
                        showMessage = False
                        cmd = ""

                    elif len(cmd.split()) == 2:

                        # pull out the payload/number to use
                        p = cmd.split()[1]

                        # if we're choosing the payload by numbers
                        if p.isdigit() and 0 < int(p) <= len(self.payloads):
                            x = 1
                            for (name, pay) in self.payloads:
                                # if the entered number matches the payload #, use that payload
                                if int(p) == x:
                                    self.payload = pay
                                    self.outputFileName = self.PayloadMenu(
                                        self.payload)
                                x += 1

                        # else choosing the payload by name
                        elif len(p.split("/")) == 2:
                            lang, payloadName = p.split("/")

                            for (name, pay) in self.payloads:

                                # if we find the payload specified, kick off the payload menu
                                if pay.language == lang:
                                    if pay.shortname == payloadName:
                                        self.payload = pay
                                        self.outputFileName = self.PayloadMenu(
                                            self.payload)

                        cmd = ""
                        showMessage = True

                    # error catchings if not of form [use BLAH]
                    else:
                        cmd = ""
                        showMessage = False

                elif cmd.startswith("update"):
                    self.UpdateVeil()
                    showMessage = True
                    cmd = ""

                elif cmd.startswith("info"):

                    if len(cmd.split()) == 1:
                        showMessage = True
                        cmd = ""

                    elif len(cmd.split()) == 2:

                        # pull out the payload/number to use
                        p = cmd.split()[1]

                        # if we're choosing the payload by numbers
                        if p.isdigit() and 0 < int(p) <= len(self.payloads):
                            x = 1
                            for (name, pay) in self.payloads:
                                # if the entered number matches the payload #, use that payload
                                if int(p) == x:
                                    self.payload = pay
                                    self.PayloadInfo(self.payload)
                                x += 1

                        # else choosing the payload by name
                        elif len(p.split("/")) == 2:
                            lang, payloadName = p.split("/")

                            for (name, pay) in self.payloads:

                                # if we find the payload specified, kick off the payload menu
                                if pay.language == lang:
                                    if pay.shortname == payloadName:
                                        self.payload = pay
                                        self.PayloadInfo(self.payload)

                        cmd = ""
                        showMessage = False

                    # error catchings if not of form [use BLAH]
                    else:
                        cmd = ""
                        showMessage = False

                elif cmd.startswith("list"):

                    if len(cmd.split()) == 1:
                        messages.title()
                        self.ListAllPayloads()

                    if len(cmd.split()) == 2:
                        parts = cmd.split()
                        if parts[1] == "all" or parts[1] == "payloads":
                            messages.title()
                            self.ListAllPayloads()
                        elif parts[1] == "langs":
                            messages.title()
                            self.ListLangs()
                        else:
                            messages.title()
                            self.ListPayloads(parts[1])

                    cmd = ""
                    showMessage = False

                elif cmd.startswith("exit") or cmd.startswith("q"):
                    if self.oneRun:
                        # if we're being invoked from external code, just return
                        # an empty string on an exit/quit instead of killing everything
                        return ""
                    else:
                        print helpers.color("\n [!] Exiting...\n",
                                            warning=True)
                        sys.exit()

                # select a payload by just the number
                elif cmd.isdigit() and 0 < int(cmd) <= len(self.payloads):
                    x = 1
                    for (name, pay) in self.payloads:
                        # if the entered number matches the payload #, use that payload
                        if int(cmd) == x:
                            self.payload = pay
                            self.outputFileName = self.PayloadMenu(
                                self.payload)
                        x += 1
                    cmd = ""
                    showMessage = True

                # if nothing is entered
                else:
                    cmd = ""
                    showMessage = True

                # if we're looping forever on the main menu (Veil.py behsvior)
                # reset the output filname to nothing so we don't break the while
                if not self.oneRun:
                    self.outputFileName = ""

            return self.outputFileName

        # catch any ctrl + c interrupts
        except KeyboardInterrupt:
            if self.oneRun:
                # if we're being invoked from external code, just return
                # an empty string on an exit/quit instead of killing everything
                return ""
            else:
                print helpers.color("\n\n [!] Exiting...\n", warning=True)
                sys.exit()
Example #5
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)
Example #6
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)
Example #7
0
    def MainMenu(self, showMessage=True):
        """
		Main interactive menu for payload generation.
		
		showMessage = reset the screen and show the greeting message, default=True
		
		"""
        try:

            comp = completers.MainMenuCompleter(self.commands, self.payloads)
            # we want to treat '/' as part of a word, so override the delimiters
            readline.set_completer_delims(" \t\n;")
            readline.parse_and_bind("tab: complete")
            readline.set_completer(comp.complete)
            cmd = ""

            while cmd == "":

                if showMessage:
                    # print the title, where we are, and number of payloads loaded
                    messages.title()
                    print " Main Menu\n"
                    print "\t" + helpers.color(str(len(self.payloads))) + " payloads loaded\n"

                if self.firstRun:
                    messages.helpmsg(self.commands, showTitle=False)
                    # self.firstRun = False

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

                # handle our tab completed commands
                if cmd.startswith("help"):
                    # messages.helpmsg(self.commands)
                    messages.title()
                    self.commands
                    cmd = ""
                    showMessage = False

                elif cmd.startswith("use"):

                    if len(cmd.split()) == 1:
                        messages.title()
                        self.ListAllPayloads()
                        showMessage = False
                        cmd = ""

                    elif len(cmd.split()) == 2:

                        # pull out the payload/number to use
                        p = cmd.split()[1]

                        # if we're choosing the payload by numbers
                        if p.isdigit() and 0 < int(p) <= len(self.payloads):
                            x = 1
                            for (name, pay) in self.payloads:
                                # if the entered number matches the payload #, use that payload
                                if int(p) == x:
                                    self.payload = pay
                                    self.PayloadMenu(self.payload)
                                x += 1

                                # else choosing the payload by name
                        elif len(p.split("/")) == 2:
                            lang, payloadName = p.split("/")

                            for (name, pay) in self.payloads:

                                # if we find the payload specified, kick off the payload menu
                                if pay.language == lang:
                                    if pay.shortname == payloadName:
                                        self.payload = pay
                                        self.PayloadMenu(self.payload)

                        cmd = ""
                        showMessage = True

                        # error catchings if not of form [use BLAH]
                    else:
                        cmd = ""
                        showMessage = False

                elif cmd.startswith("info"):

                    if len(cmd.split()) == 1:
                        showMessage = True
                        cmd = ""

                    elif len(cmd.split()) == 2:

                        # pull out the payload/number to use
                        p = cmd.split()[1]

                        # if we're choosing the payload by numbers
                        if p.isdigit() and 0 < int(p) <= len(self.payloads):
                            x = 1
                            for (name, pay) in self.payloads:
                                # if the entered number matches the payload #, use that payload
                                if int(p) == x:
                                    self.payload = pay
                                    self.PayloadInfo(self.payload)
                                x += 1

                                # else choosing the payload by name
                        elif len(p.split("/")) == 2:
                            lang, payloadName = p.split("/")

                            for (name, pay) in self.payloads:

                                # if we find the payload specified, kick off the payload menu
                                if pay.language == lang:
                                    if pay.shortname == payloadName:
                                        self.payload = pay
                                        self.PayloadInfo(self.payload)

                        cmd = ""
                        showMessage = False

                        # error catchings if not of form [use BLAH]
                    else:
                        cmd = ""
                        showMessage = False

                elif cmd.startswith("list"):

                    if len(cmd.split()) == 1:
                        messages.title()
                        self.ListAllPayloads()

                    if len(cmd.split()) == 2:
                        parts = cmd.split()
                        if parts[1] == "all" or parts[1] == "payloads":
                            messages.title()
                            self.ListAllPayloads()
                        elif parts[1] == "langs":
                            messages.title()
                            self.ListLangs()
                        else:
                            messages.title()
                            self.ListPayloads(parts[1])

                    cmd = ""
                    showMessage = False

                elif cmd.startswith("exit") or cmd.startswith("q"):
                    print helpers.color("\n [!] Exiting...\n", warning=True)
                    sys.exit()

                    # select a payload by just the number
                elif cmd.isdigit() and 0 < int(cmd) <= len(self.payloads):
                    x = 1
                    for (name, pay) in self.payloads:
                        # if the entered number matches the payload #, use that payload
                        if int(cmd) == x:
                            self.payload = pay
                            self.PayloadMenu(self.payload)
                        x += 1
                    cmd = ""
                    showMessage = False

                    # if nothing is entered
                else:
                    showMessage = True

                    # catch any ctrl + c interrupts
        except KeyboardInterrupt:
            print helpers.color("\n\n [!] Exiting...\n", warning=True)
            sys.exit()
Example #8
0
	def MainMenu(self, showMessage=True, loop=-1):
		"""
		Main interactive menu for payload generation.
		
		showMessage = reset the screen and show the greeting message [default=True]
		loop = number of times to loop through menu, -1 for infinite
		"""

		try:
			cmd = ""
			while cmd == "" and loop != 0:
				
				# set out tab completion for the appropriate modules on each run
				# as other modules sometimes reset this
				comp = completers.MainMenuCompleter(self.commands, self.payloads)
				readline.set_completer_delims(' \t\n;')
				readline.parse_and_bind("tab: complete")
				readline.set_completer(comp.complete)

				if showMessage:
					# print the title, where we are, and number of payloads loaded
					messages.title()
					print " Main Menu\n"
					print "\t" + helpers.color(str(len(self.payloads))) + " payloads loaded\n"
					messages.helpmsg(self.commands, showTitle=False)
				
				cmd = raw_input(' [>] Please enter a command: ').strip()
				
				# handle our tab completed commands				
				if cmd.startswith("help"):
					#messages.helpmsg(self.commands)
					messages.title()
					self.commands
					cmd = ""
					showMessage=False
				
				elif cmd.startswith("use"):
					
					if len(cmd.split()) == 1:
						messages.title()
						self.ListAllPayloads()
						showMessage=False
						cmd = ""

					elif len(cmd.split()) == 2:
						
						# pull out the payload/number to use
						p = cmd.split()[1]

						# if we're choosing the payload by numbers
						if p.isdigit() and 0 < int(p) <= len(self.payloads):
							x = 1
							for (name, pay) in self.payloads:
								# if the entered number matches the payload #, use that payload
								if int(p) == x: 
									self.payload = pay
									self.outputFileName = self.PayloadMenu(self.payload)
								x += 1
								
						# else choosing the payload by name
						elif len(p.split("/")) == 2:	
							lang,payloadName = p.split("/")
							
							for (name, pay) in self.payloads:
								
								# if we find the payload specified, kick off the payload menu
								if pay.language == lang:
									if pay.shortname == payloadName:
										self.payload = pay
										self.outputFileName = self.PayloadMenu(self.payload)
							
						cmd = ""
						showMessage=True
						
					# error catchings if not of form [use BLAH]
					else:
						cmd = ""
						showMessage=False
				
				elif cmd.startswith("update"):
					self.UpdateVeil()
					showMessage=True
					cmd = ""

				elif cmd.startswith("info"):
					
					if len(cmd.split()) == 1:
						showMessage=True
						cmd = ""

					elif len(cmd.split()) == 2:
						
						# pull out the payload/number to use
						p = cmd.split()[1]

						# if we're choosing the payload by numbers
						if p.isdigit() and 0 < int(p) <= len(self.payloads):
							x = 1
							for (name, pay) in self.payloads:
								# if the entered number matches the payload #, use that payload
								if int(p) == x: 
									self.payload = pay
									self.PayloadInfo(self.payload)
								x += 1
								
						# else choosing the payload by name
						elif len(p.split("/")) == 2:	
							lang,payloadName = p.split("/")
							
							for (name, pay) in self.payloads:
								
								# if we find the payload specified, kick off the payload menu
								if pay.language == lang:
									if pay.shortname == payloadName:
										self.payload = pay
										self.PayloadInfo(self.payload)
							
						cmd = ""
						showMessage=False
						
					# error catchings if not of form [use BLAH]
					else:
						cmd = ""
						showMessage=False
				
				elif cmd.startswith("list"):
					
					if len(cmd.split()) == 1:
						messages.title()
						self.ListAllPayloads()
						
					if len(cmd.split()) == 2:
						parts = cmd.split()
						if parts[1] == "all" or parts[1] == "payloads":
							messages.title()
							self.ListAllPayloads()
						elif parts[1] == "langs":
							messages.title()
							self.ListLangs()
						else:
							messages.title()
							self.ListPayloads(parts[1])
							
					cmd = ""
					showMessage=False
				
				elif cmd.startswith("exit") or cmd.startswith("q"):
					print helpers.color("\n [!] Exiting...\n", warning=True)
					sys.exit()
				
				# select a payload by just the number
				elif cmd.isdigit() and 0 < int(cmd) <= len(self.payloads):
					x = 1
					for (name, pay) in self.payloads:
						# if the entered number matches the payload #, use that payload
						if int(cmd) == x: 
							self.payload = pay
							self.outputFileName = self.PayloadMenu(self.payload)
						x += 1
					cmd = ""
					showMessage=True
				
				# if nothing is entered
				else:
					cmd = ""
					loop += 1
					showMessage=True
			
				loop -= 1

			return self.outputFileName 

		# catch any ctrl + c interrupts
		except KeyboardInterrupt:
			print helpers.color("\n\n [!] Exiting...\n", warning=True)
			sys.exit()