rapid7/metasploit-framework

View on GitHub
lib/msf/core/auxiliary/auth_brute.rb

Summary

Maintainability
F
5 days
Test Coverage

File auth_brute.rb has 593 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Msf

###
#
# This module provides methods for brute forcing authentication
Severity: Major
Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 day to fix

    Method each_user_pass has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
    Open

      def each_user_pass(noconn=false,&block)
        this_service = [datastore['RHOST'],datastore['RPORT']].join(":")
        fq_rest = [this_service,"all remaining users"].join(":")
    
        # This should kinda halfway be in setup, halfway in run... need to
    Severity: Minor
    Found in lib/msf/core/auxiliary/auth_brute.rb - About 7 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method build_credential_collection has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

      def build_credential_collection(opts)
        cred_collection = Metasploit::Framework::CredentialCollection.new({
          blank_passwords: datastore['BLANK_PASSWORDS'],
          pass_file: datastore['PASS_FILE'],
          user_file: datastore['USER_FILE'],
    Severity: Minor
    Found in lib/msf/core/auxiliary/auth_brute.rb - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method build_credentials_array has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

      def build_credentials_array
        credentials = extract_word_pair(datastore['USERPASS_FILE'])
        translate_proto_datastores()
        return credentials if datastore['USERPASS_FILE'] =~ /^memory:/
        users = load_user_vars(credentials)
    Severity: Minor
    Found in lib/msf/core/auxiliary/auth_brute.rb - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method each_user_pass has 63 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def each_user_pass(noconn=false,&block)
        this_service = [datastore['RHOST'],datastore['RPORT']].join(":")
        fq_rest = [this_service,"all remaining users"].join(":")
    
        # This should kinda halfway be in setup, halfway in run... need to
    Severity: Major
    Found in lib/msf/core/auxiliary/auth_brute.rb - About 2 hrs to fix

      Method combine_users_and_passwords has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def combine_users_and_passwords(user_array,pass_array)
          if (user_array.length + pass_array.length) < 1
            return []
          end
          combined_array = []
      Severity: Minor
      Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 hr to fix

        Method build_credential_collection has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def build_credential_collection(opts)
            cred_collection = Metasploit::Framework::CredentialCollection.new({
              blank_passwords: datastore['BLANK_PASSWORDS'],
              pass_file: datastore['PASS_FILE'],
              user_file: datastore['USER_FILE'],
        Severity: Minor
        Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 hr to fix

          Method combine_users_and_passwords has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            def combine_users_and_passwords(user_array,pass_array)
              if (user_array.length + pass_array.length) < 1
                return []
              end
              combined_array = []
          Severity: Minor
          Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method build_credentials_array has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def build_credentials_array
              credentials = extract_word_pair(datastore['USERPASS_FILE'])
              translate_proto_datastores()
              return credentials if datastore['USERPASS_FILE'] =~ /^memory:/
              users = load_user_vars(credentials)
          Severity: Minor
          Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 hr to fix

            Method initialize has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def initialize(info = {})
                super
            
                register_options([
                  OptString.new('USERNAME', [ false, 'A specific username to authenticate as' ]),
            Severity: Minor
            Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 hr to fix

              Method build_brute_message has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                def build_brute_message(host_ip,host_port,proto,msg)
                  ip = host_ip.to_s.strip if host_ip
                  port = host_port.to_s.strip if host_port
                  complete_message = nil
                  old_msg = msg.to_s.strip
              Severity: Minor
              Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method print_brute has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                def print_brute(opts={})
                  if opts[:level] and opts[:level].to_s[/^v/]
                    return unless datastore["VERBOSE"]
                    level = opts[:level].to_s[1,16].strip
                  else
              Severity: Minor
              Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method extract_word_pair_from_memory has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def extract_word_pair_from_memory(memloc)
                  begin
                    creds = []
                    obj = get_object_from_memory_location(memloc)
                    unless obj.all_creds.empty?
              Severity: Minor
              Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 hr to fix

                Method counters_expired? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  def counters_expired?(this_service,credentials)
                    expired_cred = false
                    expired_time = false
                    # Workaround for cases where multiple auth_brute modules are running concurrently and
                    # someone stomps on the @max_per_service class variable during setup.
                Severity: Minor
                Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method extract_word_pair_from_memory has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  def extract_word_pair_from_memory(memloc)
                    begin
                      creds = []
                      obj = get_object_from_memory_location(memloc)
                      unless obj.all_creds.empty?
                Severity: Minor
                Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method cleanup_files has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  def cleanup_files
                    path = datastore['USERPASS_FILE']
                    if path and datastore['REMOVE_USERPASS_FILE']
                      ::File.unlink(path) rescue nil
                    end
                Severity: Minor
                Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method counters_expired? has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def counters_expired?(this_service,credentials)
                    expired_cred = false
                    expired_time = false
                    # Workaround for cases where multiple auth_brute modules are running concurrently and
                    # someone stomps on the @max_per_service class variable during setup.
                Severity: Minor
                Found in lib/msf/core/auxiliary/auth_brute.rb - About 1 hr to fix

                  Method extract_word_pair has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def extract_word_pair(wordfile)
                      creds = []
                      if wordfile.to_s =~ /^memory:/
                        return extract_word_pair_from_memory(wordfile.to_s)
                      else
                  Severity: Minor
                  Found in lib/msf/core/auxiliary/auth_brute.rb - About 45 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method adjust_credentials_by_max_user has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def adjust_credentials_by_max_user(credentials)
                      max = datastore['MaxGuessesPerUser'].to_i.abs
                      if max == 0
                        new_credentials = credentials
                      else
                  Severity: Minor
                  Found in lib/msf/core/auxiliary/auth_brute.rb - About 35 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method initialize_class_variables has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def initialize_class_variables(this_service,credentials)
                      @@guesses_per_service ||= {}
                      @@guesses_per_service[this_service] = nil
                      @@credentials_skipped = {}
                      @@credentials_tried   = {}
                  Severity: Minor
                  Found in lib/msf/core/auxiliary/auth_brute.rb - About 25 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    def load_user_vars(credentials = nil)
                      users = extract_words(datastore['USER_FILE'])
                      if datastore['USERNAME']
                        users.unshift datastore['USERNAME']
                        credentials = prepend_chosen_username(datastore['USERNAME'], credentials) if credentials
                  Severity: Minor
                  Found in lib/msf/core/auxiliary/auth_brute.rb and 1 other location - About 20 mins to fix
                  lib/msf/core/auxiliary/auth_brute.rb on lines 456..462

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 28.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    def load_password_vars(credentials = nil)
                      passwords = extract_words(datastore['PASS_FILE'])
                      if datastore['PASSWORD']
                        passwords.unshift datastore['PASSWORD']
                        credentials = prepend_chosen_password(datastore['PASSWORD'], credentials) if credentials
                  Severity: Minor
                  Found in lib/msf/core/auxiliary/auth_brute.rb and 1 other location - About 20 mins to fix
                  lib/msf/core/auxiliary/auth_brute.rb on lines 447..453

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 28.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 7 locations. Consider refactoring.
                  Open

                    def extract_words(wordfile)
                      return [] unless wordfile && File.readable?(wordfile)
                  
                      begin
                        File.readlines(wordfile, chomp: true)
                  Severity: Minor
                  Found in lib/msf/core/auxiliary/auth_brute.rb and 6 other locations - About 15 mins to fix
                  modules/auxiliary/admin/http/tomcat_utf8_traversal.rb on lines 49..57
                  modules/auxiliary/admin/http/trendmicro_dlp_traversal.rb on lines 48..56
                  modules/auxiliary/scanner/http/linksys_e1500_traversal.rb on lines 39..47
                  modules/auxiliary/scanner/http/netgear_sph200d_traversal.rb on lines 36..44
                  modules/auxiliary/scanner/http/tplink_traversal_noauth.rb on lines 36..44
                  modules/auxiliary/scanner/smtp/smtp_enum.rb on lines 210..218

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 25.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status