rapid7/metasploit-framework

View on GitHub
lib/rex/post/meterpreter/packet_dispatcher.rb

Summary

Maintainability
F
4 days
Test Coverage

Method monitor_socket has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring.
Open

  def monitor_socket

    # Skip if we are using a passive dispatcher
    return if self.passive_service

Severity: Minor
Found in lib/rex/post/meterpreter/packet_dispatcher.rb - About 1 day 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

File packet_dispatcher.rb has 462 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'rex/post/meterpreter/command_mapper'
require 'rex/post/meterpreter/packet_response_waiter'
require 'rex/exceptions'
require 'pathname'

Severity: Minor
Found in lib/rex/post/meterpreter/packet_dispatcher.rb - About 7 hrs to fix

    Method monitor_socket has 87 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def monitor_socket
    
        # Skip if we are using a passive dispatcher
        return if self.passive_service
    
    
    Severity: Major
    Found in lib/rex/post/meterpreter/packet_dispatcher.rb - About 3 hrs to fix

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

        def send_packet_wait_response(packet, timeout)
          if packet.type == PACKET_TYPE_REQUEST && commands.present?
            # XXX: Remove this condition once the payloads gem has had another major version bump from 2.x to 3.x and
            # rapid7/metasploit-payloads#451 has been landed to correct the `enumextcmd` behavior on Windows. Until then, skip
            # proactive validation of Windows core commands. This is not the only instance of this workaround.
      Severity: Minor
      Found in lib/rex/post/meterpreter/packet_dispatcher.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 send_packet has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def send_packet(packet, opts={})
          if self.pivot_session
            opts[:session_guid] = self.session_guid
            opts[:tlv_enc_key] = self.tlv_enc_key
            return self.pivot_session.send_packet(packet, opts)
      Severity: Minor
      Found in lib/rex/post/meterpreter/packet_dispatcher.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 send_packet has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def send_packet(packet, opts={})
          if self.pivot_session
            opts[:session_guid] = self.session_guid
            opts[:tlv_enc_key] = self.tlv_enc_key
            return self.pivot_session.send_packet(packet, opts)
      Severity: Minor
      Found in lib/rex/post/meterpreter/packet_dispatcher.rb - About 1 hr to fix

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

          def on_passive_request(cli, req)
        
            begin
        
            resp = Rex::Proto::Http::Response.new(200, "OK")
        Severity: Minor
        Found in lib/rex/post/meterpreter/packet_dispatcher.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 dispatch_inbound_packet has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def dispatch_inbound_packet(packet)
            handled = false
        
            log_packet(packet, :recv)
        
        
        Severity: Minor
        Found in lib/rex/post/meterpreter/packet_dispatcher.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 on_passive_request has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def on_passive_request(cli, req)
        
            begin
        
            resp = Rex::Proto::Http::Response.new(200, "OK")
        Severity: Minor
        Found in lib/rex/post/meterpreter/packet_dispatcher.rb - About 1 hr to fix

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

            def send_packet_wait_response(packet, timeout)
              if packet.type == PACKET_TYPE_REQUEST && commands.present?
                # XXX: Remove this condition once the payloads gem has had another major version bump from 2.x to 3.x and
                # rapid7/metasploit-payloads#451 has been landed to correct the `enumextcmd` behavior on Windows. Until then, skip
                # proactive validation of Windows core commands. This is not the only instance of this workaround.
          Severity: Minor
          Found in lib/rex/post/meterpreter/packet_dispatcher.rb - About 1 hr to fix

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

              def log_packet_to_file(packet, packet_type)
                pathname = ::Pathname.new(self.tlv_log_file_path.split('file:').last)
            
                begin
                  if self.tlv_log_file.nil? || self.tlv_log_file.path != pathname.to_s
            Severity: Minor
            Found in lib/rex/post/meterpreter/packet_dispatcher.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 pivot_keepalive_start has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def pivot_keepalive_start
                return unless self.send_keepalives
                self.receiver_thread = Rex::ThreadFactory.spawn("PivotKeepalive", false) do
                  while self.alive
                    begin
            Severity: Minor
            Found in lib/rex/post/meterpreter/packet_dispatcher.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

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

                    rescue ::Exception => e
                      dlog("Exception caught in monitor_socket: #{e.class}: #{e}", 'meterpreter', LEV_1)
                      dlog("Call stack: #{e.backtrace.join("\n")}", 'meterpreter', LEV_2)
                      self.alive = false
                      break
            Severity: Minor
            Found in lib/rex/post/meterpreter/packet_dispatcher.rb and 1 other location - About 20 mins to fix
            lib/rex/post/meterpreter/packet_dispatcher.rb on lines 287..292

            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

                    rescue ::Exception => e
                      dlog("Exception caught in pivot keepalive: #{e.class}: #{e}", 'meterpreter', LEV_1)
                      dlog("Call stack: #{e.backtrace.join("\n")}", 'meterpreter', LEV_2)
                      self.alive = false
                      break
            Severity: Minor
            Found in lib/rex/post/meterpreter/packet_dispatcher.rb and 1 other location - About 20 mins to fix
            lib/rex/post/meterpreter/packet_dispatcher.rb on lines 332..337

            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

            There are no issues that match your filters.

            Category
            Status