rapid7/metasploit-framework

View on GitHub
lib/msf/base/sessions/command_shell.rb

Summary

Maintainability
F
3 days
Test Coverage

File command_shell.rb has 534 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'shellwords'
require 'rex/text/table'
require "base64"

module Msf
Severity: Major
Found in lib/msf/base/sessions/command_shell.rb - About 1 day to fix

    Class CommandShell has 44 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class CommandShell
    
      #
      # This interface supports basic interaction.
      #
    Severity: Minor
    Found in lib/msf/base/sessions/command_shell.rb - About 6 hrs to fix

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

        def cmd_upload(*args)
          if args.length != 2
            # no arguments, just print help message
            return cmd_upload_help
          end
      Severity: Minor
      Found in lib/msf/base/sessions/command_shell.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 cmd_resource has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def cmd_resource(*args)
          if args.empty? || args[0] == '-h' || args[0] == '--help'
            cmd_resource_help
            return false
          end
      Severity: Minor
      Found in lib/msf/base/sessions/command_shell.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 bootstrap has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def bootstrap(datastore = {}, handler = nil)
          session = self
      
          if datastore['AutoVerifySession']
            session_info = ''
      Severity: Minor
      Found in lib/msf/base/sessions/command_shell.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 _interact_stream has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def _interact_stream
          fds = [rstream.fd, user_input.fd]
      
          # Displays +info+ on all session startups
          # +info+ is set to the shell banner and initial prompt in the +bootstrap+ method
      Severity: Minor
      Found in lib/msf/base/sessions/command_shell.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 cmd_resource has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def cmd_resource(*args)
          if args.empty? || args[0] == '-h' || args[0] == '--help'
            cmd_resource_help
            return false
          end
      Severity: Minor
      Found in lib/msf/base/sessions/command_shell.rb - About 1 hr to fix

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

          def bootstrap(datastore = {}, handler = nil)
            session = self
        
            if datastore['AutoVerifySession']
              session_info = ''
        Severity: Minor
        Found in lib/msf/base/sessions/command_shell.rb - About 1 hr to fix

          Method cmd_shell has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def cmd_shell(*args)
              if args.length == 1 && (args[0] == '-h' || args[0] == '--help')
                # One arg, and args[0] => '-h' '--help'
                return cmd_shell_help
              end
          Severity: Minor
          Found in lib/msf/base/sessions/command_shell.rb - About 1 hr to fix

            Method cleanup has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def cleanup
                return if @cleanup
            
                @cleanup = true
                if rstream
            Severity: Minor
            Found in lib/msf/base/sessions/command_shell.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 cmd_help has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def cmd_help(*args)
                cmd = args.shift
            
                if cmd
                  unless commands.key?(cmd)
            Severity: Minor
            Found in lib/msf/base/sessions/command_shell.rb - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method cmd_shell has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def cmd_shell(*args)
                if args.length == 1 && (args[0] == '-h' || args[0] == '--help')
                  # One arg, and args[0] => '-h' '--help'
                  return cmd_shell_help
                end
            Severity: Minor
            Found in lib/msf/base/sessions/command_shell.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/msf/base/sessions/command_shell.rb - About 30 mins to fix

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

                def cmd_sessions(*args)
                  if args.length != 1
                    print_status "Wrong number of arguments expected: 1, received: #{args.length}"
                    return cmd_sessions_help
                  end
              Severity: Minor
              Found in lib/msf/base/sessions/command_shell.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

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

                def cmd_irb(*args)
                  expressions = []
              
                  # Parse the command options
                  @@irb_opts.parse(args) do |opt, idx, val|
              Severity: Minor
              Found in lib/msf/base/sessions/command_shell.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

                    sd = Rex::ThreadSafe.select(fds, nil, fds, 0.5)
                    next unless sd
              
                    if sd[0].include? rstream.fd
                      user_output.print(shell_read)
              Severity: Minor
              Found in lib/msf/base/sessions/command_shell.rb and 1 other location - About 40 mins to fix
              lib/msf/base/sessions/ssh_command_shell_reverse.rb on lines 58..67

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

              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

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

                        ::Msf::Config.script_directory + ::File::SEPARATOR + 'resource' + ::File::SEPARATOR + 'meterpreter',
                        ::Msf::Config.user_script_directory + ::File::SEPARATOR + 'resource' + ::File::SEPARATOR + 'meterpreter'
                    ].each do |dir|
              Severity: Minor
              Found in lib/msf/base/sessions/command_shell.rb and 1 other location - About 20 mins to fix
              lib/msf/ui/console/command_dispatcher/session.rb on lines 214..216

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

              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

                    args = Shellwords.shellwords( datastore['AutoRunScript'] )
                    print_status("Session ID #{sid} (#{tunnel_to_s}) processing AutoRunScript '#{datastore['AutoRunScript']}'")
                    execute_script(args.shift, *args)
              Severity: Minor
              Found in lib/msf/base/sessions/command_shell.rb and 1 other location - About 15 mins to fix
              lib/msf/base/sessions/command_shell.rb on lines 724..726

              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

                    args = Shellwords.shellwords( datastore['InitialAutoRunScript'] )
                    print_status("Session ID #{sid} (#{tunnel_to_s}) processing InitialAutoRunScript '#{datastore['InitialAutoRunScript']}'")
                    execute_script(args.shift, *args)
              Severity: Minor
              Found in lib/msf/base/sessions/command_shell.rb and 1 other location - About 15 mins to fix
              lib/msf/base/sessions/command_shell.rb on lines 730..732

              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