rapid7/metasploit-framework

View on GitHub
plugins/session_notifier.rb

Summary

Maintainability
D
2 days
Test Coverage

File session_notifier.rb has 353 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'net/https'
require 'net/http'
require 'uri'
module Msf
  class Plugin::SessionNotifier < Msf::Plugin
Severity: Minor
Found in plugins/session_notifier.rb - About 4 hrs to fix

    Method load_settings_from_config has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

          def load_settings_from_config
            config_file = Msf::Config.config_file
            ini = Rex::Parser::Ini.new(config_file)
            group = ini[name]
            if group
    Severity: Minor
    Found in plugins/session_notifier.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

    Class SessionNotifierCommandDispatcher has 30 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class SessionNotifierCommandDispatcher
    
          include Msf::Ui::Console::CommandDispatcher
    
          attr_reader :sms_client, :sms_carrier, :sms_number, :smtp_address, :smtp_port, :smtp_username, :smtp_password, :smtp_from, :minimum_ip, :maximum_ip, :dingtalk_webhook, :gotify_address, :gotify_sslcert_path, :serverjang_webhook
    Severity: Minor
    Found in plugins/session_notifier.rb - About 3 hrs to fix

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

            def save_settings_to_config
              config_file = Msf::Config.config_file
              ini = Rex::Parser::Ini.new(config_file)
              ini.add_group(name) unless ini[name]
              ini[name]['smtp_address'] = smtp_address
      Severity: Minor
      Found in plugins/session_notifier.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 send_text_to_gotify has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def send_text_to_gotify(session)
              # https://gotify.net/docs/more-pushmsg
              uri_parser = URI.parse(gotify_address)
              message_text =
                "Platform : #{session.platform}\n" \
      Severity: Minor
      Found in plugins/session_notifier.rb - About 1 hr to fix

        Method cmd_start_session_notifier has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def cmd_start_session_notifier(*_args)
                if session_notifier_subscribed?
                  print_status('You already have an active session notifier.')
                  return
                end
        Severity: Minor
        Found in plugins/session_notifier.rb - About 1 hr to fix

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

                def send_text_to_dingtalk(session)
                  # https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq/9e91d73c
                  uri_parser = URI.parse(dingtalk_webhook)
                  markdown_text = "## You have a new #{session.type} session!\n\n" \
                  "**platform** : #{session.platform}\n\n" \
          Severity: Minor
          Found in plugins/session_notifier.rb - About 1 hr to fix

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

                  def send_text_to_gotify(session)
                    # https://gotify.net/docs/more-pushmsg
                    uri_parser = URI.parse(gotify_address)
                    message_text =
                      "Platform : #{session.platform}\n" \
            Severity: Minor
            Found in plugins/session_notifier.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 send_text_to_dingtalk has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def send_text_to_dingtalk(session)
                    # https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq/9e91d73c
                    uri_parser = URI.parse(dingtalk_webhook)
                    markdown_text = "## You have a new #{session.type} session!\n\n" \
                    "**platform** : #{session.platform}\n\n" \
            Severity: Minor
            Found in plugins/session_notifier.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

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

                  def cmd_start_session_notifier(*_args)
                    if session_notifier_subscribed?
                      print_status('You already have an active session notifier.')
                      return
                    end
            Severity: Minor
            Found in plugins/session_notifier.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

                    {
                      'set_session_smtp_address' => 'Set the SMTP address for the session notifier',
                      'set_session_smtp_port' => 'Set the SMTP port for the session notifier',
                      'set_session_smtp_username' => 'Set the SMTP username',
                      'set_session_smtp_password' => 'Set the SMTP password',
            Severity: Minor
            Found in plugins/session_notifier.rb and 2 other locations - About 35 mins to fix
            modules/auxiliary/gather/xerox_workcentre_5xxx_ldap.rb on lines 162..179
            modules/exploits/linux/http/cisco_rv32x_rce.rb on lines 147..164

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

            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