rapid7/metasploit-framework

View on GitHub
lib/metasploit/framework/ssh/platform.rb

Summary

Maintainability
C
1 day
Test Coverage

Method get_platform_info has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

        def self.get_platform_info(ssh_socket, timeout: 10)
          info = ''
          begin
            Timeout.timeout(timeout) do
              info = ssh_socket.exec!("id\n").to_s
Severity: Minor
Found in lib/metasploit/framework/ssh/platform.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

Method get_platform_info has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def self.get_platform_info(ssh_socket, timeout: 10)
          info = ''
          begin
            Timeout.timeout(timeout) do
              info = ssh_socket.exec!("id\n").to_s
Severity: Major
Found in lib/metasploit/framework/ssh/platform.rb - About 2 hrs to fix

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

            def self.get_platform_from_info(info)
              case info
              when /unifi\.version|UniFiSecurityGateway/i # Ubiquiti Unifi.  uname -a is left in, so we got to pull before Linux
                'unifi'
              when /Linux/i
    Severity: Minor
    Found in lib/metasploit/framework/ssh/platform.rb - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                    elsif info =~ /sh: id: not found/
                      info = ssh_socket.exec!("vmware -v\n").to_s
                    else
                      info << ssh_socket.exec!("help\n?\n\n\n").to_s
      Severity: Major
      Found in lib/metasploit/framework/ssh/platform.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                        if version && platform && board
                          info = "#{platform.strip} #{board.strip} #{version.strip}"
                        end
        Severity: Major
        Found in lib/metasploit/framework/ssh/platform.rb - About 45 mins to fix

          There are no issues that match your filters.

          Category
          Status