rapid7/metasploit-framework

View on GitHub
modules/post/linux/gather/mimipenguin.rb

Summary

Maintainability
F
3 days
Test Coverage

Method choose_mem_regions has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

  def choose_mem_regions(pid, match_data = [])
    return [] if match_data.empty?

    mem_regions = []
    match_data.each do |match|
Severity: Minor
Found in modules/post/linux/gather/mimipenguin.rb - About 4 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

File mimipenguin.rb has 341 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'unix_crypt'

class MetasploitModule < Msf::Post
  include Msf::Post::Linux::Priv
  include Msf::Post::Linux::System
Severity: Minor
Found in modules/post/linux/gather/mimipenguin.rb - About 4 hrs to fix

    Method run has 89 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def run
        fail_with(Failure::BadConfig, 'Root privileges are required') unless is_root?
        user_data = get_user_names_and_hashes
        fail_with(Failure::UnexpectedReply, 'Failed to retrieve user information') if user_data.empty?
        password_data = configure_passwords(user_data)
    Severity: Major
    Found in modules/post/linux/gather/mimipenguin.rb - About 3 hrs to fix

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

        def run
          fail_with(Failure::BadConfig, 'Root privileges are required') unless is_root?
          user_data = get_user_names_and_hashes
          fail_with(Failure::UnexpectedReply, 'Failed to retrieve user information') if user_data.empty?
          password_data = configure_passwords(user_data)
      Severity: Minor
      Found in modules/post/linux/gather/mimipenguin.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 check_for_valid_passwords has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        def check_for_valid_passwords(captured_strings, user_data, process_name)
          captured_strings.each do |str|
            user_data.each do |pass_info|
              salt = pass_info['salt']
              hash = pass_info['hash']
      Severity: Minor
      Found in modules/post/linux/gather/mimipenguin.rb - About 2 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 choose_mem_regions has 65 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def choose_mem_regions(pid, match_data = [])
          return [] if match_data.empty?
      
          mem_regions = []
          match_data.each do |match|
      Severity: Major
      Found in modules/post/linux/gather/mimipenguin.rb - About 2 hrs to fix

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

          def initialize(info = {})
            super(
              update_info(
                info,
                'Name' => 'MimiPenguin',
        Severity: Minor
        Found in modules/post/linux/gather/mimipenguin.rb - About 1 hr to fix

          Method configure_passwords has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            def configure_passwords(user_data = [])
              user_data.each do |info|
                hash = info['hash']
                hash_format = Metasploit::Framework::Hashes.identify_hash(hash)
                info['type'] = hash_format.empty? ? 'unsupported' : hash_format
          Severity: Minor
          Found in modules/post/linux/gather/mimipenguin.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 get_user_names_and_hashes has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            def get_user_names_and_hashes
              shadow_contents = read_file('/etc/shadow')
              fail_with(Failure::UnexpectedReply, "Failed to read '/etc/shadow'") if shadow_contents.blank?
              vprint_status('Storing shadow file...')
              store_loot('shadow.file', 'text/plain', session, shadow_contents, nil)
          Severity: Minor
          Found in modules/post/linux/gather/mimipenguin.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_for_valid_passwords has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def check_for_valid_passwords(captured_strings, user_data, process_name)
              captured_strings.each do |str|
                user_data.each do |pass_info|
                  salt = pass_info['salt']
                  hash = pass_info['hash']
          Severity: Minor
          Found in modules/post/linux/gather/mimipenguin.rb - About 1 hr to fix

            Avoid too many return statements within this method.
            Open

                    return updated_regions
            Severity: Major
            Found in modules/post/linux/gather/mimipenguin.rb - About 30 mins to fix

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

                    if prev && prev.include?('00000000 00:00 0')
                      formatted = format_addresses(prev)
                      start_addr = formatted['start']
                      end_addr = formatted['end']
                      length = end_addr - start_addr
              Severity: Minor
              Found in modules/post/linux/gather/mimipenguin.rb and 1 other location - About 25 mins to fix
              modules/post/linux/gather/mimipenguin.rb on lines 188..195

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

              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

                    if post && post.include?('00000000 00:00 0')
                      formatted = format_addresses(post)
                      start_addr = formatted['start']
                      end_addr = formatted['end']
                      length = end_addr - start_addr
              Severity: Minor
              Found in modules/post/linux/gather/mimipenguin.rb and 1 other location - About 25 mins to fix
              modules/post/linux/gather/mimipenguin.rb on lines 178..185

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

              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