rapid7/metasploit-framework

View on GitHub
lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb

Summary

Maintainability
D
2 days
Test Coverage

Method download_file has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

  def File.download_file(dest_file, src_file, opts = {}, &stat)
    stat ||= lambda { |a,b,c| }

    adaptive = opts["adaptive"]
    block_size = opts["block_size"] || 1024 * 1024
Severity: Minor
Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.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 file.rb has 321 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'rex/post/file'
require 'rex/post/meterpreter/channel'
require 'rex/post/meterpreter/channels/pools/file'
require 'rex/post/meterpreter/extensions/stdapi/stdapi'
require 'rex/post/meterpreter/extensions/stdapi/fs/io'
Severity: Minor
Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb - About 3 hrs to fix

    Method download_file has 89 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def File.download_file(dest_file, src_file, opts = {}, &stat)
        stat ||= lambda { |a,b,c| }
    
        adaptive = opts["adaptive"]
        block_size = opts["block_size"] || 1024 * 1024
    Severity: Major
    Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb - About 3 hrs to fix

      Class File has 24 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
      
        include Rex::Post::File
      
        MIN_BLOCK_SIZE = 1024
      Severity: Minor
      Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb - About 2 hrs to fix

        Method download has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

          def File.download(dest, src_files, opts = {}, &stat)
            dest.force_encoding('UTF-8')
            timestamp = opts["timestamp"]
            [*src_files].each { |src|
              src.force_encoding('UTF-8')
        Severity: Minor
        Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.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 upload has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          def File.upload(dest, *src_files, &stat)
            src_files.each { |src|
              if (self.basename(dest) != ::File.basename(src))
                dest += self.separator unless dest.end_with?(self.separator)
                dest += ::File.basename(src)
        Severity: Minor
        Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.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 upload_file has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def File.upload_file(dest_file, src_file, &stat)
            # Open the file on the remote side for writing and read
            # all of the contents of the local file
            stat.call('Uploading', src_file, dest_file) if stat
            dest_fd = nil
        Severity: Minor
        Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb - About 55 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 search has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def File.search( root=nil, glob="*.*", recurse=true, timeout=-1, modified_start_date=nil, modified_end_date=nil)
        Severity: Minor
        Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb - About 45 mins to fix

          Method expand_path has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def File.expand_path(path)
              case client.platform
                when 'osx', 'freebsd', 'bsd', 'linux', 'android', 'apple_ios'
                  # For unix-based systems, do some of the work here
                  # First check for ~
          Severity: Minor
          Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb - About 45 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 search has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def File.search( root=nil, glob="*.*", recurse=true, timeout=-1, modified_start_date=nil, modified_end_date=nil)
          
              files = ::Array.new
          
              request = Packet.create_request( COMMAND_ID_STDAPI_FS_SEARCH )
          Severity: Minor
          Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb - About 25 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

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

            def File.sha1(path)
              request = Packet.create_request(COMMAND_ID_STDAPI_FS_SHA1)
          
              request.add_tlv(TLV_TYPE_FILE_PATH, client.unicode_filter_decode( path ))
          
          
          Severity: Minor
          Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb and 1 other location - About 20 mins to fix
          lib/rex/post/meterpreter/extensions/stdapi/fs/file.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 27.

          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

            def File.md5(path)
              request = Packet.create_request(COMMAND_ID_STDAPI_FS_MD5)
          
              request.add_tlv(TLV_TYPE_FILE_PATH, client.unicode_filter_decode( path ))
          
          
          Severity: Minor
          Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb and 1 other location - About 20 mins to fix
          lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb on lines 189..199

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

          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

            def File.cp(oldname, newname)
              request = Packet.create_request(COMMAND_ID_STDAPI_FS_FILE_COPY)
          
              request.add_tlv(TLV_TYPE_FILE_NAME, client.unicode_filter_decode( oldname ))
              request.add_tlv(TLV_TYPE_FILE_PATH, client.unicode_filter_decode( newname ))
          Severity: Minor
          Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb and 1 other location - About 15 mins to fix
          lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb on lines 238..246

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

          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

            def File.mv(oldname, newname)
              request = Packet.create_request(COMMAND_ID_STDAPI_FS_FILE_MOVE)
          
              request.add_tlv(TLV_TYPE_FILE_NAME, client.unicode_filter_decode( oldname ))
              request.add_tlv(TLV_TYPE_FILE_PATH, client.unicode_filter_decode( newname ))
          Severity: Minor
          Found in lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb and 1 other location - About 15 mins to fix
          lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb on lines 257..265

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

          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

          There are no issues that match your filters.

          Category
          Status