rapid7/metasploit-framework

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

Summary

Maintainability
F
5 days
Test Coverage

File bitbucket_env_var_rce.rb has 520 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

  include Msf::Exploit::Remote::HttpClient
  include Msf::Exploit::Git
Severity: Major
Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 1 day to fix

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

      def check
        res = send_request_cgi(
          'method' => 'GET',
          'uri' => normalize_uri(target_uri.path, 'login'),
          'keep_cookies' => true
    Severity: Minor
    Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 6 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 initialize has 80 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def initialize(info = {})
        super(
          update_info(
            info,
            'Name' => 'Bitbucket Environment Variable RCE',
    Severity: Major
    Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 3 hrs to fix

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

        def check
          res = send_request_cgi(
            'method' => 'GET',
            'uri' => normalize_uri(target_uri.path, 'login'),
            'keep_cookies' => true
      Severity: Minor
      Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 2 hrs to fix

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

          def get_repo_info
            unless @project_name && @project_key
              print_status('Failed to find valid project information. Will attempt to create repo')
              return nil
            end
        Severity: Minor
        Found in modules/exploits/multi/http/bitbucket_env_var_rce.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 create_repository has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def create_repository
            repo_uri = normalize_uri(target_uri.path, 'projects', @project_key, 'repos?create')
            res = send_request_cgi(
              'method' => 'GET',
              'uri' => repo_uri,
        Severity: Minor
        Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 1 hr to fix

          Method get_repo_info has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def get_repo_info
              unless @project_name && @project_key
                print_status('Failed to find valid project information. Will attempt to create repo')
                return nil
              end
          Severity: Minor
          Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 1 hr to fix

            Method create_project has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def create_project
                proj_uri = normalize_uri(target_uri.path, 'projects?create')
                res = send_request_cgi(
                  'method' => 'GET',
                  'uri' => proj_uri,
            Severity: Minor
            Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 1 hr to fix

              Method cleanup has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                def cleanup
                  if @curr_uname != datastore['USERNAME']
                    print_status("Changing user name back to '#{datastore['USERNAME']}'")
              
                    if change_username(@curr_uname, datastore['USERNAME'])
              Severity: Minor
              Found in modules/exploits/multi/http/bitbucket_env_var_rce.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 change_username has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def change_username(curr_uname, new_uname)
                  @user_id ||= get_user_id(curr_uname)
              
                  headers = {
                    'X-Requested-With' => 'XMLHttpRequest',
              Severity: Minor
              Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 1 hr to fix

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

                  def log_in(username, password)
                    res = send_request_cgi(
                      'method' => 'GET',
                      'uri' => normalize_uri(target_uri.path, 'login'),
                      'keep_cookies' => true
                Severity: Minor
                Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 1 hr to fix

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

                    def exploit
                      @use_public_repo = true
                      datastore['GIT_USERNAME'] = datastore['USERNAME']
                      datastore['GIT_PASSWORD'] = datastore['PASSWORD']
                  
                  
                  Severity: Minor
                  Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 1 hr to fix

                    Method delete_project has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def delete_project(username)
                        vprint_status("Now attempting to delete project '#{@project_name}'")
                        send_request_cgi( # fails to return a response
                          'method' => 'DELETE',
                          'uri' => normalize_uri(target_uri.path, 'projects', @project_key),
                    Severity: Minor
                    Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 1 hr to fix

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

                        def create_project
                          proj_uri = normalize_uri(target_uri.path, 'projects?create')
                          res = send_request_cgi(
                            'method' => 'GET',
                            'uri' => proj_uri,
                      Severity: Minor
                      Found in modules/exploits/multi/http/bitbucket_env_var_rce.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 change_username has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def change_username(curr_uname, new_uname)
                          @user_id ||= get_user_id(curr_uname)
                      
                          headers = {
                            'X-Requested-With' => 'XMLHttpRequest',
                      Severity: Minor
                      Found in modules/exploits/multi/http/bitbucket_env_var_rce.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 log_in has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def log_in(username, password)
                          res = send_request_cgi(
                            'method' => 'GET',
                            'uri' => normalize_uri(target_uri.path, 'login'),
                            'keep_cookies' => true
                      Severity: Minor
                      Found in modules/exploits/multi/http/bitbucket_env_var_rce.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 create_repository has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def create_repository
                          repo_uri = normalize_uri(target_uri.path, 'projects', @project_key, 'repos?create')
                          res = send_request_cgi(
                            'method' => 'GET',
                            'uri' => repo_uri,
                      Severity: Minor
                      Found in modules/exploits/multi/http/bitbucket_env_var_rce.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 get_repo has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def get_repo
                          res = send_request_cgi(
                            'method' => 'GET',
                            'uri' => normalize_uri(target_uri.path, 'rest/api/latest/repos'),
                            'keep_cookies' => true
                      Severity: Minor
                      Found in modules/exploits/multi/http/bitbucket_env_var_rce.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 execute_command has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def execute_command(cmd, _opts = {})
                          if target['Platform'] == 'win'
                            curr_payload = (cmd.ends_with?('.exe') ? uname_payload("cmd.exe /c #{cmd}") : uname_payload(cmd))
                          else
                            curr_payload = uname_payload(cmd)
                      Severity: Minor
                      Found in modules/exploits/multi/http/bitbucket_env_var_rce.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

                      Avoid too many return statements within this method.
                      Open

                              return CheckCode::Appears
                      Severity: Major
                      Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return CheckCode::Appears if rev_num >= 0 && rev_num <= 11
                        Severity: Major
                        Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return CheckCode::Appears if rev_num >= 0 && rev_num <= 3
                          Severity: Major
                          Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                    return CheckCode::Appears if rev_num >= 0 && rev_num <= 5
                            Severity: Major
                            Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return CheckCode::Appears if rev_num >= 0 && rev_num <= 4
                              Severity: Major
                              Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return CheckCode::Appears if rev_num >= 0 && rev_num <= 2
                                Severity: Major
                                Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return CheckCode::Appears
                                  Severity: Major
                                  Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                        return nil unless path
                                    Severity: Major
                                    Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                          return nil unless json['values']
                                      Severity: Major
                                      Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                            return CheckCode::Detected('Failed to find version info in expected format') unless vers_matches && vers_matches.length > 1
                                        Severity: Major
                                        Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                  return CheckCode::Appears if rev_num >= 0 && rev_num <= 4
                                          Severity: Major
                                          Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                    return CheckCode::Appears
                                            Severity: Major
                                            Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                      return CheckCode::Appears if rev_num == 0 || rev_num == 1
                                              Severity: Major
                                              Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                        return CheckCode::Appears if rev_num >= 0 && rev_num <= 18
                                                Severity: Major
                                                Found in modules/exploits/multi/http/bitbucket_env_var_rce.rb - About 30 mins to fix

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

                                                    def delete_project(username)
                                                      vprint_status("Now attempting to delete project '#{@project_name}'")
                                                      send_request_cgi( # fails to return a response
                                                        'method' => 'DELETE',
                                                        'uri' => normalize_uri(target_uri.path, 'projects', @project_key),
                                                  Severity: Minor
                                                  Found in modules/exploits/multi/http/bitbucket_env_var_rce.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