Beispiel #1
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()
Beispiel #2
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()