rapid7/metasploit_data_models

View on GitHub
lib/mdm/host/operating_system_normalization.rb

Summary

Maintainability
F
3 days
Test Coverage

File operating_system_normalization.rb has 457 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'recog'

#
# Rules for operating system fingerprinting in Metasploit
#
Severity: Minor
Found in lib/mdm/host/operating_system_normalization.rb - About 7 hrs to fix

    Method apply_match_to_host has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

      def apply_match_to_host(match)
        host = self
    
        # These values in a match always override the current value unless
        # the host attribute has been explicitly locked by the user
    Severity: Minor
    Found in lib/mdm/host/operating_system_normalization.rb - About 2 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 normalize_nexpose_fingerprint has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

      def normalize_nexpose_fingerprint(data)
        ret = {}
        # :family=>"Windows" :certainty=>"0.85" :vendor=>"Microsoft" :product=>"Windows 7 Ultimate Edition"
        # :family=>"Windows" :certainty=>"0.67" :vendor=>"Microsoft" :arch=>"x86" :product=>'Windows 7' :version=>'SP1'
        # :family=>"Linux" :certainty=>"0.64" :vendor=>"Linux" :product=>"Linux"
    Severity: Minor
    Found in lib/mdm/host/operating_system_normalization.rb - About 2 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 recog_matches_for_note has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

      def recog_matches_for_note(note)
        # Skip notes that are missing the correct structure or have been blacklisted
        return [] if not validate_fingerprint_data(note)
    
        #
    Severity: Minor
    Found in lib/mdm/host/operating_system_normalization.rb - About 2 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 apply_match_to_host has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def apply_match_to_host(match)
        host = self
    
        # These values in a match always override the current value unless
        # the host attribute has been explicitly locked by the user
    Severity: Minor
    Found in lib/mdm/host/operating_system_normalization.rb - About 1 hr to fix

      Method normalize_match has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def normalize_match(m)
          # Normalize os.version strings containing 'Service Pack X' to just 'SPX'
          if m['os.version'] and m['os.version'].index('Service Pack ') == 0
            m['os.version'] = m['os.version'].gsub(/Service Pack /, 'SP')
          end
      Severity: Minor
      Found in lib/mdm/host/operating_system_normalization.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 parse_windows_os_str has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def parse_windows_os_str(str)
          ret = {}
      
          # Set some reasonable defaults for Windows
          ret['os.vendor']  = 'Microsoft'
      Severity: Minor
      Found in lib/mdm/host/operating_system_normalization.rb - About 1 hr to fix

        Method normalize_nexpose_fingerprint has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def normalize_nexpose_fingerprint(data)
            ret = {}
            # :family=>"Windows" :certainty=>"0.85" :vendor=>"Microsoft" :product=>"Windows 7 Ultimate Edition"
            # :family=>"Windows" :certainty=>"0.67" :vendor=>"Microsoft" :arch=>"x86" :product=>'Windows 7' :version=>'SP1'
            # :family=>"Linux" :certainty=>"0.64" :vendor=>"Linux" :product=>"Linux"
        Severity: Minor
        Found in lib/mdm/host/operating_system_normalization.rb - About 1 hr to fix

          Method recog_matches_for_note has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def recog_matches_for_note(note)
              # Skip notes that are missing the correct structure or have been blacklisted
              return [] if not validate_fingerprint_data(note)
          
              #
          Severity: Minor
          Found in lib/mdm/host/operating_system_normalization.rb - About 1 hr to fix

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

              def normalize_nessus_fingerprint(data)
                ret = {}
                # :os=>"Microsoft Windows 2000 Advanced Server (English)"
                # :os=>"Microsoft Windows 2000\nMicrosoft Windows XP"
                # :os=>"Linux Kernel 2.6"
            Severity: Minor
            Found in lib/mdm/host/operating_system_normalization.rb - About 1 hr to fix

              Method guess_purpose_from_match has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def guess_purpose_from_match(match)
                  # some data that is sent to this is numeric; we do not want that
                  pstr = ""
                  # Go through each character of each value and make sure it is all
                  # UTF-8
              Severity: Minor
              Found in lib/mdm/host/operating_system_normalization.rb - About 1 hr to fix

                Method normalize_os has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                  def normalize_os
                    host   = self
                    matches = []
                
                    # Note that we're already restricting the query to this host by using
                Severity: Minor
                Found in lib/mdm/host/operating_system_normalization.rb - About 55 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 normalize_qualys_fingerprint has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                  def normalize_qualys_fingerprint(data)
                    ret = {}
                    # :os=>"Microsoft Windows 2000"
                    # :os=>"Windows 2003"
                    # :os=>"Microsoft Windows XP Professional SP3"
                Severity: Minor
                Found in lib/mdm/host/operating_system_normalization.rb - About 55 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 normalize_nmap_fingerprint has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def normalize_nmap_fingerprint(data)
                    ret = {}
                
                    # :os_vendor=>"Microsoft" :os_family=>"Windows" :os_version=>"2000" :os_accuracy=>"94"
                    ret['os.certainty'] = ( data[:os_accuracy].to_f / 100.0 ).to_s if data[:os_accuracy]
                Severity: Minor
                Found in lib/mdm/host/operating_system_normalization.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 guess_purpose_from_match has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  def guess_purpose_from_match(match)
                    # some data that is sent to this is numeric; we do not want that
                    pstr = ""
                    # Go through each character of each value and make sure it is all
                    # UTF-8
                Severity: Minor
                Found in lib/mdm/host/operating_system_normalization.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 normalize_mbsa_fingerprint has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def normalize_mbsa_fingerprint(data)
                    ret = {}
                    # :os_match=>"Microsoft Windows Vista SP0 or SP1, Server 2008, or Windows 7 Ultimate (build 7000)"
                    #    :os_vendor=>"Microsoft" :os_family=>"Windows" :os_version=>"7" :os_accuracy=>"100"
                    ret['os.certainty'] = ( data[:os_accuracy].to_f / 100.0 ).to_s if data[:os_accuracy]
                Severity: Minor
                Found in lib/mdm/host/operating_system_normalization.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

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

                  def recog_matches_for_service(s)
                    #
                    # We assume that the service.info field contains certain types of probe
                    # replies and associate these with one or more Recog databases. The mapping
                    # of service.name to a specific database only fits into so many places and
                Severity: Minor
                Found in lib/mdm/host/operating_system_normalization.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

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

                  def normalize_scanner_fp(fp)
                    hits = []
                
                    return hits if not validate_fingerprint_data(fp)
                
                
                Severity: Minor
                Found in lib/mdm/host/operating_system_normalization.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

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

                  def parse_windows_os_str(str)
                    ret = {}
                
                    # Set some reasonable defaults for Windows
                    ret['os.vendor']  = 'Microsoft'
                Severity: Minor
                Found in lib/mdm/host/operating_system_normalization.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

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

                  def normalize_nessus_fingerprint(data)
                    ret = {}
                    # :os=>"Microsoft Windows 2000 Advanced Server (English)"
                    # :os=>"Microsoft Windows 2000\nMicrosoft Windows XP"
                    # :os=>"Linux Kernel 2.6"
                Severity: Minor
                Found in lib/mdm/host/operating_system_normalization.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

                    if ! host.attribute_locked?(:os_name)
                      # Try to fill this value from os.product first if it exists
                      if match.has_key?('os.product')
                        host.os_name = sanitize(match['os.product'])
                      else
                Severity: Minor
                Found in lib/mdm/host/operating_system_normalization.rb and 1 other location - About 15 mins to fix
                lib/mdm/host/operating_system_normalization.rb on lines 458..463

                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

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

                    if ! host.attribute_locked?(:os_sp)
                      if match['os.version']
                        host.os_sp = sanitize(match['os.version'])
                      else
                        if match['linux.kernel.version']
                Severity: Minor
                Found in lib/mdm/host/operating_system_normalization.rb and 1 other location - About 15 mins to fix
                lib/mdm/host/operating_system_normalization.rb on lines 436..443

                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