module_mixins.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 mixins. Handy for finding different "kinds" of modules.
  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. def do_want(klass)
  18. return false if klass.class != Module
  19. return false if [ Kernel, ERB::Util, SNMP::BER].include?(klass)
  20. return false if klass.to_s.match(/^Rex::Ui::Subscriber/)
  21. return true
  22. end
  23. # Initialize the simplified framework instance.
  24. $framework = Msf::Simple::Framework.create('DisableDatabase' => true)
  25. all_modules = $framework.exploits
  26. # If you give an argument (any argument will do), you really want a sorted
  27. # list of mixins, regardless of the module they're in.
  28. if ARGV[0]
  29. mod_hash = {}
  30. longest_name = 0
  31. all_modules.each_module do |name, mod|
  32. x = mod.new
  33. mixins = x.class.ancestors.select {|y| do_want(y) }
  34. mixins.each do |m|
  35. mod_hash[m] ||= 0
  36. mod_hash[m] += 1
  37. longest_name = m.to_s.size unless m.to_s.size < longest_name
  38. end
  39. end
  40. mod_hash.sort_by {|a| a[1]}.reverse.each do |arr|
  41. puts "%-#{longest_name}s | %d" % arr
  42. end
  43. else
  44. # Tables kind of suck for this.
  45. results = []
  46. longest_name = 0
  47. all_modules.each_module do |name, mod|
  48. x = mod.new
  49. mixins = x.class.ancestors.select {|y| do_want(y) }
  50. results << [x.fullname, mixins.sort {|a,b| a.to_s <=> b.to_s}.join(", ")]
  51. longest_name = x.fullname.size if longest_name < x.fullname.size
  52. end
  53. # name | module1, module1, etc.
  54. results.each do |r|
  55. puts "%-#{longest_name}s | %s" % r
  56. end
  57. end