rapid7/metasploit-framework

View on GitHub
data/exploits/psnuffle/smb.rb

Summary

Maintainability
D
2 days
Test Coverage

Method parse_sessionsetup has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
Open

  def parse_sessionsetup(pkt, s)
    payload = pkt.payload.dup
    ntlmpayload = payload[/NTLMSSP\x00.*/m]
    if ntlmpayload
      ntlmmessagetype = ntlmpayload[8,4].unpack("V")[0]
Severity: Minor
Found in data/exploits/psnuffle/smb.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 parse_sessionsetup has 97 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def parse_sessionsetup(pkt, s)
    payload = pkt.payload.dup
    ntlmpayload = payload[/NTLMSSP\x00.*/m]
    if ntlmpayload
      ntlmmessagetype = ntlmpayload[8,4].unpack("V")[0]
Severity: Major
Found in data/exploits/psnuffle/smb.rb - About 3 hrs to fix

    Method parse has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

      def parse(pkt)
        # We want to return immediatly if we do not have a packet which is handled by us
        return unless pkt.is_tcp?
        return if (pkt.tcp_sport != 445 and pkt.tcp_dport != 445)
        s = find_session((pkt.tcp_sport == 445) ? get_session_src(pkt) : get_session_dst(pkt))
    Severity: Minor
    Found in data/exploits/psnuffle/smb.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

    Consider simplifying this complex logical expression.
    Open

            if s[:last] == :ntlm_type2
              lmlength =     ntlmpayload[12, 2].unpack("v")[0]
              lmoffset =     ntlmpayload[16, 2].unpack("v")[0]
              ntlmlength =     ntlmpayload[20, 2].unpack("v")[0]
              ntlmoffset =     ntlmpayload[24, 2].unpack("v")[0]
    Severity: Critical
    Found in data/exploits/psnuffle/smb.rb - About 1 hr to fix

      Method parse has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def parse(pkt)
          # We want to return immediatly if we do not have a packet which is handled by us
          return unless pkt.is_tcp?
          return if (pkt.tcp_sport != 445 and pkt.tcp_dport != 445)
          s = find_session((pkt.tcp_sport == 445) ? get_session_src(pkt) : get_session_dst(pkt))
      Severity: Minor
      Found in data/exploits/psnuffle/smb.rb - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                    s[:lmhash] = "00" * 24 if s[:lmhash] == s[:ntlmhash]
        Severity: Major
        Found in data/exploits/psnuffle/smb.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                      s[:lmhash] = "00" * 24 if s[:lmhash] == '' or s[:lmhash] =~ /^(00)*$/m
          Severity: Major
          Found in data/exploits/psnuffle/smb.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                        if smb_status == 0 # success
            
                          ntlm_ver = detect_ntlm_ver(s[:lmhash],s[:ntlmhash])
            
                          logmessage =
            Severity: Major
            Found in data/exploits/psnuffle/smb.rb - About 45 mins to fix

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

                def detect_ntlm_ver(lmhash, ntlmhash)
                  return "NTLMv2" if ntlmhash.length > 48
                  if lmhash.length == 48 and ntlmhash.length == 48
                    if lmhash != "00" * 24 and lmhash[16,32] == "00" * 16
                      return "NTLM2_SESSION"
              Severity: Minor
              Found in data/exploits/psnuffle/smb.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

              There are no issues that match your filters.

              Category
              Status