rapid7/metasploit-framework

View on GitHub
lib/rex/proto/ntlm/utils.rb

Summary

Maintainability
F
1 wk
Test Coverage

File utils.rb has 587 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Rex::Proto::NTLM
  class Utils

    # duplicate from lib/rex/proto/smb/utils cause we only need this function from Rex::Proto::SMB::Utils
    # Convert a unix timestamp to a 64-bit signed server time
Severity: Major
Found in lib/rex/proto/ntlm/utils.rb - About 1 day to fix

    Method create_lm_ntlm_responses has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.create_lm_ntlm_responses(user, pass, challenge_key, domain = '', default_name = '', default_domain = '',
                dns_host_name = '', dns_domain_name = '', chall_MsvAvTimestamp = nil, spnopt = {}, opt = {} )
    
          usentlm2_session     = opt[:usentlm2_session]    != nil ? opt[:usentlm2_session] : true
          use_ntlmv2         = opt[:use_ntlmv2]         != nil ? opt[:use_ntlmv2] : false
    Severity: Minor
    Found in lib/rex/proto/ntlm/utils.rb - About 1 day 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 create_session_key has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.create_session_key(ntlmssp_flags, server_ntlmssp_flags, user, pass, domain, challenge_key,
                client_challenge = '', ntlm_cli_challenge = '' , opt = {} )
    
          usentlm2_session     = opt[:usentlm2_session]    != nil ? opt[:usentlm2_session] : true
          use_ntlmv2         = opt[:use_ntlmv2]         != nil ? opt[:use_ntlmv2] : false
    Severity: Minor
    Found in lib/rex/proto/ntlm/utils.rb - About 6 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 create_lm_ntlm_responses has 136 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def self.create_lm_ntlm_responses(user, pass, challenge_key, domain = '', default_name = '', default_domain = '',
                dns_host_name = '', dns_domain_name = '', chall_MsvAvTimestamp = nil, spnopt = {}, opt = {} )
    
          usentlm2_session     = opt[:usentlm2_session]    != nil ? opt[:usentlm2_session] : true
          use_ntlmv2         = opt[:use_ntlmv2]         != nil ? opt[:use_ntlmv2] : false
    Severity: Major
    Found in lib/rex/proto/ntlm/utils.rb - About 5 hrs to fix

      Method create_session_key has 98 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def self.create_session_key(ntlmssp_flags, server_ntlmssp_flags, user, pass, domain, challenge_key,
                  client_challenge = '', ntlm_cli_challenge = '' , opt = {} )
      
            usentlm2_session     = opt[:usentlm2_session]    != nil ? opt[:usentlm2_session] : true
            use_ntlmv2         = opt[:use_ntlmv2]         != nil ? opt[:use_ntlmv2] : false
      Severity: Major
      Found in lib/rex/proto/ntlm/utils.rb - About 3 hrs to fix

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

            def self.make_ntlm_flags(opt = {})
        
              signing         = opt[:signing]         != nil ? opt[:signing] : false
              usentlm2_session     = opt[:usentlm2_session]    != nil ? opt[:usentlm2_session] : true
              use_ntlmv2         = opt[:use_ntlmv2]         != nil ? opt[:use_ntlmv2] : false
        Severity: Minor
        Found in lib/rex/proto/ntlm/utils.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 make_ntlmssp_blob_auth has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def self.make_ntlmssp_blob_auth(domain, name, user, lm, ntlm, enc_session_key, flags = 0x080201)
              lm ||= "\x00" * 24
              ntlm ||= "\x00" * 24
        
              domain_uni = Rex::Text.to_unicode(domain)
        Severity: Minor
        Found in lib/rex/proto/ntlm/utils.rb - About 1 hr to fix

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

              def self.parse_ntlm_type_2_blob(blob)
                data = {}
                # Extract the NTLM challenge key the lazy way
                cidx = blob.index("NTLMSSP\x00\x02\x00\x00\x00")
          
          
          Severity: Minor
          Found in lib/rex/proto/ntlm/utils.rb - About 1 hr to fix

            Method make_negotiate_secblob_resp has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def self.make_negotiate_secblob_resp(account, domain)
                  blob =
                  "\x60" + self.asn1encode(
                    "\x06" + self.asn1encode(
                      "\x2b\x06\x01\x05\x05\x02"
            Severity: Minor
            Found in lib/rex/proto/ntlm/utils.rb - About 1 hr to fix

              Method create_lm_ntlm_responses has 11 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def self.create_lm_ntlm_responses(user, pass, challenge_key, domain = '', default_name = '', default_domain = '',
                          dns_host_name = '', dns_domain_name = '', chall_MsvAvTimestamp = nil, spnopt = {}, opt = {} )
              Severity: Major
              Found in lib/rex/proto/ntlm/utils.rb - About 1 hr to fix

                Method create_session_key has 9 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def self.create_session_key(ntlmssp_flags, server_ntlmssp_flags, user, pass, domain, challenge_key,
                            client_challenge = '', ntlm_cli_challenge = '' , opt = {} )
                Severity: Major
                Found in lib/rex/proto/ntlm/utils.rb - About 1 hr to fix

                  Method make_ntlmv2_clientchallenge has 7 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def self.make_ntlmv2_clientchallenge(win_domain, win_name, dns_domain, dns_name,
                                client_challenge = nil, chall_MsvAvTimestamp = nil, spnopt = {})
                  Severity: Major
                  Found in lib/rex/proto/ntlm/utils.rb - About 50 mins to fix

                    Method make_ntlmssp_blob_auth has 7 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def self.make_ntlmssp_blob_auth(domain, name, user, lm, ntlm, enc_session_key, flags = 0x080201)
                    Severity: Major
                    Found in lib/rex/proto/ntlm/utils.rb - About 50 mins to fix

                      Method make_ntlmssp_secblob_auth has 7 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          def self.make_ntlmssp_secblob_auth(domain, name, user, lm, ntlm, enc_session_key, flags = 0x080201)
                      Severity: Major
                      Found in lib/rex/proto/ntlm/utils.rb - About 50 mins to fix

                        Method make_ntlmssp_blob_chall has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            def self.make_ntlmssp_blob_chall(win_domain, win_name, dns_domain, dns_name, chall, flags)
                        Severity: Minor
                        Found in lib/rex/proto/ntlm/utils.rb - About 45 mins to fix

                          Method make_ntlmssp_secblob_chall has 6 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              def self.make_ntlmssp_secblob_chall(win_domain, win_name, dns_domain, dns_name, chall, flags)
                          Severity: Minor
                          Found in lib/rex/proto/ntlm/utils.rb - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                          if self.is_pass_ntlm_hash?(pass)
                                            arglm = {
                                              :ntlmv2_hash =>  Rex::Proto::NTLM::Crypt::ntlmv2_hash(
                                                        user,
                                                        [ pass.upcase()[33,65] ].pack('H32'),
                            Severity: Major
                            Found in lib/rex/proto/ntlm/utils.rb - About 45 mins to fix

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

                                  def self.parse_ntlm_type_2_blob(blob)
                                    data = {}
                                    # Extract the NTLM challenge key the lazy way
                                    cidx = blob.index("NTLMSSP\x00\x02\x00\x00\x00")
                              
                              
                              Severity: Minor
                              Found in lib/rex/proto/ntlm/utils.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

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

                                                        ),
                                                :challenge   => challenge_key
                                              }
                                            else
                                              arglm = {
                              Severity: Major
                              Found in lib/rex/proto/ntlm/utils.rb and 1 other location - About 1 hr to fix
                              lib/rex/proto/ntlm/utils.rb on lines 605..621

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

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

                                                    ),
                                            :challenge => challenge_key
                                          }
                                        else
                                          arglm = {
                              Severity: Major
                              Found in lib/rex/proto/ntlm/utils.rb and 1 other location - About 1 hr to fix
                              lib/rex/proto/ntlm/utils.rb on lines 527..544

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

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

                                            arglm = {
                                              :lm_hash => Rex::Proto::NTLM::Crypt::lm_hash(pass),
                                              :challenge =>  challenge_key
                                            }
                                          end
                              Severity: Minor
                              Found in lib/rex/proto/ntlm/utils.rb and 1 other location - About 35 mins to fix
                              lib/rex/proto/ntlm/utils.rb on lines 623..634

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

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

                                          arglm = {
                                            :lm_hash => Rex::Proto::NTLM::Crypt::lm_hash(pass),
                                            :challenge =>  challenge_key
                                          }
                                        end
                              Severity: Minor
                              Found in lib/rex/proto/ntlm/utils.rb and 1 other location - About 35 mins to fix
                              lib/rex/proto/ntlm/utils.rb on lines 584..595

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

                              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

                                          else
                                            user_session_key = Rex::Proto::NTLM::Crypt::ntlmv2_user_session_key(user, pass, domain,
                                                      challenge_key, ntlm_cli_challenge)
                                          end
                                        else
                              Severity: Minor
                              Found in lib/rex/proto/ntlm/utils.rb and 1 other location - About 35 mins to fix
                              lib/rex/proto/ntlm/utils.rb on lines 733..740

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

                              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

                                            user_session_key = Rex::Proto::NTLM::Crypt::lmv2_user_session_key(user, pass, domain,
                                                        challenge_key, client_challenge)
                                          end
                                        else
                                          if self.is_pass_ntlm_hash?(pass)
                              Severity: Minor
                              Found in lib/rex/proto/ntlm/utils.rb and 1 other location - About 35 mins to fix
                              lib/rex/proto/ntlm/utils.rb on lines 687..695

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

                              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

                                        end
                                    end
                              
                                    user_session_key = Rex::Proto::NTLM::Crypt::make_weak_sessionkey(user_session_key,key_size, lanman_weak)
                              
                              
                              Severity: Minor
                              Found in lib/rex/proto/ntlm/utils.rb and 1 other location - About 20 mins to fix
                              lib/rex/proto/ntlm/utils.rb on lines 723..727

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

                              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

                                        end
                                      end
                                    else
                                        if usentlm2_session && use_ntlmv2
                                          if self.is_pass_ntlm_hash?(pass)
                              Severity: Minor
                              Found in lib/rex/proto/ntlm/utils.rb and 1 other location - About 20 mins to fix
                              lib/rex/proto/ntlm/utils.rb on lines 743..747

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

                              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