rapid7/metasploit-framework

View on GitHub
lib/msf/core/payload.rb

Summary

Maintainability
F
3 days
Test Coverage

Method substitute_vars has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
Open

  def substitute_vars(raw, offsets)
    offsets.each_pair { |name, info|
      offset, pack = info

      # Give the derived class a chance to substitute this variable
Severity: Minor
Found in lib/msf/core/payload.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

Class Payload has 36 methods (exceeds 20 allowed). Consider refactoring.
Open

class Payload < Msf::Module


  # Platform specific includes
  require 'metasploit/framework/compiler/mingw'
Severity: Minor
Found in lib/msf/core/payload.rb - About 4 hrs to fix

    File payload.rb has 334 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'metasm'
    
    module Msf
    
    ###
    Severity: Minor
    Found in lib/msf/core/payload.rb - About 4 hrs to fix

      Method substitute_vars has 61 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def substitute_vars(raw, offsets)
          offsets.each_pair { |name, info|
            offset, pack = info
      
            # Give the derived class a chance to substitute this variable
      Severity: Major
      Found in lib/msf/core/payload.rb - About 2 hrs to fix

        Method choose_payload has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.choose_payload(mod)
            compatible_payloads = mod.compatible_payloads(
              excluded_platforms: ['Multi'] # We don't want to select a multi payload
            ).map(&:first)
        
        
        Severity: Minor
        Found in lib/msf/core/payload.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 build has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def build(asm, off={}, opts = {})
            if(asm.nil? or asm.empty?)
              raise ArgumentError, "Assembly must not be empty"
            end
        
        
        Severity: Minor
        Found in lib/msf/core/payload.rb - About 1 hr to fix

          Method choose_payload has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.choose_payload(mod)
              compatible_payloads = mod.compatible_payloads(
                excluded_platforms: ['Multi'] # We don't want to select a multi payload
              ).map(&:first)
          
          
          Severity: Minor
          Found in lib/msf/core/payload.rb - About 1 hr to fix

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

              def on_session(session)
            
                # If this payload is associated with an exploit, inform the exploit
                # that a session has been created and potentially shut down any
                # open sockets. This allows active exploits to continue hammering
            Severity: Minor
            Found in lib/msf/core/payload.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 initialize has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def initialize(info = {})
                super
            
                #
                # Gets the Dependencies if the payload requires external help
            Severity: Minor
            Found in lib/msf/core/payload.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

            Avoid deeply nested control flow statements.
            Open

                      if(val.length == 16)
                        raise RuntimeError, "IPv6 address specified for IPv4 payload."
                      end
            Severity: Major
            Found in lib/msf/core/payload.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                      elsif (pack == 'RAW')
                        # Just use the raw value...
                      else
                        # Check to see if the value is a hex string.  If so, convert
                        # it.
              Severity: Major
              Found in lib/msf/core/payload.rb - About 45 mins to fix

                Method build has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  def build(asm, off={}, opts = {})
                    if(asm.nil? or asm.empty?)
                      raise ArgumentError, "Assembly must not be empty"
                    end
                
                
                Severity: Minor
                Found in lib/msf/core/payload.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 "unknown"
                Severity: Major
                Found in lib/msf/core/payload.rb - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status