rapid7/ruby_smb

View on GitHub

Showing 310 of 310 total issues

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

            def build_fscc_file_information(path, info_class, rename: nil)
              case info_class
              when Fscc::FileInformation::FILE_ACCESS_INFORMATION
                info = Fscc::FileInformation::FileAccessInformation.new
                # smb2_access_mask returns back either file or directory access mask depending on what path is,
Severity: Minor
Found in lib/ruby_smb/server/share/provider/disk/processor.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 process_ntlm_type3 has 63 lines of code (exceeds 25 allowed). Consider refactoring.
Open

          def process_ntlm_type3(type3_msg)
            if type3_msg.user == '' && type3_msg.domain == ''
              if @provider.allow_anonymous
                @session_key = "\x00".b * 16 # see MS-NLMP section 3.4
                return WindowsError::NTStatus::STATUS_SUCCESS
Severity: Major
Found in lib/ruby_smb/gss/provider/ntlm.rb - About 2 hrs to fix

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

      module Dcerpc
        # The Bind ACK PDU as defined in
        # [The bind_ack PDU](http://pubs.opengroup.org/onlinepubs/9629399/chap12.htm#tagcjh_17_06_04_04)
        class BindAck < BinData::Record
          PTYPE = PTypes::BIND_ACK
    Severity: Major
    Found in lib/ruby_smb/dcerpc/bind_ack.rb and 1 other location - About 2 hrs to fix
    lib/ruby_smb/dcerpc/alter_context_resp.rb on lines 2..38

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

    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 Dcerpc
        # The Alter context resp PDU as defined in
        # [The alter_context_resp PDU](https://pubs.opengroup.org/onlinepubs/9629399/chap12.htm#tagcjh_17_06_04_02)
    
        class AlterContextResp < BinData::Record
    Severity: Major
    Found in lib/ruby_smb/dcerpc/alter_context_resp.rb and 1 other location - About 2 hrs to fix
    lib/ruby_smb/dcerpc/bind_ack.rb on lines 2..37

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

    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 do_query_directory_smb2 has 62 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

                  def do_query_directory_smb2(request)
                    local_path = get_local_path(request.file_id)
                    if local_path.nil?
                      response = RubySMB::SMB2::Packet::ErrorPacket.new
                      response.smb2_header.nt_status = WindowsError::NTStatus::STATUS_FILE_CLOSED
    Severity: Major
    Found in lib/ruby_smb/server/share/provider/disk/processor/query.rb - About 2 hrs to fix

      Method list has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def list(directory: '\\', pattern: '*', unicode: true,
                     type: RubySMB::SMB1::Packet::Trans2::FindInformationLevel::FindFileFullDirectoryInfo)
              find_first_request = RubySMB::SMB1::Packet::Trans2::FindFirst2Request.new
              find_first_request = set_header_fields(find_first_request)
              find_first_request.smb_header.flags2.unicode  = 1 if unicode
      Severity: Major
      Found in lib/ruby_smb/smb1/tree.rb - About 2 hrs to fix

        Method list has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

              def list(directory: '\\', pattern: '*', unicode: true,
                       type: RubySMB::SMB1::Packet::Trans2::FindInformationLevel::FindFileFullDirectoryInfo)
                find_first_request = RubySMB::SMB1::Packet::Trans2::FindFirst2Request.new
                find_first_request = set_header_fields(find_first_request)
                find_first_request.smb_header.flags2.unicode  = 1 if unicode
        Severity: Minor
        Found in lib/ruby_smb/smb1/tree.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 decompress_chunk has a Cognitive Complexity of 18 (exceeds 5 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 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 do_negotiate_smb2 has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

                def do_negotiate_smb2(request)
                  client_dialects = request.dialects.map { |d| "0x%04x" % d }
                  server_dialects = @server.dialects.select { |dialect| Dialect[dialect].order == Dialect::ORDER_SMB2 }
                  dialect = (server_dialects & client_dialects).first
        
        
        Severity: Minor
        Found in lib/ruby_smb/server/server_client/negotiation.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 parse has a Cognitive Complexity of 18 (exceeds 5 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 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 handle_smb has 60 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def handle_smb(raw_request)
                response = nil
        
                case raw_request[0...4].unpack1('L>')
                when RubySMB::SMB1::SMB_PROTOCOL_ID
        Severity: Major
        Found in lib/ruby_smb/server/server_client.rb - About 2 hrs to fix

          Class VirtualPathname has 22 methods (exceeds 20 allowed). Consider refactoring.
          Open

                    class VirtualPathname
                      SEPARATOR = File::SEPARATOR
                      # see: https://ruby-doc.org/stdlib-3.1.1/libdoc/pathname/rdoc/Pathname.html
                      STAT_METHODS = %i[
                        atime
          Severity: Minor
          Found in lib/ruby_smb/server/share/provider/virtual_disk/virtual_pathname.rb - About 2 hrs to fix

            Class Client has 22 methods (exceeds 20 allowed). Consider refactoring.
            Open

              class Client
                # This module holds all the backend client methods for authentication.
                module Authentication
                  include RubySMB::PeerInfo
            
            
            Severity: Minor
            Found in lib/ruby_smb/client/authentication.rb - About 2 hrs to fix

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

                      def do_session_setup_smb2(request, session)
                        @smb2_related_operations_state.delete(:session_id)
              
                        session_id = request.smb2_header.session_id
                        if session_id == 0
              Severity: Minor
              Found in lib/ruby_smb/server/server_client/session_setup.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 dcerpc_request has 55 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def dcerpc_request(stub_packet, options={})
                      options.merge!(endpoint: stub_packet.class.name.split('::').at(-2))
                      dcerpc_request = RubySMB::Dcerpc::Request.new({ opnum: stub_packet.opnum }, options)
                      dcerpc_request.stub.read(stub_packet.to_binary_s)
                      if options[:auth_level] &&
              Severity: Major
              Found in lib/ruby_smb/smb1/pipe.rb - About 2 hrs to fix

                Method parse_negotiate_response has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def parse_negotiate_response(packet)
                        case packet
                        when RubySMB::SMB1::Packet::NegotiateResponseExtended
                          self.smb1 = true
                          self.smb2 = false
                Severity: Major
                Found in lib/ruby_smb/client/negotiation.rb - About 2 hrs to fix

                  Method transaction2_smb1_query_information has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                  Open

                                def transaction2_smb1_query_information(request, response, local_path)
                                  unless local_path&.exist?
                                    response = SMB1::Packet::EmptyPacket.new
                                    response.smb_header.nt_status = WindowsError::NTStatus::STATUS_NO_SUCH_FILE
                                    return response
                  Severity: Minor
                  Found in lib/ruby_smb/server/share/provider/disk/processor/query.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 process_ntlm_type3 has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                  Open

                            def process_ntlm_type3(type3_msg)
                              if type3_msg.user == '' && type3_msg.domain == ''
                                if @provider.allow_anonymous
                                  @session_key = "\x00".b * 16 # see MS-NLMP section 3.4
                                  return WindowsError::NTStatus::STATUS_SUCCESS
                  Severity: Minor
                  Found in lib/ruby_smb/gss/provider/ntlm.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 compress_chunk has a Cognitive Complexity of 16 (exceeds 5 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 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 negotiate_response has a Cognitive Complexity of 16 (exceeds 5 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 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

                  Severity
                  Category
                  Status
                  Source
                  Language