rapid7/metasploit-framework

View on GitHub
scripts/meterpreter/dumplinks.rb

Summary

Maintainability
F
4 days
Test Coverage

Method extract_lnk_info has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring.
Open

def extract_lnk_info(path)
  @client.fs.dir.foreach(path) do |file_name|
    if file_name =~ /\.lnk$/   # We have a .lnk file
      record = nil
      offset = 0 # ToDo: Look at moving this to smaller scope
Severity: Minor
Found in scripts/meterpreter/dumplinks.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

File dumplinks.rb has 336 lines of code (exceeds 250 allowed). Consider refactoring.
Open

opts = Rex::Parser::Arguments.new(
  "-h" => [ false, "Help menu." ],
  "-e" => [ false, "Dump everything for each link file." ],
  "-w" => [ false, "Redirect output to file."]
)
Severity: Minor
Found in scripts/meterpreter/dumplinks.rb - About 4 hrs to fix

    Method extract_lnk_info has 79 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def extract_lnk_info(path)
      @client.fs.dir.foreach(path) do |file_name|
        if file_name =~ /\.lnk$/   # We have a .lnk file
          record = nil
          offset = 0 # ToDo: Look at moving this to smaller scope
    Severity: Major
    Found in scripts/meterpreter/dumplinks.rb - About 3 hrs to fix

      Method enum_users has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      def enum_users(os)
        users = []
        userinfo = {}
        userpath = nil
        useroffcpath = nil
      Severity: Minor
      Found in scripts/meterpreter/dumplinks.rb - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                    if loc['base_ofs'] > 0
                      @data_out += get_target_path(loc['base_ofs'] + offset, lnk_file)
                    elsif loc['path_ofs'] > 0
                      @data_out += get_target_path(loc['path_ofs'] + offset, lnk_file)
                    end
        Severity: Major
        Found in scripts/meterpreter/dumplinks.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                      if (loc['flags'] & 0x02) > 0
                        if @everything
                          @data_out += "\tFile is on a network share.\n"
                        end
                        lnk_file.sysseek(offset + loc['network_ofs'], ::IO::SEEK_SET)
          Severity: Major
          Found in scripts/meterpreter/dumplinks.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                        if (loc['flags'] & 0x01) > 0
                          if @everything
                            @data_out += "\tShortcut file is on a local volume.\n"
                          end
                          lnk_file.sysseek(offset + loc['vol_ofs'], ::IO::SEEK_SET)
            Severity: Major
            Found in scripts/meterpreter/dumplinks.rb - About 45 mins to fix

              Method enum_users has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              def enum_users(os)
                users = []
                userinfo = {}
                userpath = nil
                useroffcpath = nil
              Severity: Minor
              Found in scripts/meterpreter/dumplinks.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

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

              def get_headers(record)
                hd = record.unpack('x16V12x8')
                hdr = Hash.new()
                hdr["flags"]    = hd[0]
                hdr["attr"]     = hd[1]
              Severity: Major
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 2 hrs to fix
              modules/post/windows/gather/dumplinks.rb on lines 324..336

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

              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

                  if user['userpath']
                    print_status "Extracting lnk files for user #{user['username']} at #{user['userpath']}..."
                    extract_lnk_info(user['userpath'])
                  else
                    print_status "No Recent directory found for user #{user['username']}. Nothing to do."
              Severity: Major
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 1 hr to fix
              modules/post/windows/gather/dumplinks.rb on lines 48..58

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

              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

              def get_attrs(hdr)
                fileattr = {0x01 => "Target is read only",
                  0x02 => "Target is hidden",
                  0x04 => "Target is a system file",
                  0x08 => "Target is a volume label",
              Severity: Major
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 1 hr to fix
              modules/post/windows/gather/dumplinks.rb on lines 269..291

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

              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

              def get_showwnd(hdr)
                showwnd = { 0 => "SW_HIDE",
                  1 => "SW_NORMAL",
                  2 => "SW_SHOWMINIMIZED",
                  3 => "SW_SHOWMAXIMIZED",
              Severity: Major
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 1 hr to fix
              modules/post/windows/gather/dumplinks.rb on lines 238..258

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

              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

              def get_flags(hdr)
                flags  = {0x01 => "Shell Item ID List exists",
                  0x02 => "Shortcut points to a file or directory",
                  0x04 => "The shortcut has a descriptive string",
                  0x08 => "The shortcut has a relative path string",
              Severity: Minor
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 50 mins to fix
              modules/post/windows/gather/dumplinks.rb on lines 305..321

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

              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_lnk_MAC(hdr)
                data_out = "\tTarget file's MAC Times stored in lnk file:\n"
                data_out += "\t\tCreation Time     = #{Time.at(hdr["ctime"])}. (UTC)\n"
                data_out += "\t\tModification Time = #{Time.at(hdr["mtime"])}. (UTC)\n"
                data_out += "\t\tAccess Time       = #{Time.at(hdr["atime"])}. (UTC)\n"
              Severity: Minor
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 45 mins to fix
              modules/post/windows/gather/dumplinks.rb on lines 261..266

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

              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

              def get_time(lo_byte, hi_byte)
                if (lo_byte == 0 && hi_byte == 0)
                  return 0
                else
                  lo_byte -= 0xd53e8000
              Severity: Minor
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 40 mins to fix
              modules/post/windows/gather/dumplinks.rb on lines 359..371

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

              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

              def get_target_path(path_ofs, lnk_file)
                name = []
                lnk_file.sysseek(path_ofs, ::IO::SEEK_SET)
                record = lnk_file.sysread(2)
                while (record.unpack('v')[0] != 0)
              Severity: Minor
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 35 mins to fix
              modules/post/windows/gather/dumplinks.rb on lines 197..205

              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

              def get_lnk_file_MAC(file_stat, path, file_name)
                data_out = "#{path + file_name}:\n"
                data_out += "\tAccess Time       = #{file_stat.atime}\n"
                data_out += "\tCreation Date     = #{file_stat.ctime}\n"
                data_out += "\tModification Time = #{file_stat.mtime}\n"
              Severity: Minor
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 35 mins to fix
              modules/post/windows/gather/dumplinks.rb on lines 217..222

              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

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

              def get_file_location(file_loc_rec)
                location = Hash.new()
                (location["len"], location["ptr"], location["flags"],
                  location["vol_ofs"], location["base_ofs"], location["network_ofs"],
                  location["path_ofs"]) = file_loc_rec.unpack('V7')
              Severity: Minor
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 35 mins to fix
              modules/post/windows/gather/dumplinks.rb on lines 351..356

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

              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

                          if loc['base_ofs'] > 0
                            @data_out += get_target_path(loc['base_ofs'] + offset, lnk_file)
                          elsif loc['path_ofs'] > 0
                            @data_out += get_target_path(loc['path_ofs'] + offset, lnk_file)
                          end
              Severity: Minor
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 30 mins to fix
              modules/post/windows/gather/dumplinks.rb on lines 180..184

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

              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

              def get_local_vol_tbl(lvt_rec)
                lv = Hash.new()
                (lv['len'], lv['type'], lv['vol_sn'], lv['ofs']) = lvt_rec.unpack('V4')
                return lv
              Severity: Minor
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 15 mins to fix
              modules/post/windows/gather/dumplinks.rb on lines 345..348

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

              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

                              @data_out += "\t\tVolume Name = #{lvt['name']}\n" +
                                "\t\tVolume Type = #{get_vol_type(lvt['type'])}\n" +
                                "\t\tVolume SN   = 0x%X" % lvt['vol_sn'] + "\n"
                            end
              Severity: Minor
              Found in scripts/meterpreter/dumplinks.rb and 1 other location - About 15 mins to fix
              modules/post/windows/gather/dumplinks.rb on lines 163..166

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

              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