rapid7/ruby_smb

View on GitHub

Showing 301 of 301 total issues

File ndr.rb has 1018 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module RubySMB::Dcerpc::Ndr

  require 'ruby_smb/field'

  # NDR Syntax
Severity: Major
Found in lib/ruby_smb/dcerpc/ndr.rb - About 2 days to fix

    File samr.rb has 715 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module RubySMB
      module Dcerpc
        module Samr
    
          UUID = '12345778-1234-abcd-ef00-0123456789ac'
    Severity: Major
    Found in lib/ruby_smb/dcerpc/samr.rb - About 1 day to fix

      File drsr.rb has 673 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      module RubySMB
        module Dcerpc
          module Drsr
      
            UUID = 'E3514235-4B06-11D1-AB04-00C04FC2DCD2'
      Severity: Major
      Found in lib/ruby_smb/dcerpc/drsr.rb - About 1 day to fix

        Method handle_smb has a Cognitive Complexity of 42 (exceeds 5 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: Minor
        Found in lib/ruby_smb/server/server_client.rb - About 6 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 send_recv has a Cognitive Complexity of 37 (exceeds 5 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 5 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

        File client.rb has 355 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        module RubySMB
          # Represents an SMB client capable of talking to SMB1 or SMB2 servers and handling
          # all end-user client functionality.
          class Client
            require 'ruby_smb/ntlm'
        Severity: Minor
        Found in lib/ruby_smb/client.rb - About 4 hrs to fix

          File server_client.rb has 345 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          module RubySMB
            class Server
              # This class represents a single connected client to the server. It stores and processes connection specific related
              # information.
              class ServerClient
          Severity: Minor
          Found in lib/ruby_smb/server/server_client.rb - About 4 hrs to fix

            Method parse_negotiate_response has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
            Open

                  def parse_negotiate_response(packet)
                    case packet
                    when RubySMB::SMB1::Packet::NegotiateResponseExtended
                      self.smb1 = true
                      self.smb2 = false
            Severity: Minor
            Found in lib/ruby_smb/client/negotiation.rb - About 4 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

            Class VirtualStat has 32 methods (exceeds 20 allowed). Consider refactoring.
            Open

                      class VirtualStat
            
                        # All of the keyword arguments are the keys of the attributes to set. The names are left as is, maintaining
                        # a direct 1 to 1 relationship. See the Ruby docs for File::Stat
                        # (https://ruby-doc.org/core-3.0.2/File/Stat.html) for a list of all the attributes that can be set. Some
            Severity: Minor
            Found in lib/ruby_smb/server/share/provider/virtual_disk/virtual_stat.rb - About 4 hrs to fix

              Method do_create_smb2 has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
              Open

                            def do_create_smb2(request)
                              unless request.create_disposition == RubySMB::Dispositions::FILE_OPEN
                                logger.warn("Can not handle CREATE request for disposition: #{request.create_disposition}")
                                raise NotImplementedError
                              end
              Severity: Minor
              Found in lib/ruby_smb/server/share/provider/disk/processor/create.rb - About 3 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

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

                module SMB2
                  module BitField
                    # An Access Mask bit field used to describe the permissions on a File, Printer, or named Pipe. As defined in
                    # [2.2.13.1.1 File_Pipe_Printer_Access_Mask](https://msdn.microsoft.com/en-us/library/cc246802.aspx)
                    class FileAccessMask < BinData::Record
              Severity: Major
              Found in lib/ruby_smb/smb2/bit_field/file_access_mask.rb and 3 other locations - About 3 hrs to fix
              lib/ruby_smb/smb1/bit_field/directory_access_mask.rb on lines 2..35
              lib/ruby_smb/smb1/bit_field/file_access_mask.rb on lines 2..35
              lib/ruby_smb/smb2/bit_field/directory_access_mask.rb on lines 2..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 119.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

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

                module SMB1
                  module BitField
                    # An Access Mask bit field used to describe the permissions on a Directory, as defined in
                    # [2.2.1.4.2 Directory_Access_Mask](https://msdn.microsoft.com/en-us/library/ff470234.aspx)
                    class DirectoryAccessMask < BinData::Record
              Severity: Major
              Found in lib/ruby_smb/smb1/bit_field/directory_access_mask.rb and 3 other locations - About 3 hrs to fix
              lib/ruby_smb/smb1/bit_field/file_access_mask.rb on lines 2..35
              lib/ruby_smb/smb2/bit_field/directory_access_mask.rb on lines 2..35
              lib/ruby_smb/smb2/bit_field/file_access_mask.rb on lines 2..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 119.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

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

                module SMB1
                  module BitField
                    # An Access Mask bit field used to describe the permissions on a File, Printer, or named Pipe. As defined in
                    # [2.2.1.4.1 File_Pipe_Printer_Access_Mask](https://msdn.microsoft.com/en-us/library/ff469915.aspx)
                    class FileAccessMask < BinData::Record
              Severity: Major
              Found in lib/ruby_smb/smb1/bit_field/file_access_mask.rb and 3 other locations - About 3 hrs to fix
              lib/ruby_smb/smb1/bit_field/directory_access_mask.rb on lines 2..35
              lib/ruby_smb/smb2/bit_field/directory_access_mask.rb on lines 2..35
              lib/ruby_smb/smb2/bit_field/file_access_mask.rb on lines 2..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 119.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

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

                module SMB2
                  module BitField
                    # An Access Mask bit field used to describe the permissions on a Directory, as defined in
                    # [2.2.13.1.2 Directory_Access_Mask](https://msdn.microsoft.com/en-us/library/cc246801.aspx)
                    class DirectoryAccessMask < BinData::Record
              Severity: Major
              Found in lib/ruby_smb/smb2/bit_field/directory_access_mask.rb and 3 other locations - About 3 hrs to fix
              lib/ruby_smb/smb1/bit_field/directory_access_mask.rb on lines 2..35
              lib/ruby_smb/smb1/bit_field/file_access_mask.rb on lines 2..35
              lib/ruby_smb/smb2/bit_field/file_access_mask.rb on lines 2..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 119.

              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

              optparser = OptionParser.new do |opts|
                opts.banner = "Usage: #{File.basename(__FILE__)} [options] target command"
                opts.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{options[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1|
                  options[:smbv1] = smbv1
                end
              Severity: Major
              Found in examples/pwsh_service.rb and 2 other locations - About 3 hrs to fix
              examples/read_file.rb on lines 27..46
              examples/tree_connect.rb on lines 25..44

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

              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

              optparser = OptionParser.new do |opts|
                opts.banner = "Usage: #{File.basename(__FILE__)} [options] target share"
                opts.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{options[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1|
                  options[:smbv1] = smbv1
                end
              Severity: Major
              Found in examples/tree_connect.rb and 2 other locations - About 3 hrs to fix
              examples/pwsh_service.rb on lines 29..48
              examples/read_file.rb on lines 27..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 115.

              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

              optparser = OptionParser.new do |opts|
                opts.banner = "Usage: #{File.basename(__FILE__)} [options] target share file"
                opts.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{options[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1|
                  options[:smbv1] = smbv1
                end
              Severity: Major
              Found in examples/read_file.rb and 2 other locations - About 3 hrs to fix
              examples/pwsh_service.rb on lines 29..48
              examples/tree_connect.rb on lines 25..44

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

              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

              File query.rb has 297 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              require 'ruby_smb/server/share/provider/processor'
              
              module RubySMB
                class Server
                  module Share
              Severity: Minor
              Found in lib/ruby_smb/server/share/provider/disk/processor/query.rb - About 3 hrs to fix

                Method dcerpc_request has a Cognitive Complexity of 22 (exceeds 5 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: Minor
                Found in lib/ruby_smb/smb1/pipe.rb - About 3 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 transaction2_smb1_find_first2 has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
                Open

                              def transaction2_smb1_find_first2(request)
                                # see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-cifs/f93455dc-2bd7-4698-b91e-8c9c7abd63cf
                                raise ArgumentError unless request.data_block.trans2_parameters.is_a? SMB1::Packet::Trans2::FindFirst2RequestTrans2Parameters
                
                                subdir, _, search_pattern = request.data_block.trans2_parameters.filename.encode.gsub('\\', File::SEPARATOR).rpartition(File::SEPARATOR)
                Severity: Minor
                Found in lib/ruby_smb/server/share/provider/disk/processor/query.rb - About 3 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