def check_io(): output = "" while True: output = proc.stdout.readline().decode() output = output.replace("\n", "") if output: info(output) else: break if output != "": while proc.poll() is None: check_io()
def mainloop(): while 1: # set title set_title("The PenTesters Framework (PTF) v%s" % grab_version) try: prompt = input(bcolors.BOLD + "ptf" + bcolors.ENDC + "> ") info(prompt) except EOFError as eof: error(eof) prompt = "quit" print("") handle_prompt(prompt)
def mainloop(): has_run = 0 while 1: has_run += 1 # set title set_title("The PenTesters Framework (PTF) v%s" % grab_version) if not has_run >= 2: print_info("[!] Logs are now outputed into the directory of cloned ptf under name 'ptf-output.log'") try: prompt = input(bcolors.BOLD + "ptf" + bcolors.ENDC + "> ") info(prompt) except EOFError as eof: error(eof) prompt = "quit" print("") handle_prompt(prompt)
def use_module(module, all_trigger): prompt = ("") # if we aren't using all if not "install_update_all" in module and not "update_installed" in module and not "__init__" in module and not "custom_list" in module: # set terminal title set_title("ptf - %s" % module) # if we are using a normal module if int(all_trigger) == 0 or int(all_trigger) == 1 or int( all_trigger) == 2: filename = discover_module_filename(module) module = filename_to_module(filename) # grab the author try: author = module_parser(filename, "AUTHOR") except TypeError: author = "Invalid" # grab the description description = module_parser(filename, "DESCRIPTION") # grab install type install_type = module_parser(filename, "INSTALL_TYPE") # if were are tool depends for other modules prior to install tool_depend = module_parser(filename, "TOOL_DEPEND") # Since unicorn requires metasploit to be installed in order to generate the payloads, # by default PTF will install or update metasploit. # Here it will ask what the user wants to do for if they already have msf installed # If they do, it will skip, else it will install if 'metasploit' in tool_depend and 'unicorn' in module: print_warning( "Unicorn requires Metasploit Framework to be installed.") # Check if metasploit is installed if os.path.isdir("/opt/metasploit-framework/"): print_info( "Seems like you have Metasploit Framework already installed" ) install_unicorn = input( "Do you want to update metasploit? (y/n) (default is yes) " ).lower() # Do we want to update metasploit now or later # If yes, then this will run as this part never existed if install_unicorn == 'y': print_info( "Once you enter run, update, install or upgrade I will install metasploit for you" ) pass # If we do not want to update, then it will skip metasploit update elif install_unicorn == 'n': print_info("Skipping metasploit installation/update") tool_depend = "" else: # If we enter anything but 'y' or 'n', it will continue like normal print_info( "No input detected. I will continue as normal and update metasploit" ) pass else: # If metasploit is not installed, then we will run as this part never existed print_warning( "Metasploit Framework is NOT installed. Therefore, I will install it for you" ) pass else: pass # if the module path is wrong, throw a warning try: if not os.path.isfile(tool_depend + ".py"): if len(tool_depend) > 1: print_warning( "Tool depend: " + tool_depend + " not found. Ensure the module is pointing to a module location." ) except TypeError: pass # grab repository location repository_location = module_parser(filename, "REPOSITORY_LOCATION") # custom work for zaproxy if "zaproxy" in repository_location: repository_location = zaproxy() # here we check if we need to do x86 or x64 if module_parser(filename, "X64_LOCATION") != "": # grab architecture arch_detect = arch() if "64bit" in arch_detect: repository_location = module_parser( filename, "X64_LOCATION") # grab install path base_install = check_config("BASE_INSTALL_PATH=") strorganize_dirs = check_config("USE_DIRECTORY_ORGANIZATION=") install_base_location = module_parser(filename, "INSTALL_LOCATION") module_split = module.split("/") module_split = module_split[1] if strorganize_dirs == "False": organize_dirs = False else: # Default to True organize_dirs = True if bool(organize_dirs) == True: install_location = os.path.expanduser(base_install + "/" + module_split + "/" + install_base_location + "/") else: install_location = base_install + "/" + install_base_location + "/" while 1: # if we aren't doing update/install all if int(all_trigger) == 0: try: prompt = input(bcolors.BOLD + "ptf:" + bcolors.ENDC + "(" + bcolors.RED + "%s" % module + bcolors.ENDC + ")>") info("Options after module has been chosen") info(prompt) except EOFError as eof: error(eof) prompt = "back" print("") # exit if we need to if prompt == "back" or prompt == "quit" or prompt == "exit": return "None" # show the help menu if prompt == "?" or prompt == "help": show_help_menu() # show modules if prompt == "show modules": print_warning( "In order to show modules, you must type 'back' first") # if we are using a module within a module we return our prompt if "use " in prompt: return prompt # if we are searching for something if "search " in prompt: search(prompt) if "show " in prompt: prompt = split("/", "")[1] search(prompt) # options menu - was a choice here to load upon initial load of dynamically pull each time # if changes are made, it makes sense to keep it loading each time if prompt.lower() == "show options": print("Module options (%s):" % module) # if we are using a normal module if module != "modules/install_update_all": print("\n\n") print(bcolors.BOLD + "Module Author: " + bcolors.ENDC + author) print(bcolors.BOLD + "Module Description: " + bcolors.ENDC + description) print( "-------------------------------------------------------------------------------------" ) print(bcolors.BOLD + "INSTALL_TYPE: " + bcolors.ENDC + install_type) print(bcolors.BOLD + "REPOSITORY_LOCATION: " + bcolors.ENDC + repository_location) print(bcolors.BOLD + "INSTALL_LOCATION: " + bcolors.ENDC + install_location) print( "-------------------------------------------------------------------------------------" ) # if we are setting the command now if prompt.lower().startswith("set"): # need to grab the options set_breakout = prompt.split(" ") # here we rewrite the options for the menu if set_breakout[1].upper() == "INSTALL_TYPE": install_type = set_breakout[2] if set_breakout[1].upper() == "REPOSITORY_LOCATION": repository_location = set_breakout[2] if set_breakout[1].upper() == "INSTALL_LOCATION": install_location = set_breakout[2] # tool depend is if there is a tool for example like veil that has a depend of Metasploit - can put TOOL_DEPEND = the tool or tools here if not "show options" in prompt.lower(): if len(tool_depend) > 1: try: if " " in tool_depend: tool_depend = tool_depend.split(" ") for tool in tool_depend: use_module(tool, "1") elif "," in tool_depend: tool_depend = tool_depend.split(",") for tool in tool_depend: use_module(tool, "1") else: use_module(tool_depend, "1") except: pass if len(tool_depend) < 1: if int(all_trigger) == 1: prompt = "run" if int(all_trigger) == 2: prompt = "update" # if we are using run, check first to see if its there, if so, do # an upgrade if prompt.lower() == "run": # check if empty directory - if so purge it before anything # else check_blank_dir(install_location) if os.path.isdir(install_location): print_status( "Detected installation already. Going to upgrade for you." ) prompt = "update" else: print_status( "Tool not installed yet, will run through install routine" ) prompt = "install" def log_output(): # Log proc output into the log file def check_io(): output = "" while True: output = proc.stdout.readline().decode() output = output.replace("\n", "") if output: info(output) else: break if output != "": while proc.poll() is None: check_io() # check to see if we need to bypass after commands for certain # files - this is needed when using FILE and others where after # commands need to be run if module_parser(filename, "BYPASS_UPDATE") == "YES": if prompt.lower() == "update": prompt = "install" # if we are updating the tools if prompt.lower() == "update" or prompt.lower() == "upgrade": # if we are using ignore modules then don't process if not "__init__.py" in filename and not ignore_module( filename): # move to the location if os.path.isdir(install_location): if install_type.lower() == "git": msg = "Updating %s , be patient while git pull is initiated" % module print_status(msg) info(msg) proc = subprocess.Popen("cd %s;git pull" % (install_location), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) log_output() # check launcher launcher(filename, install_location) # here we check to see if we need anything we need to # run after things are updated update_counter = 0 if not "Already up-to-date." in proc.communicate(): after_commands(filename, install_location) update_counter = 1 else: print_status("Tool already up-to-date!") log("Tool already up-to-date") msg = "Finished Installing! Enjoy the tool installed under: " + install_location print_status(msg) log(msg) # run after commands if update_counter == 0: after_commands(filename, install_location) if install_type.lower() == "gitlab": if pexpect_check == 0: print( "[!] You can't use gitlab features unless you install pexpect. Please install pexpect in order to use these features. Install option: pip install python-pexpect." ) else: print_status( "Updating the tool, be patient while git pull is initiated." ) get_password_gitlab() proc = pexpect.spawn('git -C %s pull' % (install_location)) proc.expect('passphrase') proc.sendline('%s' % password_gitlab) proc.expect(pexpect.EOF) # check launcher launcher(filename, install_location) # here we check to see if we need anything we need to # run after things are updated update_counter = 0 i = proc.expect( ['Already up-to-date!', pexpect.EOF]) if i == 1: after_commands(filename, install_location) update_counter = 1 elif i == 0: print_status("Tool already up-to-date!") print_status( "Finished Installing! Enjoy the tool installed under: " + (install_location)) # run after commands if update_counter == 0: after_commands(filename, install_location) if install_type.lower() == "svn": print_status( "Updating the tool, be patient while svn pull is initiated." ) proc = subprocess.Popen("cd %s;svn update" % (install_location), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) # here we do some funky stuff to store old # revisions try: if not os.path.isfile(install_location + "/.goatsvn_storage"): filewrite = open( install_location + "/.goatsvn_storage", "w") filewrite.write(proc.communicate()[0]) filewrite.close() if os.path.isfile(install_location + "/.goatsvn_storage"): cmp = open( install_location + "/.goatsvn_storage", "r").read() # if we are at a new revision if cmp != proc.communicate()[0]: # change prompt to something other than # update prompt = "goat" except: pass finally: proc.wait() print_status( "Finished Installing! Enjoy the tool installed under: " + (install_location)) # check launcher launcher(filename, install_location) # run after commands if prompt != "update": after_commands(filename, install_location) print_status("Running updatedb to tidy everything up.") subprocess.Popen("updatedb", shell=True).wait() if not os.path.isdir(install_location): print_error( "The tool was not found in the install location. Try running install first!" ) # if we want to install it if prompt.lower() == "install": # if we are using ignore modules then don't process if not "__init__.py" in filename and not ignore_module( filename): # grab the OS type, DEBIAN, FEDORA, CUSTOM, BSD!!!! WOW!!, ostype = profile_os() # Global msg for below preparing dependencies for module msg_prep_dpns = "Preparing dependencies for module: " + module msg_prep_reqs = "Pre-reqs for %s have been installed." % module # if OSTYPE is DEBIAN if ostype == "DEBIAN": print_status(msg_prep_dpns) info(msg_prep_dpns) from src.platforms.debian import base_install_modules # grab all the modules we need deb_modules = module_parser(filename, "DEBIAN") base_install_modules(deb_modules) print_status(msg_prep_reqs) info(msg_prep_reqs) # if OSTYPE is ARCHLINUX if ostype == "ARCHLINUX": print_status(msg_prep_dpns) info(msg_prep_dpns) from src.platforms.archlinux import base_install_modules # grab all the modules we need arch_modules = module_parser(filename, "ARCHLINUX") base_install_modules(arch_modules) print_status(msg_prep_reqs) info(msg_prep_reqs) # if OSTYPE is FEDORA if ostype == "FEDORA": print_status(msg_prep_dpns) info(msg_prep_dpns) from src.platforms.fedora import base_install_modules # grab all the modules we need fedora_modules = module_parser(filename, "FEDORA") base_install_modules(fedora_modules) print_status(msg_prep_reqs) info(msg_prep_reqs) # if OSTYPE is OPENBSD if ostype == "OPENBSD": print_status(msg_prep_dpns) info(msg_prep_dpns) from src.platforms.openbsd import base_install_modules # grab all the modules we need openbsd_modules = module_parser(filename, "OPENBSD") base_install_modules(openbsd_modules) print_status(msg_prep_reqs) info(msg_prep_reqs) msg = "Making the appropriate directory structure first" print_status(msg) info(msg) subprocess.Popen("mkdir -p %s" % install_location, shell=True).wait() # if we are using git if install_type.lower() in ["git", "gitlab"]: # if there are files in the install_location, we'll update. if os.listdir(install_location): msg = "Installation already exists, going to git pull then run after commands.." info(msg) print_status(msg) if install_type.lower() == "gitlab": get_password_gitlab() proc = pexpect.spawn('git -C %s pull' % (install_location)) proc.expect('passphrase') proc.sendline('%s' % password_gitlab) proc.expect(pexpect.EOF) proc.wait() else: subprocess.Popen("cd %s;git pull" % (install_location), stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).wait() msg = "Finished updating the tool located in:" + install_location print_status(msg) info(msg) else: msg = "%s was the selected method for installation... Using %s to install." % ( install_type.upper(), install_type.upper()) print_status(msg) info(msg) print_status("Installing now.. be patient...") info("Installing now.. be patient...") if install_type.lower() == "gitlab": get_password_gitlab() proc = pexpect.spawn( 'git clone --depth=1 %s %s' % (repository_location, install_location)) log_output() proc.expect('passphrase') proc.sendline('%s' % password_gitlab) proc.expect(pexpect.EOF) else: proc = subprocess.Popen( "git clone --depth=1 %s %s" % (repository_location, install_location), stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).wait() log_output() msg = "Finished Installing! Enjoy the tool located under: " + install_location info(msg) print_status(msg) after_commands(filename, install_location) launcher(filename, install_location) # if we are using svn if install_type.lower() == "svn": print_status( "SVN was the selected method for installation... Using SVN to install." ) subprocess.Popen( "svn co %s %s" % (repository_location, install_location), stderr=subprocess.PIPE, shell=True).wait() print_status( "Finished Installing! Enjoy the tool located under: " + install_location) launcher(filename, install_location) after_commands(filename, install_location) # if we are using file if install_type.lower() == "file": print_status( "FILE was the selected method for installation... Using curl -o to install." ) repository_file = repository_location.split("/")[-1] subprocess.Popen( 'curl -k -L -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30" -o %s%s %s' % (install_location, repository_file, repository_location), stderr=subprocess.PIPE, shell=True).wait() print_status( "Finished Installing! Enjoy the tool located under: " + install_location) launcher(filename, install_location) after_commands(filename, install_location) # if we are using wget if install_type.lower() == "wget": print_status( "WGET was the selected method for installation because it plays better than curl -l with recursive URLs." ) subprocess.Popen( "cd %s && wget -q %s" % (install_location, repository_location), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).wait() print_status( "Finished Installing! Enjoy the tool located under: " + install_location) launcher(filename, install_location) after_commands(filename, install_location) print_status("Running updatedb to tidy everything up.") subprocess.Popen("updatedb", shell=True).wait() # if we update all we need to break out until finished if int(all_trigger) == 1 or int(all_trigger) == 2: break