module_license.rb 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 by its licensing terms
  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 lic_short(l)
  18. if (l.class == Array)
  19. l = l[0]
  20. end
  21. case l
  22. when MSF_LICENSE
  23. 'MSF'
  24. when GPL_LICENSE
  25. 'GPL'
  26. when BSD_LICENSE
  27. 'BSD'
  28. when ARTISTIC_LICENSE
  29. 'ART'
  30. else
  31. 'UNK'
  32. end
  33. end
  34. sort=0
  35. filter= 'All'
  36. filters = ['all','exploit','payload','post','nop','encoder','auxiliary']
  37. reg=0
  38. regex= ''
  39. opts = Rex::Parser::Arguments.new(
  40. "-h" => [ false, "Help menu." ],
  41. "-s" => [ false, "Sort by License instead of Module Type."],
  42. "-r" => [ false, "Reverse Sort"],
  43. "-f" => [ true, "Filter based on Module Type [#{filters.map{|f|f.capitalize}.join(", ")}] (Default = All)."],
  44. "-x" => [ true, "String or RegEx to try and match against the License Field"]
  45. )
  46. opts.parse(ARGV) { |opt, idx, val|
  47. case opt
  48. when "-h"
  49. puts "\nMetasploit Script for Displaying Module License information."
  50. puts "=========================================================="
  51. puts opts.usage
  52. exit
  53. when "-s"
  54. puts "Sorting by License"
  55. sort = 1
  56. when "-r"
  57. puts "Reverse Sorting"
  58. sort = 2
  59. when "-f"
  60. unless filters.include?(val.downcase)
  61. puts "Invalid Filter Supplied: #{val}"
  62. puts "Please use one of these: #{filters.map{|f|f.capitalize}.join(", ")}"
  63. exit
  64. end
  65. puts "Module Filter: #{val}"
  66. filter = val
  67. when "-x"
  68. puts "Regex: #{val}"
  69. reg=1
  70. regex = val
  71. end
  72. }
  73. Indent = ' '
  74. # Always disable the database (we never need it just to list module
  75. # information).
  76. framework_opts = { 'DisableDatabase' => true }
  77. # If the user only wants a particular module type, no need to load the others
  78. if filter.downcase != 'all'
  79. framework_opts[:module_types] = [ filter.downcase ]
  80. end
  81. # Initialize the simplified framework instance.
  82. $framework = Msf::Simple::Framework.create(framework_opts)
  83. tbl = Rex::Text::Table.new(
  84. 'Header' => 'Licensed Modules',
  85. 'Indent' => Indent.length,
  86. 'Columns' => [ 'License','Type', 'Name' ]
  87. )
  88. licenses = {}
  89. $framework.modules.each { |name, mod|
  90. x = mod.new
  91. lictype = lic_short(x.license)
  92. if reg==0 or lictype=~/#{regex}/
  93. tbl << [ lictype, mod.type.capitalize, name ]
  94. end
  95. }
  96. if sort == 1
  97. tbl.sort_rows(0)
  98. end
  99. if sort == 2
  100. tbl.sort_rows(1)
  101. tbl.rows.reverse
  102. end
  103. puts tbl.to_s