rapid7/ruby_smb

View on GitHub

Showing 310 of 310 total issues

Method initialize has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

            def initialize(disk, path, **kwargs)
              @virtual_disk = disk
              @path = path

              if kwargs.fetch(:exist?, true)
Severity: Minor
Found in lib/ruby_smb/server/share/provider/virtual_disk/virtual_pathname.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 proxy_share_io_smb2 has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

        def proxy_share_io_smb2(request, session)
          if request.smb2_header.flags.related_operations == 0
            # see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/9a639360-87be-4d49-a1dd-4c6be0c020bd
            share_processor = session.tree_connect_table[request.smb2_header.tree_id]
            @smb2_related_operations_state[:tree_id] = request.smb2_header.tree_id
Severity: Minor
Found in lib/ruby_smb/server/server_client/share_io.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 handle_smb2 has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def handle_smb2(raw_request, header)
        session_required = !(header.command == SMB2::Commands::SESSION_SETUP && header.session_id == 0)

        if header.flags.related_operations == 0
          @smb2_related_operations_state.clear
Severity: Minor
Found in lib/ruby_smb/server/server_client.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 do_tree_connect_smb2 has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def do_tree_connect_smb2(request, session)
          @smb2_related_operations_state.delete(:tree_id)

          response = RubySMB::SMB2::Packet::TreeConnectResponse.new
          response.smb2_header.credits = 1
Severity: Minor
Found in lib/ruby_smb/server/server_client/tree_connect.rb - About 1 hr to fix

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

          def add_smb3_to_negotiate_request(packet, dialects = SMB3_DIALECT_DEFAULT)
            dialects.each do |dialect|
              raise ArgumentError, 'Must be an array of strings' unless dialect.is_a? String
              packet.add_dialect(dialect.to_i(16))
            end
    Severity: Minor
    Found in lib/ruby_smb/client/negotiation.rb - About 1 hr to fix

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

            def _handle_smb2(raw_request)
              begin
                header = RubySMB::SMB2::SMB2Header.read(raw_request)
              rescue IOError => e
                logger.error("Caught a #{e.class} while reading the SMB2 header (#{e.message})")
      Severity: Minor
      Found in lib/ruby_smb/server/server_client.rb - About 1 hr to fix

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

              module Trans2
                # Transaction2 subcommand constants as defined in
                # [2.2.6 Transaction2 Subcommands](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-cifs/1cc40e02-aaea-4f33-b7b7-3a6b63906516)
                module Subcommands
                  OPEN2                    = 0x0000
        Severity: Major
        Found in lib/ruby_smb/smb1/packet/trans2/subcommands.rb and 1 other location - About 1 hr to fix
        lib/ruby_smb/smb1/commands.rb on lines 2..23

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

        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

          module SMB1
            module Commands
              SMB_COM_CLOSE                   = 0x04
              SMB_COM_TRANSACTION             = 0x25
              SMB_COM_ECHO                    = 0x2B
        Severity: Major
        Found in lib/ruby_smb/smb1/commands.rb and 1 other location - About 1 hr to fix
        lib/ruby_smb/smb1/packet/trans2/subcommands.rb on lines 4..27

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

        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

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

            def bind(options={})
              @call_id ||= 1
              bind_req = Bind.new(options)
              bind_req.pdu_header.call_id = @call_id
              auth_type = options.fetch(:auth_type) { RPC_C_AUTHN_WINNT }
        Severity: Minor
        Found in lib/ruby_smb/dcerpc.rb - About 1 hr to fix

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

                def negotiate_response(raw_data)
                  response = nil
                  if smb1
                    packet = RubySMB::SMB1::Packet::NegotiateResponseExtended.read raw_data
          
          
          Severity: Minor
          Found in lib/ruby_smb/client/negotiation.rb - About 1 hr to fix

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

                  def samr_rid_to_sid(object_handle:, rid:)
                    samr_rid_to_sid_request = SamrRidToSidRequest.new(
                      object_handle: object_handle,
                      rid: rid
                    )
            Severity: Major
            Found in lib/ruby_smb/dcerpc/samr.rb and 3 other locations - About 1 hr to fix
            lib/ruby_smb/dcerpc/lsarpc.rb on lines 562..578
            lib/ruby_smb/dcerpc/lsarpc.rb on lines 581..597
            lib/ruby_smb/dcerpc/samr.rb on lines 636..652

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

            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 lsar_query_information_policy(policy_handle:, information_class:)
                    lsar_request = LsarQueryInformationPolicyRequest.new(
                      policy_handle: policy_handle,
                      information_class: information_class
                    )
            Severity: Major
            Found in lib/ruby_smb/dcerpc/lsarpc.rb and 3 other locations - About 1 hr to fix
            lib/ruby_smb/dcerpc/lsarpc.rb on lines 581..597
            lib/ruby_smb/dcerpc/samr.rb on lines 636..652
            lib/ruby_smb/dcerpc/samr.rb on lines 831..847

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

            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 samr_lookup_domain(server_handle:, name:)
                    samr_lookup_domain_in_sam_server_request = SamrLookupDomainInSamServerRequest.new(
                      server_handle: server_handle,
                      name: name
                    )
            Severity: Major
            Found in lib/ruby_smb/dcerpc/samr.rb and 3 other locations - About 1 hr to fix
            lib/ruby_smb/dcerpc/lsarpc.rb on lines 562..578
            lib/ruby_smb/dcerpc/lsarpc.rb on lines 581..597
            lib/ruby_smb/dcerpc/samr.rb on lines 831..847

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

            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 lsar_query_information_policy2(policy_handle:, information_class:)
                    lsar_request = LsarQueryInformationPolicy2Request.new(
                      policy_handle: policy_handle,
                      information_class: information_class
                    )
            Severity: Major
            Found in lib/ruby_smb/dcerpc/lsarpc.rb and 3 other locations - About 1 hr to fix
            lib/ruby_smb/dcerpc/lsarpc.rb on lines 562..578
            lib/ruby_smb/dcerpc/samr.rb on lines 636..652
            lib/ruby_smb/dcerpc/samr.rb on lines 831..847

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

            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

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

                  def drs_crack_names(h_drs, flags: 0, format_offered: DS_SID_OR_SID_HISTORY_NAME, format_desired: DS_UNIQUE_ID_NAME, rp_names: [])
                    drs_crack_names_request = DrsCrackNamesRequest.new(
                      h_drs: h_drs,
                      pmsg_in: {
                        switch_type: 1,
            Severity: Minor
            Found in lib/ruby_smb/dcerpc/drsr.rb - About 1 hr to fix

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

                    def query_value(handle, value_name)
                      query_value_request_packet = RubySMB::Dcerpc::Winreg::QueryValueRequest.new(hkey: handle, lp_value_name: value_name)
                      query_value_request_packet.lp_type = 0
                      query_value_request_packet.lpcb_data = 0
                      query_value_request_packet.lpcb_len = 0
              Severity: Minor
              Found in lib/ruby_smb/dcerpc/winreg.rb - About 1 hr to fix

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

                      def read(bytes: @size, offset: 0)
                        atomic_read_size = [bytes, @tree.client.max_buffer_size].min
                        remaining_bytes = bytes
                        data = ''
                
                
                Severity: Minor
                Found in lib/ruby_smb/smb1/file.rb - About 1 hr to fix

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

                          def encrypt(unencrypted_data, key, algorithm: 'AES-128-GCM')
                            if unencrypted_data.is_a? BinData::Record
                              unencrypted_data = unencrypted_data.to_binary_s
                            end
                  
                  
                  Severity: Minor
                  Found in lib/ruby_smb/smb2/packet/transform_header.rb - About 1 hr to fix

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

                          def samr_lookup_names_in_domain(domain_handle:, names:)
                            raise ArgumentError.new('names may not be longer than 1000') if names.length > 1000
                    
                            samr_lookup_request = SamrLookupNamesInDomainRequest.new(
                              domain_handle: domain_handle,
                    Severity: Minor
                    Found in lib/ruby_smb/dcerpc/samr.rb - About 1 hr to fix

                      Method write has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def write(data:, offset: 0)
                              buffer = data.dup
                              bytes  = data.length
                              total_bytes_written = 0
                      
                      
                      Severity: Minor
                      Found in lib/ruby_smb/smb1/file.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

                      Severity
                      Category
                      Status
                      Source
                      Language