module_targets.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 all modules with their targets
  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. sort=0
  18. fil = 0
  19. filter = ""
  20. opts = Rex::Parser::Arguments.new(
  21. "-h" => [ false, "Help menu." ],
  22. "-s" => [ false, "Sort by Target instead of Module Type."],
  23. "-r" => [ false, "Reverse Sort"],
  24. "-x" => [ true, "String or RegEx to try and match against the Targets field"]
  25. )
  26. opts.parse(ARGV) { |opt, idx, val|
  27. case opt
  28. when "-h"
  29. puts "\nMetasploit Script for Displaying Module Target information."
  30. puts "=========================================================="
  31. puts opts.usage
  32. exit
  33. when "-s"
  34. puts "Sorting by Target"
  35. sort = 1
  36. when "-r"
  37. puts "Reverse Sorting"
  38. sort = 2
  39. when "-x"
  40. puts "Filter: #{val}"
  41. filter = val
  42. fil=1
  43. end
  44. }
  45. Indent = ' '
  46. # Initialize the simplified framework instance.
  47. $framework = Msf::Simple::Framework.create('DisableDatabase' => true)
  48. tbl = Rex::Text::Table.new(
  49. 'Header' => 'Module Targets',
  50. 'Indent' => Indent.length,
  51. 'Columns' => [ 'Module name','Target' ]
  52. )
  53. all_modules = $framework.exploits
  54. all_modules.each_module { |name, mod|
  55. x = mod.new
  56. x.targets.each do |targ|
  57. if fil==0 or targ.name=~/#{filter}/
  58. tbl << [ x.fullname, targ.name ]
  59. end
  60. end
  61. }
  62. if sort == 1
  63. tbl.sort_rows(1)
  64. end
  65. if sort == 2
  66. tbl.sort_rows(1)
  67. tbl.rows.reverse
  68. end
  69. puts tbl.to_s