rapid7/metasploit-framework

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

Summary

Maintainability
F
5 days
Test Coverage

File client_core.rb has 562 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'rex/post/meterpreter/packet'
require 'rex/post/meterpreter/core_ids'
require 'rex/post/meterpreter/extension'
require 'rex/post/meterpreter/extension_mapper'
require 'rex/post/meterpreter/client'
Severity: Major
Found in lib/rex/post/meterpreter/client_core.rb - About 1 day to fix

    Method transport_prepare_request has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
    Open

      def transport_prepare_request(method, opts={})
        unless valid_transport?(opts[:transport]) && opts[:lport]
          return nil
        end
    
    
    Severity: Minor
    Found in lib/rex/post/meterpreter/client_core.rb - About 6 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 use has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

      def use(mod, opts = { })
        if mod.nil?
          raise RuntimeError, "No modules were specified", caller
        end
    
    
    Severity: Minor
    Found in lib/rex/post/meterpreter/client_core.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

    Class ClientCore has 32 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class ClientCore < Extension
    
      METERPRETER_TRANSPORT_TCP   = 0
      METERPRETER_TRANSPORT_HTTP  = 1
      METERPRETER_TRANSPORT_HTTPS = 2
    Severity: Minor
    Found in lib/rex/post/meterpreter/client_core.rb - About 4 hrs to fix

      Method migrate has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

        def migrate(target_pid, writable_dir = nil, opts = {})
          keepalive              = client.send_keepalives
          client.send_keepalives = false
          target_process         = nil
          current_process        = nil
      Severity: Minor
      Found in lib/rex/post/meterpreter/client_core.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 load_library has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

        def load_library(opts)
          library_path = opts['LibraryFilePath']
          library_image = opts['LibraryFileImage']
          target_path  = opts['TargetFilePath']
          load_flags   = LOAD_LIBRARY_FLAG_LOCAL
      Severity: Minor
      Found in lib/rex/post/meterpreter/client_core.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 migrate has 67 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def migrate(target_pid, writable_dir = nil, opts = {})
          keepalive              = client.send_keepalives
          client.send_keepalives = false
          target_process         = nil
          current_process        = nil
      Severity: Major
      Found in lib/rex/post/meterpreter/client_core.rb - About 2 hrs to fix

        Method transport_prepare_request has 64 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def transport_prepare_request(method, opts={})
            unless valid_transport?(opts[:transport]) && opts[:lport]
              return nil
            end
        
        
        Severity: Major
        Found in lib/rex/post/meterpreter/client_core.rb - About 2 hrs to fix

          Method load_library has 59 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def load_library(opts)
              library_path = opts['LibraryFilePath']
              library_image = opts['LibraryFileImage']
              target_path  = opts['TargetFilePath']
              load_flags   = LOAD_LIBRARY_FLAG_LOCAL
          Severity: Major
          Found in lib/rex/post/meterpreter/client_core.rb - About 2 hrs to fix

            Method use has 58 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def use(mod, opts = { })
                if mod.nil?
                  raise RuntimeError, "No modules were specified", caller
                end
            
            
            Severity: Major
            Found in lib/rex/post/meterpreter/client_core.rb - About 2 hrs to fix

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

                def generate_migrate_stub(target_process)
                  stub = nil
              
              
                  if client.platform == 'windows' && [ARCH_X86, ARCH_X64].include?(client.arch)
              Severity: Minor
              Found in lib/rex/post/meterpreter/client_core.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 generate_migrate_stub has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def generate_migrate_stub(target_process)
                  stub = nil
              
              
                  if client.platform == 'windows' && [ARCH_X86, ARCH_X64].include?(client.arch)
              Severity: Minor
              Found in lib/rex/post/meterpreter/client_core.rb - About 1 hr to fix

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

                  def get_loaded_extension_commands(extension)
                    request = Packet.create_request(COMMAND_ID_CORE_ENUMEXTCMD)
                
                    # handle 'core' as a special case since it's not a typical extension
                    extension = EXTENSION_ID_CORE if extension == 'core'
                Severity: Minor
                Found in lib/rex/post/meterpreter/client_core.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

                        c.include(::Msf::Payload::Windows::BlockApi_x64)
                        case t[:url]
                        when /^tcp/i
                          c.include(::Msf::Payload::Windows::MigrateTcp_x64)
                        when /^pipe/i
                Severity: Minor
                Found in lib/rex/post/meterpreter/client_core.rb and 1 other location - About 40 mins to fix
                lib/rex/post/meterpreter/client_core.rb on lines 812..820

                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 38.

                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

                        c.include(::Msf::Payload::Windows::BlockApi)
                        case t[:url]
                        when /^tcp/i
                          c.include(::Msf::Payload::Windows::MigrateTcp)
                        when /^pipe/i
                Severity: Minor
                Found in lib/rex/post/meterpreter/client_core.rb and 1 other location - About 40 mins to fix
                lib/rex/post/meterpreter/client_core.rb on lines 823..831

                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 38.

                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