rapid7/metasploit-framework

View on GitHub
lib/msf/core/exploit/capture.rb

Summary

Maintainability
F
4 days
Test Coverage

File capture.rb has 440 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Msf

###
#
# This module provides methods for sending and receiving
Severity: Minor
Found in lib/msf/core/exploit/capture.rb - About 6 hrs to fix

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

      class Exploit
        module Capture
    
          #
          # Initializes an instance of an exploit module that captures traffic
    Severity: Minor
    Found in lib/msf/core/exploit/capture.rb - About 4 hrs to fix

      Method open_pcap has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

            def open_pcap(opts={})
              check_pcaprub_loaded
              if RUBY_PLATFORM == "i386-mingw32"
                if opts['INTERFACE'] or datastore['INTERFACE']
                  dev = opts['INTERFACE'] || datastore['INTERFACE']
      Severity: Minor
      Found in lib/msf/core/exploit/capture.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 arp has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

            def arp(target_ip=nil)
              return self.arp_cache[target_ip] if self.arp_cache[target_ip]
              return self.arp_cache[:gateway] unless should_arp? target_ip
              source_ip = Rex::Socket.source_address(target_ip)
              raise RuntimeError, "Could not access the capture process." unless self.arp_capture
      Severity: Minor
      Found in lib/msf/core/exploit/capture.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 probe_gateway has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

            def probe_gateway(addr)
              dst_host = datastore['GATEWAY_PROBE_HOST']
              dst_port = datastore['GATEWAY_PROBE_PORT'].to_i == 0 ? rand(30000) + 1024 : datastore['GATEWAY_PROBE_PORT']
              preamble = [datastore['SECRET']].pack("N")
              secret   = "#{preamble}#{Rex::Text.rand_text(rand(0xff)+1)}"
      Severity: Minor
      Found in lib/msf/core/exploit/capture.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 open_pcap has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def open_pcap(opts={})
              check_pcaprub_loaded
              if RUBY_PLATFORM == "i386-mingw32"
                if opts['INTERFACE'] or datastore['INTERFACE']
                  dev = opts['INTERFACE'] || datastore['INTERFACE']
      Severity: Minor
      Found in lib/msf/core/exploit/capture.rb - About 1 hr to fix

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

              def initialize(info = {})
                super
        
                register_options(
                  [
        Severity: Minor
        Found in lib/msf/core/exploit/capture.rb - About 1 hr to fix

          Method is_interface? has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

                def is_interface?(dev)
                  check_pcaprub_loaded
                  if RUBY_PLATFORM == "i386-mingw32"
                    if dev =~ /\\Device\\NPF_\{[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}\}/
                      return NetworkInterface.interfaces.include?(dev)
          Severity: Minor
          Found in lib/msf/core/exploit/capture.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 probe_gateway has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def probe_gateway(addr)
                  dst_host = datastore['GATEWAY_PROBE_HOST']
                  dst_port = datastore['GATEWAY_PROBE_PORT'].to_i == 0 ? rand(30000) + 1024 : datastore['GATEWAY_PROBE_PORT']
                  preamble = [datastore['SECRET']].pack("N")
                  secret   = "#{preamble}#{Rex::Text.rand_text(rand(0xff)+1)}"
          Severity: Minor
          Found in lib/msf/core/exploit/capture.rb - About 1 hr to fix

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

                  def arp(target_ip=nil)
                    return self.arp_cache[target_ip] if self.arp_cache[target_ip]
                    return self.arp_cache[:gateway] unless should_arp? target_ip
                    source_ip = Rex::Socket.source_address(target_ip)
                    raise RuntimeError, "Could not access the capture process." unless self.arp_capture
            Severity: Minor
            Found in lib/msf/core/exploit/capture.rb - About 1 hr to fix

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

                    def get_interface_guid(dev)
                      check_pcaprub_loaded
                      if RUBY_PLATFORM == "i386-mingw32"
                        if dev.to_s =~ /^[0-9]{1,2}$/
                          if is_interface?(dev)
              Severity: Minor
              Found in lib/msf/core/exploit/capture.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 lookup_eth has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                    def lookup_eth(addr=nil, iface=nil)
                      raise RuntimeError, "Could not access the capture process." unless self.arp_capture
              
                      self.arp_cache ||= {}
                      self.dst_cache ||= {}
              Severity: Minor
              Found in lib/msf/core/exploit/capture.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 inject_reply has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                    def inject_reply(proto=:udp, pcap=self.capture)
                      # Defaults to ~2 seconds
                      to = ((datastore['TIMEOUT'] || 500).to_f * 4) / 1000.0
                      raise RuntimeError, "Could not access the capture process (remember to open_pcap first!)" if not pcap
                      begin
              Severity: Minor
              Found in lib/msf/core/exploit/capture.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 capture_sendto has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                    def capture_sendto(payload="", dhost=nil, bcast=false, dev=nil)
                      raise RuntimeError, "Could not access the capture process (remember to open_pcap first!)" unless self.capture
                      raise RuntimeError, "Must specify a host to sendto" unless dhost
                      dev              ||= datastore['INTERFACE']
                      dst_mac, src_mac = lookup_eth(dhost, dev)
              Severity: Minor
              Found in lib/msf/core/exploit/capture.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 NetworkInterface.interfaces.include?(dev)
              Severity: Major
              Found in lib/msf/core/exploit/capture.rb - About 30 mins to fix

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

                      def inject_pcap(pcap_file, filter=nil, delay = 0, pcap=self.capture)
                        check_pcaprub_loaded
                        unless pcap
                          raise RuntimeError, "Could not access the capture process (remember to open_pcap first!)"
                        end
                Severity: Minor
                Found in lib/msf/core/exploit/capture.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

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

                      def inject_eth(args={})
                        eth_daddr   = args[:eth_daddr] || "ff:ff:ff:ff:ff:ff"
                        eth_saddr   = args[:eth_saddr] || "00:00:00:00:00:00"
                        eth_type    = args[:eth_type] || 0x0800 # IP default
                        payload     = args[:payload]
                Severity: Minor
                Found in lib/msf/core/exploit/capture.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

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

                      def get_ipv4_addr(dev, num=0)
                        check_pcaprub_loaded
                        dev   = get_interface_guid(dev)
                        addrs = NetworkInterface.addresses(dev)
                        raise RuntimeError, "Interface #{dev} does not exist" if !addrs
                Severity: Major
                Found in lib/msf/core/exploit/capture.rb and 2 other locations - About 1 hr to fix
                lib/msf/core/exploit/capture.rb on lines 505..512
                lib/msf/core/exploit/capture.rb on lines 515..522

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

                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 3 locations. Consider refactoring.
                Open

                      def get_ipv4_netmask(dev, num=0)
                        check_pcaprub_loaded
                        dev   = get_interface_guid(dev)
                        addrs = NetworkInterface.addresses(dev)
                        raise RuntimeError, "Interface #{dev} does not exist" if !addrs
                Severity: Major
                Found in lib/msf/core/exploit/capture.rb and 2 other locations - About 1 hr to fix
                lib/msf/core/exploit/capture.rb on lines 495..502
                lib/msf/core/exploit/capture.rb on lines 515..522

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

                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 3 locations. Consider refactoring.
                Open

                      def get_ipv4_broadcast(dev, num=0)
                        check_pcaprub_loaded
                        dev   = get_interface_guid(dev)
                        addrs = NetworkInterface.addresses(dev)
                        raise RuntimeError, "Interface #{dev} do not exists" if !addrs
                Severity: Major
                Found in lib/msf/core/exploit/capture.rb and 2 other locations - About 1 hr to fix
                lib/msf/core/exploit/capture.rb on lines 495..502
                lib/msf/core/exploit/capture.rb on lines 505..512

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

                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