rapid7/metasploit-framework

View on GitHub
modules/exploits/windows/http/manageengine_adaudit_plus_authenticated_rce.rb

Summary

Maintainability
F
5 days
Test Coverage

File manageengine_adaudit_plus_authenticated_rce.rb has 474 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class MetasploitModule < Msf::Exploit::Remote

  Rank = ExcellentRanking
  prepend Msf::Exploit::Remote::AutoCheck
  include Msf::Exploit::Remote::HttpClient

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

      def exploit
        if @exploit_method.nil? # this means the user has disabled autocheck so we should try the default exploit method
          @exploit_method = 'default'
        elsif @exploit_method == 'cve_2021_42847' && datastore['PAYLOAD'] =~ /meterpreter/
          print_warning('Exploitation is possible only via CVE-2021-42847. This attack vector may fail in combination with a meterpreter payload.')

    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 89 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def exploit
        if @exploit_method.nil? # this means the user has disabled autocheck so we should try the default exploit method
          @exploit_method = 'default'
        elsif @exploit_method == 'cve_2021_42847' && datastore['PAYLOAD'] =~ /meterpreter/
          print_warning('Exploitation is possible only via CVE-2021-42847. This attack vector may fail in combination with a meterpreter payload.')

      Method create_alert_profile has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

        def create_alert_profile
          if @exploit_method == 'cve_2021_42847'
            print_status('Attempting to authenticate again in order to retrieve the required cookies.')
            # We have to authenticate again in order to get the required cookie, so reset the cookie cache
            cookie_jar.clear

      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_alert_profile has 78 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def create_alert_profile
          if @exploit_method == 'cve_2021_42847'
            print_status('Attempting to authenticate again in order to retrieve the required cookies.')
            # We have to authenticate again in order to get the required cookie, so reset the cookie cache
            cookie_jar.clear

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

          def initialize(info = {})
            super(
              update_info(
                info,
                'Name' => 'ManageEngine ADAudit Plus Authenticated File Write RCE',

          Method check has 70 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def check
              target_check_results = adaudit_plus_target_check
              target_check_msg = target_check_results['message']
              case target_check_results['status']
              when adaudit_plus_status::CONNECTION_FAILED

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

              def check
                target_check_results = adaudit_plus_target_check
                target_check_msg = target_check_results['message']
                case target_check_results['status']
                when adaudit_plus_status::CONNECTION_FAILED

            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 delete_alert has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def delete_alert(adapcsrf_cookie)
                print_status("Attempting to delete alert profile #{@alert_name}")
                # let's try and get the the ID of the alert we want to delete
                res_get_alert = send_request_cgi({
                  'uri' => normalize_uri(target_uri.path, 'api', 'json', 'leftTrees', 'getLeftTreeList'),

              Method alert_profile_info has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def alert_profile_info
                  script_location = @ps1_script_name || payload.encoded
              
                  alert_name = rand_text_alphanumeric(8..12)
                  alert_data = {

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

                  def delete_alert(adapcsrf_cookie)
                    print_status("Attempting to delete alert profile #{@alert_name}")
                    # let's try and get the the ID of the alert we want to delete
                    res_get_alert = send_request_cgi({
                      'uri' => normalize_uri(target_uri.path, 'api', 'json', 'leftTrees', 'getLeftTreeList'),

                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 CheckCode::Unknown(login_msg)

                  Avoid too many return statements within this method.
                  Open

                        return CheckCode::Safe('No Active Directory domains are configured on the target, so the module will not be able to trigger the payload.')

                    Avoid too many return statements within this method.
                    Open

                            return CheckCode::Appears("The target is ADAudit Plus #{build_version} and the endpoint for CVE-2021-42847 exists.")

                      Avoid too many return statements within this method.
                      Open

                            return CheckCode::Detected("The provided AUTH_DOMAIN #{auth_domain} does not match the configured authentication domain(s).")

                        Avoid too many return statements within this method.
                        Open

                                return CheckCode::Safe("The target is ADAudit Plus #{build_version} but the endpoint for CVE-2021-42847 is not accessible.")

                          Avoid too many return statements within this method.
                          Open

                                return

                            Avoid too many return statements within this method.
                            Open

                                  return CheckCode::Safe(login_msg)

                              Avoid too many return statements within this method.
                              Open

                                    return CheckCode::Unknown(build_msg)

                                Avoid too many return statements within this method.
                                Open

                                        return CheckCode::Detected("The target is ADAudit Plus #{build_version} but the connection failed when checking for the CVE-2021-42847 endpoint")

                                  Avoid too many return statements within this method.
                                  Open

                                        return CheckCode::Safe('Failed to verify if any Active Directory domains are configured on the target.')

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

                                      def create_alert_script
                                        ps1_script_name = "#{rand_text_alpha_lower(5..10)}.ps1"
                                        print_status("Attempting to write the payload to /alert_scripts/#{ps1_script_name}")
                                    
                                        if @domain.blank?

                                    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

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

                                          case login_results['status']
                                          when adaudit_plus_status::CONNECTION_FAILED
                                            fail_with(Failure::Unreachable, login_msg)
                                          when adaudit_plus_status::UNEXPECTED_REPLY
                                            fail_with(Failure::UnexpectedReply, login_msg)
                                    modules/exploits/windows/http/manageengine_adaudit_plus_authenticated_rce.rb on lines 225..235

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

                                    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

                                            case login_results['status']
                                            when adaudit_plus_status::CONNECTION_FAILED
                                              fail_with(Failure::Unreachable, login_msg)
                                            when adaudit_plus_status::UNEXPECTED_REPLY
                                              fail_with(Failure::UnexpectedReply, login_msg)
                                    modules/exploits/windows/http/manageengine_adaudit_plus_authenticated_rce.rb on lines 169..182

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

                                    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 17 locations. Consider refactoring.
                                    Open

                                        register_options([
                                          OptString.new('TARGETURI', [true, 'The base path to ManageEngine ADAudit Plus', '/']),
                                          OptString.new('AUTH_DOMAIN', [true, 'ADAudit Plus authentication domain (default is ADAuditPlus Authentication)', 'ADAuditPlus Authentication']),
                                          OptString.new('USERNAME', [true, 'Username to authenticate with', 'admin']),
                                          OptString.new('PASSWORD', [true, 'Password to authenticate with', 'admin']),
                                    modules/auxiliary/admin/http/joomla_registration_privesc.rb on lines 35..41
                                    modules/auxiliary/admin/http/kaseya_master_admin.rb on lines 36..42
                                    modules/auxiliary/admin/http/vbulletin_upgrade_admin.rb on lines 35..41
                                    modules/auxiliary/gather/mantisbt_admin_sqli.rb on lines 33..39
                                    modules/auxiliary/scanner/http/riverbed_steelhead_vcx_file_read.rb on lines 31..37
                                    modules/auxiliary/scanner/sap/sap_soap_rfc_pfl_check_os_file_existence.rb on lines 51..56
                                    modules/auxiliary/scanner/sap/sap_soap_rfc_rzl_read_dir.rb on lines 51..56
                                    modules/auxiliary/scanner/telephony/wardial.rb on lines 48..54
                                    modules/exploits/linux/http/froxlor_log_path_rce.rb on lines 67..73
                                    modules/exploits/linux/http/seagate_nas_php_exec_noauth.rb on lines 48..53
                                    modules/exploits/unix/webapp/wp_google_document_embedder_exec.rb on lines 53..59
                                    modules/exploits/windows/http/ajaxpro_deserialization_rce.rb on lines 91..96
                                    modules/exploits/windows/http/apache_activemq_traversal_upload.rb on lines 61..66
                                    modules/exploits/windows/http/sharepoint_data_deserialization.rb on lines 77..82
                                    modules/exploits/windows/http/zentao_pro_rce.rb on lines 74..79
                                    modules/post/osx/manage/mount_share.rb on lines 51..57

                                    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