rapid7/metasploit-framework

View on GitHub
modules/exploits/multi/http/struts2_namespace_ognl.rb

Summary

Maintainability
D
2 days
Test Coverage

File struts2_namespace_ognl.rb has 386 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class MetasploitModule < Msf::Exploit::Remote
  Rank = ExcellentRanking

  include Msf::Exploit::Remote::HttpClient
  include Msf::Exploit::EXE
Severity: Minor
Found in modules/exploits/multi/http/struts2_namespace_ognl.rb - About 5 hrs to fix

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

      def initialize(info = {})
        super(update_info(info,
          'Name'           => 'Apache Struts 2 Namespace Redirect OGNL Injection',
          'Description'    => %q{
            This module exploits a remote code execution vulnerability in Apache Struts
    Severity: Major
    Found in modules/exploits/multi/http/struts2_namespace_ognl.rb - About 2 hrs to fix

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

        def execute_command(cmd_input, opts={})
          # Semicolons appear to be a bad character in OGNL.  cmdstager doesn't understand that.
          if cmd_input.include? ';'
            print_warning("WARNING: Command contains bad characters: semicolons (;).")
          end
      Severity: Minor
      Found in modules/exploits/multi/http/struts2_namespace_ognl.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 send_profile has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def send_profile
          # Use OGNL to extract properties from the Java environment
      
          properties = { 'os.name': nil,          # e.g. 'Linux'
                         'os.arch': nil,          # e.g. 'amd64'
      Severity: Minor
      Found in modules/exploits/multi/http/struts2_namespace_ognl.rb - About 1 hr to fix

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

          def check
            # METHOD 1: Try to extract the state of hte allowStaticMethodAccess variable
            ognl = "#_memberAccess['allowStaticMethodAccess']"
        
            resp = send_struts_request(ognl)
        Severity: Minor
        Found in modules/exploits/multi/http/struts2_namespace_ognl.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 check has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def check
            # METHOD 1: Try to extract the state of hte allowStaticMethodAccess variable
            ognl = "#_memberAccess['allowStaticMethodAccess']"
        
            resp = send_struts_request(ognl)
        Severity: Minor
        Found in modules/exploits/multi/http/struts2_namespace_ognl.rb - About 1 hr to fix

          Method execute_command has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def execute_command(cmd_input, opts={})
              # Semicolons appear to be a bad character in OGNL.  cmdstager doesn't understand that.
              if cmd_input.include? ';'
                print_warning("WARNING: Command contains bad characters: semicolons (;).")
              end
          Severity: Minor
          Found in modules/exploits/multi/http/struts2_namespace_ognl.rb - About 1 hr to fix

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

              def send_payload_oneshot(payload)
                data_header = datastore['HEADER']
                if data_header.empty?
                  fail_with(Failure::BadConfig, "HEADER parameter cannot be blank when sending a payload")
                end
            Severity: Minor
            Found in modules/exploits/multi/http/struts2_namespace_ognl.rb - About 1 hr to fix

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

                def ognl_append_file(payload_file, payload_chunk)
                  data_header = datastore['HEADER'] + 'd'
                  file_header = datastore['HEADER'] + 'f'
                  headers = {
                    "#{data_header}": payload_chunk,
              Severity: Minor
              Found in modules/exploits/multi/http/struts2_namespace_ognl.rb - About 1 hr to fix

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

                  def send_profile
                    # Use OGNL to extract properties from the Java environment
                
                    properties = { 'os.name': nil,          # e.g. 'Linux'
                                   'os.arch': nil,          # e.g. 'amd64'
                Severity: Minor
                Found in modules/exploits/multi/http/struts2_namespace_ognl.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 profile_os has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  def profile_os
                    # Probe for the target OS and architecture
                    begin
                      properties = send_profile()
                      os = properties[:'os.name'].downcase
                Severity: Minor
                Found in modules/exploits/multi/http/struts2_namespace_ognl.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 send_payload_oneshot has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def send_payload_oneshot(payload)
                    data_header = datastore['HEADER']
                    if data_header.empty?
                      fail_with(Failure::BadConfig, "HEADER parameter cannot be blank when sending a payload")
                    end
                Severity: Minor
                Found in modules/exploits/multi/http/struts2_namespace_ognl.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 3 locations. Consider refactoring.
                Open

                      register_options(
                        [
                          Opt::RPORT(8080),
                          OptString.new('TARGETURI', [ true, 'A valid base path to a struts application', '/' ]),
                          OptString.new('ACTION', [ true, 'A valid endpoint that is configured as a redirect action', 'showcase.action' ]),
                Severity: Minor
                Found in modules/exploits/multi/http/struts2_namespace_ognl.rb and 2 other locations - About 15 mins to fix
                modules/auxiliary/scanner/vmware/vmware_enum_vms.rb on lines 24..30
                modules/exploits/multi/misc/msf_rpc_console.rb on lines 50..53

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

                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