rapid7/metasploit-framework

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

Summary

Maintainability
F
4 days
Test Coverage

File jetbrains_teamcity_rce_cve_2024_27198.rb has 520 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
Severity: Major
Found in modules/exploits/multi/http/jetbrains_teamcity_rce_cve_2024_27198.rb - About 1 day to fix

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

      def exploit
        #
        # 1. Leverage the auth bypass to generate a new administrator access token. Older version of TeamCity (circa 2018)
        #    do not have support for access token, so we fall back to creating a new administrator account. The benefit
        #    of using an access token is we can delete it when we are finished, unlike a user account.
    Severity: Minor
    Found in modules/exploits/multi/http/jetbrains_teamcity_rce_cve_2024_27198.rb - About 5 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 exploit has 110 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def exploit
        #
        # 1. Leverage the auth bypass to generate a new administrator access token. Older version of TeamCity (circa 2018)
        #    do not have support for access token, so we fall back to creating a new administrator account. The benefit
        #    of using an access token is we can delete it when we are finished, unlike a user account.
    Severity: Major
    Found in modules/exploits/multi/http/jetbrains_teamcity_rce_cve_2024_27198.rb - About 4 hrs to fix

      Method create_payload_plugin has 84 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def create_payload_plugin(plugin_name)
          if target['Arch'] == ARCH_CMD
      
            case target['Platform']
            when 'win'
      Severity: Major
      Found in modules/exploits/multi/http/jetbrains_teamcity_rce_cve_2024_27198.rb - About 3 hrs to fix

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

          def initialize(info = {})
            super(
              update_info(
                info,
                'Name' => 'JetBrains TeamCity Unauthenticated Remote Code Execution',
        Severity: Major
        Found in modules/exploits/multi/http/jetbrains_teamcity_rce_cve_2024_27198.rb - About 3 hrs to fix

          Method delete_plugin has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def delete_plugin(http_authorization, plugin_name)
              plugin_uuid = get_plugin_uuid(http_authorization, plugin_name)
          
              if plugin_uuid.nil?
                print_warning('Failed to discover enabled plugin UUID')

            Method auth_new_admin_user has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def auth_new_admin_user
                admin_username = Faker::Internet.username
                admin_password = Rex::Text.rand_text_alphanumeric(16)
            
                res = send_auth_bypass_request_cgi(

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

                def get_install_path(http_authorization)
                  res = send_request_cgi(
                    'method' => 'GET',
                    'uri' => normalize_uri(target_uri.path, 'app', 'rest', 'server', 'plugins'),
                    'keep_cookies' => true,

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

                  def check
                    # We leverage the vulnerability to reach the /app/rest/server endpoint. If this request succeeds then we know the
                    # target is vulnerable.
                    server_res = send_auth_bypass_request_cgi(
                      'method' => 'GET',
                Severity: Minor
                Found in modules/exploits/multi/http/jetbrains_teamcity_rce_cve_2024_27198.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 create_payload_plugin has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def create_payload_plugin(plugin_name)
                    if target['Arch'] == ARCH_CMD
                
                      case target['Platform']
                      when 'win'
                Severity: Minor
                Found in modules/exploits/multi/http/jetbrains_teamcity_rce_cve_2024_27198.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 delete_plugin has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def delete_plugin(http_authorization, plugin_name)
                    plugin_uuid = get_plugin_uuid(http_authorization, plugin_name)
                
                    if plugin_uuid.nil?
                      print_warning('Failed to discover enabled plugin UUID')
                Severity: Minor
                Found in modules/exploits/multi/http/jetbrains_teamcity_rce_cve_2024_27198.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

                      res = send_request_cgi(
                        'method' => 'POST',
                        'uri' => normalize_uri(target_uri.path, 'admin', 'plugins.html'),
                        'keep_cookies' => true,
                        'headers' => {
                modules/exploits/multi/http/jetbrains_teamcity_rce_cve_2024_27198.rb on lines 675..687

                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

                    res = send_request_cgi(
                      'method' => 'POST',
                      'uri' => normalize_uri(target_uri.path, 'admin', 'plugins.html'),
                      'keep_cookies' => true,
                      'headers' => {
                modules/exploits/multi/http/jetbrains_teamcity_rce_cve_2024_27198.rb on lines 263..275

                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