rapid7/ruby_smb

View on GitHub

Showing 307 of 307 total issues

Method smb2_authenticate has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def smb2_authenticate
        response = smb2_ntlmssp_negotiate
        challenge_packet = smb2_ntlmssp_challenge_packet(response)
        if @dialect == '0x0311'
          update_preauth_hash(challenge_packet)
Severity: Minor
Found in lib/ruby_smb/client/authentication.rb - About 1 hr to fix

    Method drs_get_nc_changes has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def drs_get_nc_changes(h_drs, nc_guid:, dsa_object_guid:)
            drs_get_nc_changes_request = DrsGetNcChangesRequest.new(
              h_drs: h_drs,
              dw_in_version: 8,
              pmsg_in: {
    Severity: Minor
    Found in lib/ruby_smb/dcerpc/drsr.rb - About 1 hr to fix

      Method compress_chunk has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def self.compress_chunk(chunk)
              blob = chunk
              out = ''
              pow2 = 0x10
              l_mask3 = 0x1002
      Severity: Minor
      Found in lib/ruby_smb/compression/lznt1.rb - About 1 hr to fix

        Method display_field has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def display_field(field, depth = 0, parents = [])
              my_parents = parents.dup
              field_str = ''
              name = field[:name]
              if field[:class] == BinData::Array
        Severity: Minor
        Found in lib/ruby_smb/generic_packet.rb - About 1 hr to fix

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

                      def share_io(method_name, request)
                        @provider.hooks.each do |hook|
                          next unless hook.request_class == request.class && hook.location == :before
          
                          request = hook.callback.call(@session, request) || request
          Severity: Minor
          Found in lib/ruby_smb/server/share/provider/processor.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 write_ref_id has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def write_ref_id(io)
                if is_alias?
                  ref_field = fetch_alias_referent
                  if ref_field
                    if ref_field.class != self.class
          Severity: Minor
          Found in lib/ruby_smb/dcerpc/ndr.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 consume_dirents has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                        def consume_dirents(local_path, dirents, filter_regex: nil)
                          until dirents.empty?
                            dirent = dirents.shift
                            next unless dirent.file? || dirent.directory? # filter out everything but files and directories
          
          
          Severity: Minor
          Found in lib/ruby_smb/server/share/provider/disk/processor/query.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 _open has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                def _open(filename:, attributes: nil, options: nil, disposition: RubySMB::Dispositions::FILE_OPEN,
                              impersonation: RubySMB::ImpersonationLevels::SEC_IMPERSONATE, read: true, write: false, delete: false)
          
                  create_request = RubySMB::SMB2::Packet::CreateRequest.new
                  create_request = set_header_fields(create_request)
          Severity: Minor
          Found in lib/ruby_smb/smb2/tree.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 dcerpc_request has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def dcerpc_request(stub_packet, auth_level: nil, auth_type: nil)
                  stub_class = stub_packet.class.name.split('::')
                  #opts.merge!(endpoint: stub_class[-2])
                  values = {
                    opnum: stub_packet.opnum,
          Severity: Minor
          Found in lib/ruby_smb/dcerpc/client.rb - About 1 hr to fix

            Method process has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                      def process(request_buffer=nil)
                        if request_buffer.nil?
                          # this is only NTLMSSP (as opposed to SPNEGO + NTLMSSP)
                          buffer = OpenSSL::ASN1::ASN1Data.new([
                            Gss::OID_SPNEGO,
            Severity: Minor
            Found in lib/ruby_smb/gss/provider/ntlm.rb - About 1 hr to fix

              Method parse has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def self.parse(defaults: {}, &block)
                      defaults = DEFAULT_OPTIONS.merge(defaults)
                      options = defaults.clone
                      OptionParser.new do |parser|
                        parser.on("--share-name SHARE_NAME", "The share name (default: #{defaults[:share_name]})") do |share|
              Severity: Minor
              Found in lib/ruby_smb/server/cli.rb - About 1 hr to fix

                Method decompress_chunk has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def self.decompress_chunk(chunk)
                        out = ''
                        until chunk.empty?
                          flags = chunk[0].unpack1('C')
                          chunk = chunk[1..-1]
                Severity: Minor
                Found in lib/ruby_smb/compression/lznt1.rb - About 1 hr to fix

                  Method proxy_share_io_smb2 has 33 lines of code (exceeds 25 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

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

                            unless @client_encryption_key
                              raise RubySMB::Error::EncryptionError.new('The encryption algorithm has not been set') if @encryption_algorithm.nil?
                    
                              key_bit_len = OpenSSL::Cipher.new(@encryption_algorithm).key_len * 8
                    
                    
                    Severity: Major
                    Found in lib/ruby_smb/client/encryption.rb and 1 other location - About 1 hr to fix
                    lib/ruby_smb/client/encryption.rb on lines 41..62

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

                    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

                            unless @server_encryption_key
                              raise RubySMB::Error::EncryptionError.new('The encryption algorithm has not been set') if @encryption_algorithm.nil?
                    
                              key_bit_len = OpenSSL::Cipher.new(@encryption_algorithm).key_len * 8
                    
                    
                    Severity: Major
                    Found in lib/ruby_smb/client/encryption.rb and 1 other location - About 1 hr to fix
                    lib/ruby_smb/client/encryption.rb on lines 6..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 57.

                    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 BitField
                          # The OptionalSupport bit-field for an SMB1 TreeConnect Response Packet
                          # [2.2.4.7.2 Server Response Extensions](https://msdn.microsoft.com/en-us/library/cc246331.aspx)
                          class OptionalSupport < BinData::Record
                    Severity: Major
                    Found in lib/ruby_smb/smb1/bit_field/optional_support.rb and 1 other location - About 1 hr to fix
                    lib/ruby_smb/smb1/bit_field/tree_connect_flags.rb on lines 2..15

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

                      module SMB1
                        module BitField
                          # The Flags bit-field for an SMB1 TreeConnect Request Packet
                          # [2.2.4.7.1 Client Request Extensions](https://msdn.microsoft.com/en-us/library/cc246330.aspx)
                          class TreeConnectFlags < BinData::Record
                    Severity: Major
                    Found in lib/ruby_smb/smb1/bit_field/tree_connect_flags.rb and 1 other location - About 1 hr to fix
                    lib/ruby_smb/smb1/bit_field/optional_support.rb on lines 2..15

                    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

                    Method parse_smb3_capabilities has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                          def parse_smb3_capabilities(response_packet)
                            nc = response_packet.find_negotiate_context(
                              RubySMB::SMB2::NegotiateContext::SMB2_PREAUTH_INTEGRITY_CAPABILITIES
                            )
                            @preauth_integrity_hash_algorithm = RubySMB::SMB2::PreauthIntegrityCapabilities::HASH_ALGORITM_MAP[nc&.data&.hash_algorithms&.first]
                    Severity: Minor
                    Found in lib/ruby_smb/client/negotiation.rb - About 1 hr to fix

                      Method do_session_setup_andx_smb1 has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                              def do_session_setup_andx_smb1(request, session)
                                session_id = request.smb_header.uid
                                if session_id == 0
                                  session_id = rand(1..0x10000)
                                  session = @session_table[session_id] = Server::Session.new(session_id)
                      Severity: Minor
                      Found in lib/ruby_smb/server/server_client/session_setup.rb - About 1 hr to fix

                        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

                        Severity
                        Category
                        Status
                        Source
                        Language