rapid7/ruby_smb

View on GitHub

Showing 171 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

              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

                File winreg.rb has 295 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                module RubySMB
                  module Dcerpc
                    module Winreg
                
                      UUID = '338CD001-2244-31F1-AAAA-900038001003'
                Severity: Minor
                Found in lib/ruby_smb/dcerpc/winreg.rb - About 3 hrs to fix

                  Method do_create_smb2 has 76 lines of code (exceeds 25 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: Major
                  Found in lib/ruby_smb/server/share/provider/disk/processor/create.rb - About 3 hrs to fix

                    Method ioctl_send_recv has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def ioctl_send_recv(action, options={})
                            request = set_header_fields(RubySMB::SMB2::Packet::IoctlRequest.new(options))
                            request.ctl_code = 0x0011C017
                            request.flags.is_fsctl = 0x00000001
                            # TODO: handle fragmentation when the request size > MAX_XMIT_FRAG
                    Severity: Minor
                    Found in lib/ruby_smb/smb2/pipe.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

                    File svcctl.rb has 287 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    module RubySMB
                      module Dcerpc
                        module Svcctl
                    
                          UUID = '367abb81-9844-35f1-ad32-98f038001003'
                    Severity: Minor
                    Found in lib/ruby_smb/dcerpc/svcctl.rb - About 2 hrs to fix

                      Method build_fscc_file_information has 72 lines of code (exceeds 25 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: Major
                      Found in lib/ruby_smb/server/share/provider/disk/processor.rb - About 2 hrs to fix

                        Method _handle_smb2 has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                        Open

                              def _handle_smb2(raw_request)
                                begin
                                  header = RubySMB::SMB2::SMB2Header.read(raw_request)
                                rescue IOError => e
                                  logger.error("Caught a #{e.class} while reading the SMB2 header (#{e.message})")
                        Severity: Minor
                        Found in lib/ruby_smb/server/server_client.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 recv_packet has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                        Open

                              def recv_packet(full_response: false)
                                raise RubySMB::Error::CommunicationError, 'Connection has already been closed' if @tcp_socket.closed?
                                if IO.select([@tcp_socket], nil, nil, @read_timeout).nil?
                                  raise RubySMB::Error::CommunicationError, "Read timeout expired when reading from the Socket (timeout=#{@read_timeout})"
                                end
                        Severity: Minor
                        Found in lib/ruby_smb/dispatcher/socket.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