rapid7/metasploit-framework

View on GitHub
lib/msf/core/post/windows/powershell.rb

Summary

Maintainability
C
1 day
Test Coverage

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

        def get_ps_output(cmd_out, eof, read_wait = 5)
          results = ''

          if datastore['Powershell::Post::log_output']
            # Get target's computer name
Severity: Minor
Found in lib/msf/core/post/windows/powershell.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 psh_exec has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

        def psh_exec(script, greedy_kill = true, ps_cleanup = true)
          # Define vars
          eof = Rex::Text.rand_text_alpha(8)
          # eof = "THIS__SCRIPT_HAS__COMPLETED_EXECUTION#{rand(100)}"
          env_suffix = Rex::Text.rand_text_alpha(8)
Severity: Minor
Found in lib/msf/core/post/windows/powershell.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 stage_psh_env has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def stage_psh_env(script)
          begin
            ps_script = read_script(script)
            encoded_expression = encode_script(ps_script)
            cleanup_commands = []
Severity: Minor
Found in lib/msf/core/post/windows/powershell.rb - About 1 hr to fix

    Method psh_exec has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def psh_exec(script, greedy_kill = true, ps_cleanup = true)
              # Define vars
              eof = Rex::Text.rand_text_alpha(8)
              # eof = "THIS__SCRIPT_HAS__COMPLETED_EXECUTION#{rand(100)}"
              env_suffix = Rex::Text.rand_text_alpha(8)
    Severity: Minor
    Found in lib/msf/core/post/windows/powershell.rb - About 1 hr to fix

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

              def get_powershell_version
                return nil unless have_powershell?
      
                process, _pid, _c = execute_script('$PSVersionTable.PSVersion')
      
      
      Severity: Minor
      Found in lib/msf/core/post/windows/powershell.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 execute_script has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

              def execute_script(script, greedy_kill = false)
                @session_pids ||= []
                running_pids = greedy_kill ? get_ps_pids : []
                open_channels = []
                # Execute using -EncodedCommand
      Severity: Minor
      Found in lib/msf/core/post/windows/powershell.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 clean_up has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

              def clean_up(script_file = nil, eof = '', running_pids = [], open_channels = [],
                           env_suffix = Rex::Text.rand_text_alpha(8), delete = false)
      Severity: Minor
      Found in lib/msf/core/post/windows/powershell.rb - About 45 mins to fix

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

                def clean_up(script_file = nil, eof = '', running_pids = [], open_channels = [],
                             env_suffix = Rex::Text.rand_text_alpha(8), delete = false)
                  # Remove environment variables
                  env_del_command =  "[Environment]::GetEnvironmentVariables('User').keys|"
                  env_del_command += "Select-String #{env_suffix}|%{"
        Severity: Minor
        Found in lib/msf/core/post/windows/powershell.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

        There are no issues that match your filters.

        Category
        Status