rapid7/metasploit-framework

View on GitHub
plugins/aggregator.rb

Summary

Maintainability
D
3 days
Test Coverage

File aggregator.rb has 411 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Msf
  Aggregator_yaml = "#{Msf::Config.config_directory}/aggregator.yaml".freeze # location of the aggregator.yml containing saved aggregator creds

  # This plugin provides management and interaction with an external session aggregator.
  class Plugin::Aggregator < Msf::Plugin
Severity: Minor
Found in plugins/aggregator.rb - About 5 hrs to fix

    Method cmd_aggregator_sessions has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

          def cmd_aggregator_sessions(*args)
            case args.length
            when 0
              is_detailed = false
            when 1
    Severity: Minor
    Found in plugins/aggregator.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

    Class AggregatorCommandDispatcher has 28 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class AggregatorCommandDispatcher
          include Msf::Ui::Console::CommandDispatcher
    
          @response_queue = []
    
    
    Severity: Minor
    Found in plugins/aggregator.rb - About 3 hrs to fix

      Method cmd_aggregator_disconnect has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

            def cmd_aggregator_disconnect(*_args)
              if @aggregator && @aggregator.available?
                # check if this connection is the default forward
                @aggregator.register_default(nil, nil) if @aggregator.default == @aggregator.uuid
      
      
      Severity: Minor
      Found in plugins/aggregator.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 cmd_aggregator_sessions has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def cmd_aggregator_sessions(*args)
              case args.length
              when 0
                is_detailed = false
              when 1
      Severity: Minor
      Found in plugins/aggregator.rb - About 1 hr to fix

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

              def aggregator_login
                if !((@host && !@host.empty?) && (@port && !@port.empty? && @port.to_i > 0))
                  usage_connect
                  return
                end
        Severity: Minor
        Found in plugins/aggregator.rb - About 1 hr to fix

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

                def cmd_aggregator_disconnect(*_args)
                  if @aggregator && @aggregator.available?
                    # check if this connection is the default forward
                    @aggregator.register_default(nil, nil) if @aggregator.default == @aggregator.uuid
          
          
          Severity: Minor
          Found in plugins/aggregator.rb - About 1 hr to fix

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

                  def cmd_aggregator_cable_add(*args)
                    host, port, certificate = nil
                    case args.length
                    when 1
                      host, port = args[0].split(':', 2)
            Severity: Minor
            Found in plugins/aggregator.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 cmd_aggregator_session_park has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def cmd_aggregator_session_park(*args)
                    return if !aggregator_verify
            
                    case args.length
                    when 1
            Severity: Minor
            Found in plugins/aggregator.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 cmd_aggregator_session_forward has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def cmd_aggregator_session_forward(*args)
                    return if !aggregator_verify
            
                    remote_id = nil
                    case args.length
            Severity: Minor
            Found in plugins/aggregator.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 cmd_aggregator_save has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def cmd_aggregator_save(*args)
                    # if we are logged in, save session details to aggregator.yaml
                    if !args.empty? || args[0] == '-h'
                      usage_save
                      return
            Severity: Minor
            Found in plugins/aggregator.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 cmd_aggregator_connect has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def cmd_aggregator_connect(*args)
                    if !args[0] && ::File.readable?(Aggregator_yaml.to_s)
                      lconfig = YAML.load_file(Aggregator_yaml.to_s)
                      @host = lconfig['default']['server']
                      @port = lconfig['default']['port']
            Severity: Minor
            Found in plugins/aggregator.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 aggregator_login has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def aggregator_login
                    if !((@host && !@host.empty?) && (@port && !@port.empty? && @port.to_i > 0))
                      usage_connect
                      return
                    end
            Severity: Minor
            Found in plugins/aggregator.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

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

                  def guess_target_platform(os)
                    case os
                    when /windows/i
                      Msf::Module::Platform::Windows.realname.downcase
                    when /darwin/i
            Severity: Major
            Found in plugins/aggregator.rb and 1 other location - About 1 hr to fix
            lib/msf/base/sessions/meterpreter.rb on lines 448..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 56.

            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 4 locations. Consider refactoring.
            Open

                  def commands
                    {
                      'aggregator_connect' => 'Connect to a running Aggregator instance ( host[:port] )',
                      'aggregator_save' => 'Save connection details to an Aggregator instance',
                      'aggregator_disconnect' => 'Disconnect from an active Aggregator instance',
            Severity: Minor
            Found in plugins/aggregator.rb and 3 other locations - About 15 mins to fix
            lib/msf/ui/console/command_dispatcher/session.rb on lines 20..32
            modules/auxiliary/admin/scada/moxa_credentials_recovery.rb on lines 56..68
            tools/modules/module_reference.rb on lines 25..37

            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