rapid7/metasploit-framework

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

Summary

Maintainability
F
5 days
Test Coverage

File http_client.rb has 591 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'uri'
require 'digest'

module Msf

Severity: Major
Found in lib/msf/core/exploit/remote/http_client.rb - About 1 day to fix

    Method http_fingerprint has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

      def http_fingerprint(opts={})
        res    = nil
        uri    = opts[:uri] || '/'
        method = opts[:method] || 'GET'
    
    
    Severity: Minor
    Found in lib/msf/core/exploit/remote/http_client.rb - About 4 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 http_fingerprint has 91 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def http_fingerprint(opts={})
        res    = nil
        uri    = opts[:uri] || '/'
        method = opts[:method] || 'GET'
    
    
    Severity: Major
    Found in lib/msf/core/exploit/remote/http_client.rb - About 3 hrs to fix

      Method connect has 69 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def connect(opts={})
          dossl = false
          if(opts.has_key?('SSL'))
            dossl = opts['SSL']
          else
      Severity: Major
      Found in lib/msf/core/exploit/remote/http_client.rb - About 2 hrs to fix

        Method lookup_http_fingerprints has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

          def lookup_http_fingerprints(opts={})
            uri     = opts[:uri] || '/'
            method  = opts[:method] || 'GET'
            fprints = []
        
        
        Severity: Minor
        Found in lib/msf/core/exploit/remote/http_client.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 initialize has 61 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def initialize(info = {})
            super
        
            register_options(
              [
        Severity: Major
        Found in lib/msf/core/exploit/remote/http_client.rb - About 2 hrs to fix

          Method send_request_raw has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

            def send_request_raw(opts = {}, timeout = 20, disconnect = false)
              if datastore['HttpClientTimeout'] && datastore['HttpClientTimeout'] > 0
                actual_timeout = datastore['HttpClientTimeout']
              else
                actual_timeout = opts[:timeout] || timeout
          Severity: Minor
          Found in lib/msf/core/exploit/remote/http_client.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 reconfig_redirect_opts! has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

            def reconfig_redirect_opts!(res, opts)
              # XXX: https://github.com/rapid7/metasploit-framework/issues/12281
              if opts['method'] == 'POST'
                opts['method'] = 'GET'
                opts['data'] = nil
          Severity: Minor
          Found in lib/msf/core/exploit/remote/http_client.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_request_cgi has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

            def send_request_cgi(opts = {}, timeout = 20, disconnect = true)
              if opts.has_key?('cookie')
                if opts['cookie'].is_a?(Msf::Exploit::Remote::HTTP::HttpCookieJar)
                  opts.merge({ 'cookie' => opts['cookie'].cookies.join('; ') })
                else
          Severity: Minor
          Found in lib/msf/core/exploit/remote/http_client.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 configure_http_login_scanner has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def configure_http_login_scanner(conf)
              {
                host:                          rhost,
                port:                          rport,
                ssl:                           ssl,
          Severity: Minor
          Found in lib/msf/core/exploit/remote/http_client.rb - About 1 hr to fix

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

              def reconfig_redirect_opts!(res, opts)
                # XXX: https://github.com/rapid7/metasploit-framework/issues/12281
                if opts['method'] == 'POST'
                  opts['method'] = 'GET'
                  opts['data'] = nil
            Severity: Minor
            Found in lib/msf/core/exploit/remote/http_client.rb - About 1 hr to fix

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

                def full_uri(custom_uri = nil, vhost_uri: false)
                  uri_scheme = ssl ? 'https' : 'http'
              
                  if (rport == 80 && !ssl) || (rport == 443 && ssl)
                    uri_port = ''
              Severity: Minor
              Found in lib/msf/core/exploit/remote/http_client.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_fingerprint has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                def validate_fingerprint()
                  # Don't bother checking if there's no database active.
                  if (framework.db.active and
                      datastore['FingerprintCheck'] and
                      self.class.const_defined?('HttpFingerprint'))
              Severity: Minor
              Found in lib/msf/core/exploit/remote/http_client.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 connect has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def connect(opts={})
                  dossl = false
                  if(opts.has_key?('SSL'))
                    dossl = opts['SSL']
                  else
              Severity: Minor
              Found in lib/msf/core/exploit/remote/http_client.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 download has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def download(url)
                  print_status "Downloading '#{url}'"
              
                  begin
                    target = URI.parse url
              Severity: Minor
              Found in lib/msf/core/exploit/remote/http_client.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 connect_ws has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def connect_ws(opts={}, timeout = 20)
                  ws_key = Rex::Text.rand_text_alphanumeric(20)
                  opts['headers'] = opts.fetch('headers', {}).merge({
                    'Connection' => 'Upgrade',
                    'Upgrade' => 'WebSocket',
              Severity: Minor
              Found in lib/msf/core/exploit/remote/http_client.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 request_opts_from_url has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def request_opts_from_url(url)
                  # verify and extract components from the URL
                  begin
                    tgt = URI.parse(url)
                    raise 'Invalid URL' unless tgt.scheme =~ %r{https?}
              Severity: Minor
              Found in lib/msf/core/exploit/remote/http_client.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 send_request_cgi! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def send_request_cgi!(opts = {}, timeout = 20, redirect_depth = 1)
                  res = send_request_cgi(opts, timeout)
              
                  return unless res
                  return res unless res.redirect? && res.redirection && redirect_depth > 0
              Severity: Minor
              Found in lib/msf/core/exploit/remote/http_client.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

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

                def target_uri
                  begin
                    # In case TARGETURI is empty, at least we default to '/'
                    u = datastore['TARGETURI']
                    u = "/" if u.nil? or u.empty?
              Severity: Minor
              Found in lib/msf/core/exploit/remote/http_client.rb and 2 other locations - About 35 mins to fix
              modules/auxiliary/admin/scada/ge_proficy_substitute_traversal.rb on lines 58..66
              modules/exploits/linux/misc/jenkins_java_deserialize.rb on lines 76..84

              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

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

                  begin
                    target = URI.parse url
                    raise 'Invalid URL' unless target.scheme =~ /https?/
                    raise 'Invalid URL' if target.host.to_s.eql? ''
                  rescue => e
              Severity: Minor
              Found in lib/msf/core/exploit/remote/http_client.rb and 1 other location - About 25 mins to fix
              lib/msf/core/exploit/remote/http_client.rb on lines 589..596

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

              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
                    tgt = URI.parse(url)
                    raise 'Invalid URL' unless tgt.scheme =~ %r{https?}
                    raise 'Invalid URL' if tgt.host.to_s.eql? ''
                  rescue => e
              Severity: Minor
              Found in lib/msf/core/exploit/remote/http_client.rb and 1 other location - About 25 mins to fix
              lib/msf/core/exploit/remote/http_client.rb on lines 626..633

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

              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

              Identical blocks of code found in 6 locations. Consider refactoring.
              Open

                def normalize_uri(*strs)
                  new_str = strs * "/"
              
                  new_str = new_str.gsub!("//", "/") while new_str.index("//")
              
              
              Severity: Minor
              Found in lib/msf/core/exploit/remote/http_client.rb and 5 other locations - About 20 mins to fix
              modules/auxiliary/admin/scada/ge_proficy_substitute_traversal.rb on lines 45..55
              modules/exploits/linux/misc/jenkins_java_deserialize.rb on lines 88..98
              modules/exploits/linux/misc/jenkins_ldap_deserialize.rb on lines 77..87
              modules/exploits/windows/fileformat/word_mshtml_rce.rb on lines 239..249
              modules/exploits/windows/local/microfocus_operations_privesc.rb on lines 83..93

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

              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