rapid7/ruby_smb

View on GitHub

Showing 307 of 307 total issues

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

optparser = OptionParser.new do |opts|
  opts.banner = "Usage: #{File.basename(__FILE__)} [options] target"
  opts.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{options[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1|
    options[:smbv1] = smbv1
  end
Severity: Major
Found in examples/anonymous_auth.rb and 1 other location - About 1 hr to fix
examples/auth_capture.rb on lines 16..25

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

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

OptionParser.new do |opts|
  opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
  opts.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{options[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1|
    options[:smbv1] = smbv1
  end
Severity: Major
Found in examples/auth_capture.rb and 1 other location - About 1 hr to fix
examples/anonymous_auth.rb on lines 34..43

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

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

    def send_recv(packet, encrypt: false)
      version = packet.packet_smb_version
      case version
      when 'SMB1'
        packet.smb_header.uid = self.user_id if self.user_id
Severity: Minor
Found in lib/ruby_smb/client.rb - About 1 hr to fix

    Method get_host_port_from_ept_mapper has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def get_host_port_from_ept_mapper(uuid:, maj_ver:, min_ver:, max_towers: 1)
            decoded_tower = EpmDecodedTowerOctetString.new(
              interface_identifier: {
                interface: uuid,
                major_version: maj_ver,
    Severity: Minor
    Found in lib/ruby_smb/dcerpc/epm.rb - About 1 hr to fix

      Method cert_server_request has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def cert_server_request(attributes:, authority:, csr:)
              cert_server_request_request = CertServerRequestRequest.new(
                pwsz_authority: authority,
                pctb_attribs: { pb: (RubySMB::Utils.safe_encode(attributes.map { |k,v| "#{k}:#{v}" }.join("\n"), 'UTF-16le').force_encoding('ASCII-8bit') + "\x00\x00".b) },
                pctb_request: { pb: csr.to_der }
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/icpr.rb - About 1 hr to fix

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

              def run
                loop do
                  begin
                    raw_request = recv_packet
                  rescue RubySMB::Error::CommunicationError
        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 dcerpc_request has a Cognitive Complexity of 13 (exceeds 5 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

        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_read has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def do_read(io, is_deferred: false)
              if is_deferred
                if is_a?(NdrStruct) && self.class.superclass.has_conformant_array
                  # align :max_count since it will be placed in front of the structure.
                  # The structure itself will be properly aligned later.
        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 oid_from_attid has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

                def oid_from_attid(attr_typ)
                  upper_word = attr_typ / 0x10000
                  lower_word = attr_typ % 0x10000
                  prefix_table = self.prefix_table_src.p_prefix_entry
                  binary_oid = nil
        Severity: Minor
        Found in lib/ruby_smb/dcerpc/drsr.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_write has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def do_write(io, is_deferred: false)
              if is_deferred
                if is_a?(NdrStruct) && self.class.superclass.has_conformant_array
                  # align :max_count since it will be placed in front of the structure.
                  # The structure itself will be properly aligned later.
        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 list has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

              def list(directory: nil, pattern: '*', type: RubySMB::Fscc::FileInformation::FileIdFullDirectoryInformation)
                create_response = open_directory(directory: directory)
                opened_directory = RubySMB::SMB2::File.new(tree: self, response: create_response, name: directory)
                file_id         = create_response.file_id
        
        
        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 do_negotiate_smb1 has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def do_negotiate_smb1(request)
                  client_dialects = request.dialects.map(&:dialect_string).map(&:value)
        
                  if client_dialects.include?(Client::SMB1_DIALECT_SMB2_WILDCARD) && \
                      @server.dialects.any? { |dialect| Dialect[dialect].order == Dialect::ORDER_SMB2 }
        Severity: Minor
        Found in lib/ruby_smb/server/server_client/negotiation.rb - About 1 hr to fix

          Method do_session_setup_smb2 has 38 lines of code (exceeds 25 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 1 hr to fix

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

                  def list(directory: nil, pattern: '*', type: RubySMB::Fscc::FileInformation::FileIdFullDirectoryInformation)
                    create_response = open_directory(directory: directory)
                    opened_directory = RubySMB::SMB2::File.new(tree: self, response: create_response, name: directory)
                    file_id         = create_response.file_id
            
            
            Severity: Minor
            Found in lib/ruby_smb/smb2/tree.rb - About 1 hr to fix

              Method process_gss_type3 has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                        def process_gss_type3(gss_api)
                          neg_token_init = Hash[RubySMB::Gss.asn1dig(gss_api, 0).value.map { |obj| [obj.tag, obj.value[0].value] }]
                          raw_type3_msg = neg_token_init[2]
              
                          type3_msg = Net::NTLM::Message.parse(raw_type3_msg)
              Severity: Minor
              Found in lib/ruby_smb/gss/provider/ntlm.rb - About 1 hr to fix

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

                            if response.is_a?(SMB1::Packet::EmptyPacket)
                              response.smb_header.command = header.command if response.smb_header.command == 0
                              response.smb_header.flags.reply = 1
                              nt_status = response.smb_header.nt_status.to_i
                              message = "Sending an error packet for SMB1 command: #{SMB1::Commands.name(header.command)}, status: 0x#{nt_status.to_s(16).rjust(8, '0')}"
                Severity: Major
                Found in lib/ruby_smb/server/server_client.rb and 1 other location - About 1 hr to fix
                lib/ruby_smb/server/server_client.rb on lines 433..441

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

                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

                          if response.is_a?(SMB2::Packet::ErrorPacket)
                            response.smb2_header.command = header.command if response.smb2_header.command == 0
                            response.smb2_header.flags.reply = 1
                            nt_status = response.smb2_header.nt_status.to_i
                            message = "Sending an error packet for SMB2 command: #{SMB2::Commands.name(header.command)}, status: 0x#{nt_status.to_s(16).rjust(8, '0')}"
                Severity: Major
                Found in lib/ruby_smb/server/server_client.rb and 1 other location - About 1 hr to fix
                lib/ruby_smb/server/server_client.rb on lines 101..109

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

                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

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

                      def dcerpc_response_from_raw_response(raw_data)
                        dcerpc_response = RubySMB::Dcerpc::Response.read(raw_data)
                        if dcerpc_response.pdu_header.ptype == RubySMB::Dcerpc::PTypes::FAULT
                          status = dcerpc_response.stub.unpack('V').first
                          raise RubySMB::Dcerpc::Error::FaultError.new('A fault occurred', status: status)
                Severity: Major
                Found in lib/ruby_smb/smb2/pipe.rb and 1 other location - About 1 hr to fix
                lib/ruby_smb/smb1/pipe.rb on lines 173..183

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

                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

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

                      def dcerpc_response_from_raw_response(raw_data)
                        dcerpc_response = RubySMB::Dcerpc::Response.read(raw_data)
                        if dcerpc_response.pdu_header.ptype == RubySMB::Dcerpc::PTypes::FAULT
                          status = dcerpc_response.stub.unpack('V').first
                          raise RubySMB::Dcerpc::Error::FaultError.new('A fault occurred', status: status)
                Severity: Major
                Found in lib/ruby_smb/smb1/pipe.rb and 1 other location - About 1 hr to fix
                lib/ruby_smb/smb2/pipe.rb on lines 171..181

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

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

                    def initialize(dispatcher, smb1: true, smb2: true, smb3: true, username:, password:, domain: '.',
                                   local_workstation: 'WORKSTATION', always_encrypt: true, ntlm_flags: NTLM::DEFAULT_CLIENT_FLAGS)
                      raise ArgumentError, 'No Dispatcher provided' unless dispatcher.is_a? RubySMB::Dispatcher::Base
                      if smb1 == false && smb2 == false && smb3 == false
                        raise ArgumentError, 'You must enable at least one Protocol'
                Severity: Minor
                Found in lib/ruby_smb/client.rb - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language