rapid7/metasploit-framework

View on GitHub
plugins/capture.rb

Summary

Maintainability
F
4 days
Test Coverage

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

require 'uri'
require 'rex/sync/event'
require 'fileutils'

module Msf
Severity: Major
Found in plugins/capture.rb - About 1 day to fix

    Method listeners_start has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

          def listeners_start(args)
            config = parse_start_args(args)
            if config[:show_help]
              help('start')
              return
    Severity: Minor
    Found in plugins/capture.rb - About 7 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 listeners_start has 145 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def listeners_start(args)
            config = parse_start_args(args)
            if config[:show_help]
              help('start')
              return
    Severity: Major
    Found in plugins/capture.rb - About 5 hrs to fix

      Class ConsoleCommandDispatcher has 31 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class ConsoleCommandDispatcher
            include Msf::Ui::Console::CommandDispatcher
      
            class CaptureJobListener
              def initialize(name, done_event, dispatcher)
      Severity: Minor
      Found in plugins/capture.rb - About 3 hrs to fix

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

              def parse_start_args(args)
                config_file = File.join(Msf::Config.config_directory, 'capture_config.yaml')
                # See if there was a config file set
                @start_opt_parser.parse(args) do |opt, _idx, val|
                  case opt
        Severity: Minor
        Found in plugins/capture.rb - About 1 hr to fix

          Method listeners_stop has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                def listeners_stop(args)
                  options = parse_stop_args(args)
                  if options[:show_help]
                    help('stop')
                    return
          Severity: Minor
          Found in plugins/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 validate_params has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

                def validate_params(options)
                  unless options[:srvhost] && Rex::Socket.is_ip_addr?(options[:srvhost])
                    raise ArgumentError, 'Must provide a valid IP address to listen on'
                  end
                  # If we're running poisoning (which is disabled remotely, so excluding that situation),
          Severity: Minor
          Found in plugins/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 transform_params has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                def transform_params(options)
                  # If we've been given a specific IP to listen on, use that as our poisoning IP
                  if options[:spoof_ip].nil? && Rex::Socket.is_ip_addr?(options[:srvhost]) && Rex::Socket.addr_atoi(options[:srvhost]) != 0
                    options[:spoof_ip] = options[:srvhost]
                  end
          Severity: Minor
          Found in plugins/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 cmd_captureg has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                def cmd_captureg(*args)
                  # short circuit the whole deal if they need help
                  return help if args.empty?
                  return help if args.length == 1 && args.first =~ HELP_REGEX
                  return help(args.last) if args.length == 2 && args.first =~ HELP_REGEX
          Severity: Minor
          Found in plugins/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

          Avoid too many return statements within this method.
          Open

                    return []
          Severity: Major
          Found in plugins/capture.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                      return help
            Severity: Major
            Found in plugins/capture.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return result
              Severity: Major
              Found in plugins/capture.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return
                Severity: Major
                Found in plugins/capture.rb - About 30 mins to fix

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

                          modules = {
                            # Capturing
                            'DRDA' => 'auxiliary/server/capture/drda',
                            'FTP' => 'auxiliary/server/capture/ftp',
                            'IMAP' => 'auxiliary/server/capture/imap',
                  Severity: Minor
                  Found in plugins/capture.rb and 1 other location - About 55 mins to fix
                  data/sounds/gensounds_mac.rb on lines 1..22

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

                  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