rapid7/metasploit-framework

View on GitHub
lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb

Summary

Maintainability
F
1 wk
Test Coverage

File fs.rb has 691 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'tempfile'
require 'filesize'
require 'rex/post/meterpreter'
require 'rex/post/meterpreter/extensions/stdapi/command_ids'
require 'msf/ui/console/local_file_system'
Severity: Major
Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb - About 1 day to fix

    Method cmd_download has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
    Open

      def cmd_download(*args)
        if (args.empty? or args.include? "-h")
          cmd_download_help
          return true
        end
    Severity: Minor
    Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb - About 1 day 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_path has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

      def list_path(path, columns, sort, order, short, recursive = false, depth = 0, search_term = nil)
    
        # avoid infinite recursion
        if depth > 100
          return
    Severity: Minor
    Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.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

    Method cmd_upload has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

      def cmd_upload(*args)
        if (args.empty? or args.include?("-h"))
          cmd_upload_help
          return true
        end
    Severity: Minor
    Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.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

    Class Fs has 33 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Console::CommandDispatcher::Stdapi::Fs
    
      Klass = Console::CommandDispatcher::Stdapi::Fs
    
      include Console::CommandDispatcher
    Severity: Minor
    Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb - About 4 hrs to fix

      Method cmd_download has 99 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def cmd_download(*args)
          if (args.empty? or args.include? "-h")
            cmd_download_help
            return true
          end
      Severity: Major
      Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb - About 3 hrs to fix

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

          def cmd_search(*args)
        
            root    = nil
            recurse = true
            globs   = []
        Severity: Minor
        Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.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 cmd_search has 67 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def cmd_search(*args)
        
            root    = nil
            recurse = true
            globs   = []
        Severity: Major
        Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb - About 2 hrs to fix

          Method cmd_ls has 54 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def cmd_ls(*args)
              # Set defaults
              path = client.fs.dir.getwd
              search_term = nil
              sort = 'Name'
          Severity: Major
          Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb - About 2 hrs to fix

            Method cmd_upload has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def cmd_upload(*args)
                if (args.empty? or args.include?("-h"))
                  cmd_upload_help
                  return true
                end
            Severity: Minor
            Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb - About 2 hrs to fix

              Method cmd_ls has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                def cmd_ls(*args)
                  # Set defaults
                  path = client.fs.dir.getwd
                  search_term = nil
                  sort = 'Name'
              Severity: Minor
              Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.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_path has 45 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def list_path(path, columns, sort, order, short, recursive = false, depth = 0, search_term = nil)
              
                  # avoid infinite recursion
                  if depth > 100
                    return
              Severity: Minor
              Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb - About 1 hr to fix

                Method commands has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def commands
                    all = {
                      'cat'        => 'Read the contents of a file to the screen',
                      'cd'         => 'Change directory',
                      'checksum'   => 'Retrieve the checksum of a file',
                Severity: Minor
                Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb - About 1 hr to fix

                  Method cmd_show_mount has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def cmd_show_mount(*args)
                      if args.include?('-h')
                        print_line('Usage: show_mount')
                        return true
                      end
                  Severity: Minor
                  Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb - About 1 hr to fix

                    Method tab_complete_path has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def tab_complete_path(str, words, dir_only)
                        if client.platform == 'windows'
                            ::Readline.completion_case_fold = true
                        end
                        if client.commands.include?(COMMAND_ID_STDAPI_FS_LS)
                    Severity: Minor
                    Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.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_path has 8 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      def list_path(path, columns, sort, order, short, recursive = false, depth = 0, search_term = nil)
                    Severity: Major
                    Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb - About 1 hr to fix

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

                        def cmd_cat(*args)
                          if (args.length == 0)
                            print_line("Usage: cat file")
                            return true
                          end
                      Severity: Minor
                      Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.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 cmd_checksum has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def cmd_checksum(*args)
                          algorithm = args.shift
                          algorithm.downcase! unless algorithm.nil?
                          unless args.length > 0 and CHECKSUM_ALGORITHMS.include?(algorithm)
                            print_line("Usage: checksum [#{ CHECKSUM_ALGORITHMS.join(' / ') }] file1 file2 file3 ...")
                      Severity: Minor
                      Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.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

                      Avoid too many return statements within this method.
                      Open

                            return
                      Severity: Major
                      Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb - About 30 mins to fix

                        Method cmd_edit has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def cmd_edit(*args)
                            if args.empty? || args.include?('-h')
                              cmd_edit_help
                              return true
                            end
                        Severity: Minor
                        Found in lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.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 cmd_cp(*args)
                            if (args.length < 2)
                              print_line("Usage: cp oldfile newfile")
                              return true
                            end
                        lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb on lines 373..383

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

                        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 cmd_mv(*args)
                            if (args.length < 2)
                              print_line("Usage: mv oldfile newfile")
                              return true
                            end
                        lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb on lines 396..406

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

                        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

                            all = {
                              'cat'        => 'Read the contents of a file to the screen',
                              'cd'         => 'Change directory',
                              'checksum'   => 'Retrieve the checksum of a file',
                              'del'        => 'Delete the specified file',
                        lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb on lines 18..37

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

                        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

                                  client.fs.file.download(dest, src, opts) do |step, src, dst|
                                    print_status("#{step.ljust(11)}: #{src} -> #{dst}")
                                    client.framework.events.on_session_download(client, src, dest) if msf_loaded?
                                  end
                        lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb on lines 524..527
                        lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb on lines 859..862

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

                        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

                                    client.fs.file.download(dest_path, src_path, opts) do |step, src, dst|
                                      print_status("#{step.ljust(11)}: #{src} -> #{dst}")
                                      client.framework.events.on_session_download(client, src, dest) if msf_loaded?
                                    end
                        lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb on lines 556..559
                        lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb on lines 859..862

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

                        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

                                client.fs.dir.upload(dest, src, recursive) { |step, src, dst|
                                  print_status("#{step.ljust(11)}: #{src} -> #{dst}")
                                  client.framework.events.on_session_upload(client, src, dest) if msf_loaded?
                                }
                        lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb on lines 524..527
                        lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb on lines 556..559

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

                        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

                                  client.fs.file.upload(dest, src) { |step, src, dst|
                                    print_status("#{step.ljust(11)}: #{src} -> #{dst}")
                                    client.framework.events.on_session_upload(client, src, dest) if msf_loaded?
                                  }
                        lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb on lines 403..406
                        lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb on lines 870..873

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

                        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

                                  client.fs.file.upload_file(dest, src) { |step, src, dst|
                                    print_status("#{step.ljust(11)}: #{src} -> #{dst}")
                                    client.framework.events.on_session_upload(client, src, dest) if msf_loaded?
                                  }
                        lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb on lines 403..406
                        lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb on lines 865..868

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

                        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