rapid7/metasploit-framework

View on GitHub
lib/msf/core/post/windows/services.rb

Summary

Maintainability
F
3 days
Test Coverage

File services.rb has 434 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Msf
  class Post
    module Windows
      # @deprecated Use {Services} instead
      module WindowsServices
Severity: Minor
Found in lib/msf/core/post/windows/services.rb - About 6 hrs to fix

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

            def meterpreter_service_list
              if session.commands.include?(Rex::Post::Meterpreter::Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_ENUM_KEY)
                begin
                  return session.extapi.service.enumerate
                rescue Rex::Post::Meterpreter::RequestError => e
    Severity: Minor
    Found in lib/msf/core/post/windows/services.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

    Class Post has 23 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Post
        module Windows
          # @deprecated Use {Services} instead
          module WindowsServices
            def self.included(_base)
    Severity: Minor
    Found in lib/msf/core/post/windows/services.rb - About 2 hrs to fix

      Method service_restart has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

              def service_restart(name, start_type = START_TYPE_AUTO, server = nil, should_retry = true)
                status = service_start(name, server)
      
                if status == Error::SUCCESS
                  vprint_good("[#{name}] Service started")
      Severity: Minor
      Found in lib/msf/core/post/windows/services.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 meterpreter_service_list has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def meterpreter_service_list
                if session.commands.include?(Rex::Post::Meterpreter::Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_ENUM_KEY)
                  begin
                    return session.extapi.service.enumerate
                  rescue Rex::Post::Meterpreter::RequestError => e
      Severity: Minor
      Found in lib/msf/core/post/windows/services.rb - About 1 hr to fix

        Method service_create has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

                def service_create(name, opts, server = nil)
                  access = 'SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS'
                  open_sc_manager(host: server, access: access) do |manager|
                    opts[:display] ||= Rex::Text.rand_text_alpha(8)
                    opts[:desired_access] ||= 'SERVICE_START'
        Severity: Minor
        Found in lib/msf/core/post/windows/services.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 each_service has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

                def each_service(&block)
                  if session.commands.include?(Rex::Post::Meterpreter::Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_ENUM_KEY)
                    begin
                      return session.extapi.service.enumerate.each(&block)
                    rescue Rex::Post::Meterpreter::RequestError => e
        Severity: Minor
        Found in lib/msf/core/post/windows/services.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 service_restart has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def service_restart(name, start_type = START_TYPE_AUTO, server = nil, should_retry = true)
                  status = service_start(name, server)
        
                  if status == Error::SUCCESS
                    vprint_good("[#{name}] Service started")
        Severity: Minor
        Found in lib/msf/core/post/windows/services.rb - About 1 hr to fix

          Method service_create has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  def service_create(name, opts, server = nil)
                    access = 'SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS'
                    open_sc_manager(host: server, access: access) do |manager|
                      opts[:display] ||= Rex::Text.rand_text_alpha(8)
                      opts[:desired_access] ||= 'SERVICE_START'
          Severity: Minor
          Found in lib/msf/core/post/windows/services.rb - About 1 hr to fix

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

                    def service_change_startup(name, mode, server = nil)
                      if mode.is_a? Integer
                        startup_number = mode
                      else
                        case mode.downcase
            Severity: Minor
            Found in lib/msf/core/post/windows/services.rb - About 1 hr to fix

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

                      def service_change_startup(name, mode, server = nil)
                        if mode.is_a? Integer
                          startup_number = mode
                        else
                          case mode.downcase
              Severity: Minor
              Found in lib/msf/core/post/windows/services.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 open_sc_manager has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                      def open_sc_manager(opts = {})
                        host = opts[:host] || nil
                        access = opts[:access] || 'SC_MANAGER_ALL_ACCESS'
                        machine_str = host ? "\\\\#{host}" : nil
              
              
              Severity: Minor
              Found in lib/msf/core/post/windows/services.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 _shell_service_start has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                      def _shell_service_start(service_name, server = nil)
                        host = server ? "\\\\#{server}" : nil
                        timeout = 75 # sc.exe default RPC connection timeout 60 seconds + cmd_exec default timeout 15 seconds
              
                        fingerprint = Rex::Text.rand_text_alphanumeric(6..8)
              Severity: Minor
              Found in lib/msf/core/post/windows/services.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 _shell_service_stop has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                      def _shell_service_stop(service_name, server = nil)
                        host = server ? "\\\\#{server}" : nil
                        timeout = 75 # sc.exe default RPC connection timeout 60 seconds + cmd_exec default timeout 15 seconds
              
                        fingerprint = Rex::Text.rand_text_alphanumeric(6..8)
              Severity: Minor
              Found in lib/msf/core/post/windows/services.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

              Avoid too many return statements within this method.
              Open

                          return 2
              Severity: Major
              Found in lib/msf/core/post/windows/services.rb - About 30 mins to fix

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

                        def service_info(name)
                          if session.commands.include?(Rex::Post::Meterpreter::Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_QUERY_VALUE)
                            begin
                              return session.extapi.service.query(name)
                            rescue Rex::Post::Meterpreter::RequestError => e
                Severity: Minor
                Found in lib/msf/core/post/windows/services.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

                There are no issues that match your filters.

                Category
                Status