rapid7/metasploit-framework

View on GitHub
modules/exploits/linux/smtp/exim_gethostbyname_bof.rb

Summary

Maintainability
F
1 wk
Test Coverage

Method information_leak has a Cognitive Complexity of 81 (exceeds 5 allowed). Consider refactoring.
Open

  def information_leak
    print_status("Trying information leak...")
    leaked_arch = nil
    leaked_addr = []

Severity: Minor
Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 1 day 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 code_execution has a Cognitive Complexity of 71 (exceeds 5 allowed). Consider refactoring.
Open

  def code_execution
    print_status("Trying code execution...")

    # can't "${run{/bin/sh -c 'exec /bin/sh -i <&#{b} >&0 2>&0'}} " anymore:
    # DW/26 Set FD_CLOEXEC on SMTP sockets after forking in the daemon, to ensure
Severity: Minor
Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 1 day 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 exim_gethostbyname_bof.rb has 478 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

  include Msf::Exploit::Remote::Tcp

Severity: Minor
Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 7 hrs to fix

    Method smtp_recv has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

      def smtp_recv(expected_code = nil, expected_data = nil)
        fail_with(Failure::BadConfig, "state is #{@smtp_state}") if @smtp_state != :recv
        @smtp_state = :recving
    
        failure = catch(:failure) do
    Severity: Minor
    Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.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 smtp_send has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

      def smtp_send(prefix, arg_prefix = nil, arg_pattern = nil, arg_suffix = nil, suffix = nil, arg_length = nil)
        fail_with(Failure::BadConfig, "state is #{@smtp_state}") if @smtp_state != :send
        @smtp_state = :sending
    
        if not arg_pattern
    Severity: Minor
    Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.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 smtp_connect has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

      def smtp_connect(exploiting = true)
        fail_with(Failure::Unknown, "sock isn't nil") if sock
    
        connect
        fail_with(Failure::Unknown, "sock is nil") if not sock
    Severity: Minor
    Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.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 information_leak has 76 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def information_leak
        print_status("Trying information leak...")
        leaked_arch = nil
        leaked_addr = []
    
    
    Severity: Major
    Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 3 hrs to fix

      Method code_execution has 67 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def code_execution
          print_status("Trying code execution...")
      
          # can't "${run{/bin/sh -c 'exec /bin/sh -i <&#{b} >&0 2>&0'}} " anymore:
          # DW/26 Set FD_CLOEXEC on SMTP sockets after forking in the daemon, to ensure
      Severity: Major
      Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 2 hrs to fix

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

          def smtp_connect(exploiting = true)
            fail_with(Failure::Unknown, "sock isn't nil") if sock
        
            connect
            fail_with(Failure::Unknown, "sock is nil") if not sock
        Severity: Minor
        Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 1 hr to fix

          Method try_code_execution has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def try_code_execution(len, what, where)
              fail_with(Failure::UnexpectedReply, "#{what.length} >= #{len}") if what.length >= len
              fail_with(Failure::UnexpectedReply, "#{where} < 0") if where < 0
          
              x86 = (@leaked[:arch] == ARCH_X86)
          Severity: Minor
          Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 1 hr to fix

            Method smtp_recv has 45 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def smtp_recv(expected_code = nil, expected_data = nil)
                fail_with(Failure::BadConfig, "state is #{@smtp_state}") if @smtp_state != :recv
                @smtp_state = :recving
            
                failure = catch(:failure) do
            Severity: Minor
            Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 1 hr to fix

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

                def try_code_execution(len, what, where)
                  fail_with(Failure::UnexpectedReply, "#{what.length} >= #{len}") if what.length >= len
                  fail_with(Failure::UnexpectedReply, "#{where} < 0") if where < 0
              
                  x86 = (@leaked[:arch] == ARCH_X86)
              Severity: Minor
              Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.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 try_information_leak has 43 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def try_information_leak(heap_shift, write_offset, last_digit = 9)
                  fail_with(Failure::BadConfig, "heap_shift") if (heap_shift < MIN_HEAP_SHIFT)
                  fail_with(Failure::BadConfig, "heap_shift") if (heap_shift & 15) != 0
                  fail_with(Failure::BadConfig, "write_offset") if (write_offset & 7) != 0
                  fail_with(Failure::BadConfig, "last_digit") if "#{last_digit}" !~ /\A[0-9]\z/
              Severity: Minor
              Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 1 hr to fix

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

                  def initialize(info = {})
                    super(update_info(info,
                      'Name' => 'Exim GHOST (glibc gethostbyname) Buffer Overflow',
                      'Description' => %q{
                        This module remotely exploits CVE-2015-0235, aka GHOST, a heap-based
                Severity: Minor
                Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 1 hr to fix

                  Consider simplifying this complex logical expression.
                  Open

                            if (error[0] == error[1]) and (error[0].empty? or (error[0].unpack('C')[0] & 7) == 0) and # fd_nextsize
                               (error[2] == error[3]) and (error[2].empty? or (error[2].unpack('C')[0] & 7) == 0) and # fd
                               (error[4] =~ /\A503 send[^e].?\z/mn) and ((error[4].unpack('C*')[8] & 15) == PREV_INUSE) and # size
                               (error[5] == "177") # the last \x7F of our BAD1 command, encoded as \\177 by string_printing()
                              leaked_arch = ARCH_X64
                  Severity: Critical
                  Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 1 hr to fix

                    Method smtp_send has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def smtp_send(prefix, arg_prefix = nil, arg_pattern = nil, arg_suffix = nil, suffix = nil, arg_length = nil)
                        fail_with(Failure::BadConfig, "state is #{@smtp_state}") if @smtp_state != :send
                        @smtp_state = :sending
                    
                        if not arg_pattern
                    Severity: Minor
                    Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 1 hr to fix

                      Consider simplifying this complex logical expression.
                      Open

                                elsif (error[0].empty? or (error[0].unpack('C')[0] & 3) == 0) and # fd_nextsize
                                      (error[1].empty? or (error[1].unpack('C')[0] & 3) == 0) and # fd
                                      (error[2] =~ /\A503 [^s].?\z/mn) and ((error[2].unpack('C*')[4] & 7) == PREV_INUSE) and # size
                                      (error[3] == "177") # the last \x7F of our BAD1 command, encoded as \\177 by string_printing()
                                  leaked_arch = ARCH_X86
                      Severity: Major
                      Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 1 hr to fix

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

                          def try_information_leak(heap_shift, write_offset, last_digit = 9)
                            fail_with(Failure::BadConfig, "heap_shift") if (heap_shift < MIN_HEAP_SHIFT)
                            fail_with(Failure::BadConfig, "heap_shift") if (heap_shift & 15) != 0
                            fail_with(Failure::BadConfig, "write_offset") if (write_offset & 7) != 0
                            fail_with(Failure::BadConfig, "last_digit") if "#{last_digit}" !~ /\A[0-9]\z/
                        Severity: Minor
                        Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.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 smtp_send has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                          def smtp_send(prefix, arg_prefix = nil, arg_pattern = nil, arg_suffix = nil, suffix = nil, arg_length = nil)
                        Severity: Minor
                        Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 45 mins to fix

                          Consider simplifying this complex logical expression.
                          Open

                                    if (leaked_arch == ARCH_X86 and error[0,4] == error[4,4] and error[8..-1] == "er not yet given") or
                                       (leaked_arch == ARCH_X64 and error.length == 6 and error[5].count("\x7E-\x7F").nonzero?)
                                      leaked_addr = [leaked_addr.last] # use this one, and not another
                                      throw(:another_heap_shift, true) # done
                                    end
                          Severity: Major
                          Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 40 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                  return nil
                            Severity: Major
                            Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb - About 30 mins to fix

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

                                              (error[1].empty? or (error[1].unpack('C')[0] & 3) == 0) and # fd
                                              (error[2] =~ /\A503 [^s].?\z/mn) and ((error[2].unpack('C*')[4] & 7) == PREV_INUSE) and # size
                                              (error[3] == "177") # the last \x7F of our BAD1 command, encoded as \\177 by string_printing()
                                          leaked_arch = ARCH_X86
                              Severity: Minor
                              Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb and 1 other location - About 45 mins to fix
                              modules/exploits/linux/smtp/exim_gethostbyname_bof.rb on lines 184..198

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

                              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 (error[0] == error[1]) and (error[0].empty? or (error[0].unpack('C')[0] & 7) == 0) and # fd_nextsize
                                           (error[2] == error[3]) and (error[2].empty? or (error[2].unpack('C')[0] & 7) == 0) and # fd
                                           (error[4] =~ /\A503 send[^e].?\z/mn) and ((error[4].unpack('C*')[8] & 15) == PREV_INUSE) and # size
                                           (error[5] == "177") # the last \x7F of our BAD1 command, encoded as \\177 by string_printing()
                                          leaked_arch = ARCH_X64
                              Severity: Minor
                              Found in modules/exploits/linux/smtp/exim_gethostbyname_bof.rb and 1 other location - About 45 mins to fix
                              modules/exploits/linux/smtp/exim_gethostbyname_bof.rb on lines 191..194

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

                              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