Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/tools/modules/module_license.rb
Views: 11766
#!/usr/bin/env ruby12##3# This module requires Metasploit: https://metasploit.com/download4# Current source: https://github.com/rapid7/metasploit-framework5##67#8# This script lists each module by its licensing terms9#1011msfbase = __FILE__12while File.symlink?(msfbase)13msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))14end1516$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))17require 'msfenv'1819$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']2021require 'rex'2223def lic_short(l)24if (l.class == Array)25l = l[0]26end2728case l29when MSF_LICENSE30'MSF'31when GPL_LICENSE32'GPL'33when BSD_LICENSE34'BSD'35when ARTISTIC_LICENSE36'ART'37else38'UNK'39end40end414243sort=044filter= 'All'45filters = ['all','exploit','payload','post','nop','encoder','auxiliary']46reg=047regex= ''4849opts = Rex::Parser::Arguments.new(50"-h" => [ false, "Help menu." ],51"-s" => [ false, "Sort by License instead of Module Type."],52"-r" => [ false, "Reverse Sort"],53"-f" => [ true, "Filter based on Module Type [#{filters.map{|f|f.capitalize}.join(", ")}] (Default = All)."],54"-x" => [ true, "String or RegEx to try and match against the License Field"]55)5657opts.parse(ARGV) { |opt, idx, val|58case opt59when "-h"60puts "\nMetasploit Script for Displaying Module License information."61puts "=========================================================="62puts opts.usage63exit64when "-s"65puts "Sorting by License"66sort = 167when "-r"68puts "Reverse Sorting"69sort = 270when "-f"71unless filters.include?(val.downcase)72puts "Invalid Filter Supplied: #{val}"73puts "Please use one of these: #{filters.map{|f|f.capitalize}.join(", ")}"74exit75end76puts "Module Filter: #{val}"77filter = val78when "-x"79puts "Regex: #{val}"80reg=181regex = val82end8384}8586878889Indent = ' '9091# Always disable the database (we never need it just to list module92# information).93framework_opts = { 'DisableDatabase' => true }9495# If the user only wants a particular module type, no need to load the others96if filter.downcase != 'all'97framework_opts[:module_types] = [ filter.downcase ]98end99100# Initialize the simplified framework instance.101$framework = Msf::Simple::Framework.create(framework_opts)102103104tbl = Rex::Text::Table.new(105'Header' => 'Licensed Modules',106'Indent' => Indent.length,107'Columns' => [ 'License','Type', 'Name' ]108)109110licenses = {}111112$framework.modules.each { |name, mod|113x = mod.new114lictype = lic_short(x.license)115if reg==0 or lictype=~/#{regex}/116tbl << [ lictype, mod.type.capitalize, name ]117end118}119120121if sort == 1122tbl.sort_rows(0)123end124125126if sort == 2127tbl.sort_rows(1)128tbl.rows.reverse129end130131puts tbl.to_s132133134