rapid7/metasploit-framework

View on GitHub
lib/msf/core/exploit/remote/ms_icpr.rb

Summary

Maintainability
D
2 days
Test Coverage

Method do_request_cert has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

  def do_request_cert(icpr, opts)
    private_key = OpenSSL::PKey::RSA.new(2048)
    user = opts[:username] || datastore['SMBUser']
    status_msg = "Requesting a certificate for user #{user}"
    alt_dns = opts[:alt_dns] || (datastore['ALT_DNS'].blank? ? nil : datastore['ALT_DNS'])
Severity: Minor
Found in lib/msf/core/exploit/remote/ms_icpr.rb - About 5 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

File ms_icpr.rb has 337 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'windows_error/h_result'

module Msf

module Exploit::Remote::MsIcpr
Severity: Minor
Found in lib/msf/core/exploit/remote/ms_icpr.rb - About 4 hrs to fix

    Method do_request_cert has 91 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def do_request_cert(icpr, opts)
        private_key = OpenSSL::PKey::RSA.new(2048)
        user = opts[:username] || datastore['SMBUser']
        status_msg = "Requesting a certificate for user #{user}"
        alt_dns = opts[:alt_dns] || (datastore['ALT_DNS'].blank? ? nil : datastore['ALT_DNS'])
    Severity: Major
    Found in lib/msf/core/exploit/remote/ms_icpr.rb - About 3 hrs to fix

      Method build_on_behalf_of has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def build_on_behalf_of(csr:, on_behalf_of:, cert:, key:, algorithm: 'SHA256')
          # algorithm needs to be one that OpenSSL supports, but we also need the OID constants defined
          digest = OpenSSL::Digest.new(algorithm)
          unless [ digest.name, "RSAWith#{digest.name}" ].all? { |s| Rex::Proto::Kerberos::Model::OID.constants.include?(s.to_sym) }
            raise ArgumentError, "Can not map digest algorithm #{digest.name} to the necessary OIDs."
      Severity: Major
      Found in lib/msf/core/exploit/remote/ms_icpr.rb - About 2 hrs to fix

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

          def setup
            errors = {}
            if datastore['ALT_SID'].present? && datastore['ALT_SID'] !~ /^S(-\d+)+$/
              errors['ALT_SID'] = 'Must be a valid SID.'
            end
        Severity: Minor
        Found in lib/msf/core/exploit/remote/ms_icpr.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_csr has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def build_csr(cn:, private_key:, dns: nil, msext_sid: nil, msext_upn: nil, algorithm: 'SHA256')
            request = OpenSSL::X509::Request.new
            request.version = 1
            request.subject = OpenSSL::X509::Name.new([
              ['CN', cn, OpenSSL::ASN1::UTF8STRING]
        Severity: Minor
        Found in lib/msf/core/exploit/remote/ms_icpr.rb - About 1 hr to fix

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

            def request_certificate(opts = {})
              tree = opts[:tree] || connect_ipc
          
              begin
                icpr = connect_icpr(tree)
          Severity: Minor
          Found in lib/msf/core/exploit/remote/ms_icpr.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 build_csr has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def build_csr(cn:, private_key:, dns: nil, msext_sid: nil, msext_upn: nil, algorithm: 'SHA256')
              request = OpenSSL::X509::Request.new
              request.version = 1
              request.subject = OpenSSL::X509::Name.new([
                ['CN', cn, OpenSSL::ASN1::UTF8STRING]
          Severity: Minor
          Found in lib/msf/core/exploit/remote/ms_icpr.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

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

            def icpr_service_data
              {
                host: rhost,
                port: rport,
                host_name: simple.client.default_name,
          Severity: Minor
          Found in lib/msf/core/exploit/remote/ms_icpr.rb and 1 other location - About 25 mins to fix
          modules/auxiliary/scanner/dcerpc/petitpotam.rb on lines 184..192

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

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

            def get_cert_san_dns(cert)
              return [] unless (san = get_cert_san(cert))
          
              san[:GeneralNames].value.select do |gn|
                gn[:dNSName].value?
          Severity: Minor
          Found in lib/msf/core/exploit/remote/ms_icpr.rb and 1 other location - About 15 mins to fix
          lib/msf/core/exploit/remote/ms_icpr.rb on lines 432..438

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

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

              begin
                simple.client.tree_connect("\\\\#{sock.peerhost}\\IPC$")
              rescue RubySMB::Error::RubySMBError => e
                raise MsIcprConnectionError, "Unable to connect to the remote IPC$ share ([#{e.class}] #{e})."
              end
          Severity: Minor
          Found in lib/msf/core/exploit/remote/ms_icpr.rb and 1 other location - About 15 mins to fix
          lib/msf/core/exploit/remote/ms_samr.rb on lines 46..50

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

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

            def get_cert_san_email(cert)
              return [] unless (san = get_cert_san(cert))
          
              san[:GeneralNames].value.select do |gn|
                gn[:rfc822Name].value?
          Severity: Minor
          Found in lib/msf/core/exploit/remote/ms_icpr.rb and 1 other location - About 15 mins to fix
          lib/msf/core/exploit/remote/ms_icpr.rb on lines 417..423

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

          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