rapid7/metasploit-framework

View on GitHub
modules/exploits/multi/kubernetes/exec.rb

Summary

Maintainability
D
2 days
Test Coverage

Method initialize has 97 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def initialize(info = {})
    super(
      update_info(
        info,
        'Name' => 'Kubernetes authenticated code execution',
Severity: Major
Found in modules/exploits/multi/kubernetes/exec.rb - About 3 hrs to fix

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

      def create_pod
        if datastore['PodImage'].blank?
          image_names = @kubernetes_client.list_pods(namespace).fetch(:items, []).flat_map { |pod| pod.dig(:spec, :containers).map { |container| container[:image] } }.uniq
          fail_with(Failure::NotFound, 'An image could not be found from which to create a pod, set the PodImage option') if image_names.empty?
        else
    Severity: Minor
    Found in modules/exploits/multi/kubernetes/exec.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 create_pod has 81 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def create_pod
        if datastore['PodImage'].blank?
          image_names = @kubernetes_client.list_pods(namespace).fetch(:items, []).flat_map { |pod| pod.dig(:spec, :containers).map { |container| container[:image] } }.uniq
          fail_with(Failure::NotFound, 'An image could not be found from which to create a pod, set the PodImage option') if image_names.empty?
        else
    Severity: Major
    Found in modules/exploits/multi/kubernetes/exec.rb - About 3 hrs to fix

      File exec.rb has 252 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      class MetasploitModule < Msf::Exploit
        Rank = ManualRanking
      
        include Msf::Exploit::Retry
        include Msf::Exploit::Remote::HttpClient
      Severity: Minor
      Found in modules/exploits/multi/kubernetes/exec.rb - About 2 hrs to fix

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

          def exploit
            if session
              print_status("Routing traffic through session: #{session.sid}")
              configure_via_session
            end
        Severity: Minor
        Found in modules/exploits/multi/kubernetes/exec.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 exploit has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def exploit
            if session
              print_status("Routing traffic through session: #{session.sid}")
              configure_via_session
            end
        Severity: Minor
        Found in modules/exploits/multi/kubernetes/exec.rb - About 1 hr to fix

          Method execute_command has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

            def execute_command(cmd, _opts = {})
              case target['Platform']
              when 'python'
                command = [datastore['Shell'], '-c', "exec $(which python || which python3 || which python2) -c #{Shellwords.escape(cmd)}"]
              else
          Severity: Minor
          Found in modules/exploits/multi/kubernetes/exec.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

          There are no issues that match your filters.

          Category
          Status