rapid7/ruby_smb

View on GitHub

Showing 307 of 307 total issues

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

case svc_config.dw_error_control
when RubySMB::Dcerpc::Svcctl::SERVICE_ERROR_IGNORE
  error_control << 'SERVICE_ERROR_IGNORE'
when RubySMB::Dcerpc::Svcctl::SERVICE_ERROR_NORMAL
  error_control << 'SERVICE_ERROR_NORMAL'
Severity: Minor
Found in examples/query_service_status.rb and 1 other location - About 45 mins to fix
examples/query_service_status.rb on lines 51..59

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

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

          struct :flags do
            bit3  :reserved,    label: 'Reserved Space'
            bit1  :backup,      label: 'With Backup Intent'
            bit1  :continue,    label: 'Continue From Last'
            bit1  :resume_keys, label: 'Return Resume Keys'
Severity: Major
Found in lib/ruby_smb/smb1/packet/trans2/find_next2_request.rb and 2 other locations - About 45 mins to fix
lib/ruby_smb/smb1/packet/trans2/find_first2_request.rb on lines 12..21
lib/ruby_smb/smb2/packet/create_request.rb on lines 26..35

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

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

case svc_config.dw_service_type
when RubySMB::Dcerpc::Svcctl::SERVICE_KERNEL_DRIVER
  service_type << 'Driver service'
when RubySMB::Dcerpc::Svcctl::SERVICE_FILE_SYSTEM_DRIVER
  service_type << 'File system driver service'
Severity: Minor
Found in examples/query_service_status.rb and 1 other location - About 45 mins to fix
examples/query_service_status.rb on lines 75..83

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

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

          case @dialect
          when '0x0300', '0x0302'
            server_encryption_key = RubySMB::Crypto::KDF.counter_mode(
              session.key,
              "SMB2AESCCM\x00",
Severity: Minor
Found in lib/ruby_smb/server/server_client/encryption.rb and 1 other location - About 45 mins to fix
lib/ruby_smb/server/server_client/encryption.rb on lines 42..58

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

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

        struct :share_access do
          bit5  :reserved,          label: 'Reserved Space'
          bit1  :delete_access,     label: 'Share Delete Access'
          bit1  :write_access,      label: 'Share Write Access'
          bit1  :read_access,       label: 'Share Read Access'
Severity: Major
Found in lib/ruby_smb/smb2/packet/create_request.rb and 2 other locations - About 45 mins to fix
lib/ruby_smb/smb1/packet/trans2/find_first2_request.rb on lines 12..21
lib/ruby_smb/smb1/packet/trans2/find_next2_request.rb on lines 14..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 39.

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

          case @dialect
          when '0x0300', '0x0302'
            client_encryption_key = RubySMB::Crypto::KDF.counter_mode(
              session.key,
              "SMB2AESCCM\x00",
Severity: Minor
Found in lib/ruby_smb/server/server_client/encryption.rb and 1 other location - About 45 mins to fix
lib/ruby_smb/server/server_client/encryption.rb on lines 12..28

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

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 run_negotiation has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

def run_negotiation(address, smb1, smb2, smb3, netbios_name)
Severity: Minor
Found in examples/negotiate_with_netbios_service.rb - About 35 mins to fix

    Method run_negotiation has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def run_negotiation(address, smb1, smb2, smb3, opts = {})
    Severity: Minor
    Found in examples/negotiate.rb - About 35 mins to fix

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

                choice            :data_block, selection: -> { parameter_block.setup.first || :default } do
                  open2_request_data_block                  Subcommands::OPEN2
                  find_first2_request_data_block            Subcommands::FIND_FIRST2
                  find_next2_request_data_block             Subcommands::FIND_NEXT2
                  query_file_information_request_data_block Subcommands::QUERY_FILE_INFORMATION
      Severity: Minor
      Found in lib/ruby_smb/smb1/packet/trans2/request.rb and 1 other location - About 35 mins to fix
      lib/ruby_smb/smb1/packet/trans2/response.rb on lines 37..46

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

      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

                choice            :data_block, selection: -> { parameter_block.setup.first || :default } do
                  open2_response_data_block                  Subcommands::OPEN2
                  find_first2_response_data_block            Subcommands::FIND_FIRST2
                  find_next2_response_data_block             Subcommands::FIND_NEXT2
                  query_file_information_response_data_block Subcommands::QUERY_FILE_INFORMATION
      Severity: Minor
      Found in lib/ruby_smb/smb1/packet/trans2/response.rb and 1 other location - About 35 mins to fix
      lib/ruby_smb/smb1/packet/trans2/request.rb on lines 50..59

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

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

            def send_packet(packet, nbss_header: true)
              data = nbss_header ? nbss(packet) : ''
              data << packet.to_binary_s
              bytes_written = 0
              begin
      Severity: Minor
      Found in lib/ruby_smb/dispatcher/socket.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 handle_negotiate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

              def handle_negotiate(raw_request)
                response = nil
                case raw_request[0...4].unpack1('L>')
                when RubySMB::SMB1::SMB_PROTOCOL_ID
                  request = SMB1::Packet::NegotiateRequest.read(raw_request)
      Severity: Minor
      Found in lib/ruby_smb/server/server_client/negotiation.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 enum_registry_key has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def enum_registry_key(key, bind: true)
              bind(endpoint: RubySMB::Dcerpc::Winreg) if bind
      
              root_key, sub_key = key.gsub(/\//, '\\').split('\\', 2)
              root_key_handle = open_root_key(root_key)
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/winreg.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 do_num_bytes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def do_num_bytes
            sum = 0
      
            if should_process_max_count?
              # count max_count (4 bytes)
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.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 decompress has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def self.decompress(buf, length_check: true)
              out = ''
              until buf.empty?
                header = buf.unpack1('v')
                length = (header & 0xfff) + 1
      Severity: Minor
      Found in lib/ruby_smb/compression/lznt1.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 compress has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

            def self.compress(buf, chunk_size: 0x1000)
              out = ''
              until buf.empty?
                chunk = buf[0...chunk_size]
                compressed = compress_chunk(chunk)
      Severity: Minor
      Found in lib/ruby_smb/compression/lznt1.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 do_write has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def do_write(io)
            if should_process_max_count?
              max_count = retrieve_max_count
              io.writebytes([max_count].pack('L<')) if max_count
      
      
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.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 add_attrtyp_from_oid has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

              def add_attrtyp_from_oid(oid, to_field: :p_partial_attr_set)
                last_value = oid.split('.').last.to_i
                binary_oid = OpenSSL::ASN1::ObjectId.new(oid).to_der[2..-1]
                if last_value < 128
                  oid_prefix = binary_oid[0...-1].bytes
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/drsr.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 do_transactions2_smb1 has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

                    def do_transactions2_smb1(request)
                      # can't find an example where more than one setup is set, this code makes alot of assumptions that there
                      # are exactly 0 or 1 entries
                      if request.parameter_block.setup.length > 1
                        raise NotImplementedError, 'There are more than 1 TRANSACTION2 setup values'
      Severity: Minor
      Found in lib/ruby_smb/server/share/provider/disk/processor/query.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 add has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

                def add(virtual_pathname)
                  raise ArgumentError.new('paths must be absolute') unless virtual_pathname.absolute?
      
                  path = virtual_pathname.to_s
                  raise ArgumentError.new('paths must be normalized') unless VirtualPathname.cleanpath(path) == path
      Severity: Minor
      Found in lib/ruby_smb/server/share/provider/virtual_disk.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

      Severity
      Category
      Status
      Source
      Language