module_rank.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/usr/bin/env ruby
  2. ##
  3. # This module requires Metasploit: https://metasploit.com/download
  4. # Current source: https://github.com/rapid7/metasploit-framework
  5. ##
  6. #
  7. # This script lists each module with its rank
  8. #
  9. msfbase = __FILE__
  10. while File.symlink?(msfbase)
  11. msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
  12. end
  13. $:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))
  14. require 'msfenv'
  15. $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
  16. require 'rex'
  17. ranks= Hash.new
  18. ranks['Manual'] = 0
  19. ranks['Low'] = 100
  20. ranks['Average'] = 200
  21. ranks['Normal'] = 300
  22. ranks['Good'] = 400
  23. ranks['Great'] = 500
  24. ranks['Excellent'] = 600
  25. minrank= 0
  26. maxrank= 600
  27. sort = 0
  28. filter= 'All'
  29. filters = ['all','exploit','payload','post','nop','encoder','auxiliary']
  30. opts = Rex::Parser::Arguments.new(
  31. "-h" => [ false, "Help menu." ],
  32. "-M" => [ true, "Set Maximum Rank [Manual,Low,Average,Normal,Good,Great,Excellent] (Default = Excellent)." ],
  33. "-m" => [ true, "Set Minimum Rank [Manual,Low,Average,Normal,Good,Great,Excellent] (Default = Manual)."],
  34. "-s" => [ false, "Sort by Rank instead of Module Type."],
  35. "-r" => [ false, "Reverse Sort by Rank"],
  36. "-f" => [ true, "Filter based on Module Type [#{filters.map{|f|f.capitalize}.join(", ")}] (Default = All)."],
  37. )
  38. opts.parse(ARGV) { |opt, idx, val|
  39. case opt
  40. when "-h"
  41. puts "\nMetasploit Script for Displaying Module Rank information."
  42. puts "=========================================================="
  43. puts opts.usage
  44. exit
  45. when "-M"
  46. unless ranks.include?(val)
  47. puts "Invalid Rank Supplied: #{val}"
  48. puts "Please use one of these: [Manual,Low,Average,Normal,Good,Great,Excellent]"
  49. exit
  50. end
  51. puts "Maximum Rank: #{val}"
  52. maxrank = ranks[val]
  53. when "-m"
  54. unless ranks.include?(val)
  55. puts "Invalid Rank Supplied: #{val}"
  56. puts "Please use one of these: [Manual,Low,Average,Normal,Good,Great,Excellent]"
  57. exit
  58. end
  59. puts "Minimum Rank: #{val}"
  60. minrank = ranks[val]
  61. when "-s"
  62. puts "Sorting by Rank"
  63. sort = 1
  64. when "-r"
  65. puts "Reverse Sorting by Rank"
  66. sort = 2
  67. when "-f"
  68. unless filters.include?(val.downcase)
  69. puts "Invalid Filter Supplied: #{val}"
  70. puts "Please use one of these: #{filters.map{|f|f.capitalize}.join(", ")}"
  71. exit
  72. end
  73. puts "Module Filter: #{val}"
  74. filter = val
  75. end
  76. }
  77. Indent = ' '
  78. # Always disable the database (we never need it just to list module
  79. # information).
  80. framework_opts = { 'DisableDatabase' => true }
  81. # If the user only wants a particular module type, no need to load the others
  82. if filter.downcase != 'all'
  83. framework_opts[:module_types] = [ filter.downcase ]
  84. end
  85. # Initialize the simplified framework instance.
  86. $framework = Msf::Simple::Framework.create(framework_opts)
  87. tbl = Rex::Text::Table.new(
  88. 'Header' => 'Module Ranks',
  89. 'Indent' => Indent.length,
  90. 'Columns' => [ 'Module', 'Rank' ]
  91. )
  92. $framework.modules.each { |name, mod|
  93. x = mod.new
  94. modrank = x.rank
  95. if modrank >= minrank and modrank<= maxrank
  96. tbl << [ x.fullname, modrank ]
  97. end
  98. }
  99. if sort == 1
  100. tbl.sort_rows(1)
  101. end
  102. if sort == 2
  103. tbl.sort_rows(1)
  104. tbl.rows.reverse
  105. end
  106. puts tbl.to_s