2007-10-02 16:09:13 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
#
|
2010-05-03 17:13:09 +00:00
|
|
|
# $Id$
|
|
|
|
#
|
2010-06-15 07:14:29 +00:00
|
|
|
# This script lists each module with its references
|
2007-10-02 16:09:13 +00:00
|
|
|
#
|
2010-05-03 17:13:09 +00:00
|
|
|
# $Revision$
|
|
|
|
#
|
2007-10-02 16:09:13 +00:00
|
|
|
|
2012-02-04 06:38:21 +00:00
|
|
|
msfbase = __FILE__
|
|
|
|
while File.symlink?(msfbase)
|
|
|
|
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
|
|
|
|
end
|
|
|
|
|
|
|
|
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', 'lib')))
|
|
|
|
require 'fastlib'
|
|
|
|
|
|
|
|
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
|
2007-10-02 16:09:13 +00:00
|
|
|
|
|
|
|
require 'rex'
|
|
|
|
require 'msf/ui'
|
|
|
|
require 'msf/base'
|
|
|
|
|
2011-06-07 00:20:21 +00:00
|
|
|
|
|
|
|
sort=0
|
|
|
|
filter= 'All'
|
2011-06-07 01:25:12 +00:00
|
|
|
filters = ['all','exploit','payload','post','nop','encoder','auxiliary']
|
2011-06-07 00:20:21 +00:00
|
|
|
types = ['All','URL','CVE','OSVDB','BID','MSB','NSS','US-CERT-VU']
|
|
|
|
type='All'
|
2011-06-07 01:25:12 +00:00
|
|
|
match= nil
|
2011-06-07 00:20:21 +00:00
|
|
|
|
|
|
|
opts = Rex::Parser::Arguments.new(
|
|
|
|
"-h" => [ false, "Help menu." ],
|
|
|
|
"-s" => [ false, "Sort by Reference instead of Module Type."],
|
|
|
|
"-r" => [ false, "Reverse Sort"],
|
|
|
|
"-f" => [ true, "Filter based on Module Type [All,Exploit,Payload,Post,NOP,Encoder,Auxiliary] (Default = All)."],
|
|
|
|
"-t" => [ true, "Type of Reference to sort by [All,URL,CVE,OSVDB,BID,MSB,NSS,US-CERT-VU]"],
|
|
|
|
"-x" => [ true, "String or RegEx to try and match against the Reference Field"]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
opts.parse(ARGV) { |opt, idx, val|
|
|
|
|
case opt
|
|
|
|
when "-h"
|
|
|
|
puts "\nMetasploit Script for Displaying Module Reference information."
|
|
|
|
puts "=========================================================="
|
|
|
|
puts opts.usage
|
|
|
|
exit
|
|
|
|
when "-s"
|
|
|
|
puts "Sorting by License"
|
|
|
|
sort = 1
|
|
|
|
when "-r"
|
|
|
|
puts "Reverse Sorting"
|
|
|
|
sort = 2
|
|
|
|
when "-f"
|
2011-06-07 01:25:12 +00:00
|
|
|
unless filters.include?(val.downcase)
|
2011-06-07 00:20:21 +00:00
|
|
|
puts "Invalid Filter Supplied: #{val}"
|
2011-06-07 01:25:12 +00:00
|
|
|
puts "Please use one of these: #{filters.map{|f|f.capitalize}.join(", ")}"
|
2011-06-07 00:20:21 +00:00
|
|
|
exit
|
|
|
|
end
|
|
|
|
puts "Module Filter: #{val}"
|
|
|
|
filter = val
|
|
|
|
when "-t"
|
|
|
|
unless types.include?(val)
|
|
|
|
puts "Invalid Type Supplied: #{val}"
|
|
|
|
puts "Please use one of these: [All,URL,CVE,OSVDB,BID,MSB,NSS,US-CERT-VU]"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
puts "Type: #{val}"
|
|
|
|
type = val
|
|
|
|
when "-x"
|
|
|
|
puts "Regex: #{val}"
|
2011-06-07 01:25:12 +00:00
|
|
|
match = Regexp.new(val)
|
2011-06-07 00:20:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
puts "Type: #{type}"
|
|
|
|
|
2010-11-05 00:06:31 +00:00
|
|
|
Indent = ' '
|
2007-10-02 16:09:13 +00:00
|
|
|
|
2011-06-07 01:25:12 +00:00
|
|
|
# Always disable the database (we never need it just to list module
|
|
|
|
# information).
|
|
|
|
framework_opts = { 'DisableDatabase' => true }
|
|
|
|
|
|
|
|
# If the user only wants a particular module type, no need to load the others
|
|
|
|
if filter.downcase != 'all'
|
|
|
|
framework_opts[:module_types] = [ filter.downcase ]
|
|
|
|
end
|
|
|
|
|
2007-10-02 16:09:13 +00:00
|
|
|
# Initialize the simplified framework instance.
|
2011-06-07 01:25:12 +00:00
|
|
|
$framework = Msf::Simple::Framework.create(framework_opts)
|
|
|
|
|
2007-10-02 16:09:13 +00:00
|
|
|
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => 'Module References',
|
2009-01-10 22:26:58 +00:00
|
|
|
'Indent' => Indent.length,
|
2007-10-02 16:09:13 +00:00
|
|
|
'Columns' => [ 'Module', 'Reference' ]
|
|
|
|
)
|
|
|
|
|
2011-06-07 01:25:12 +00:00
|
|
|
$framework.modules.each { |name, mod|
|
|
|
|
next if match and not name =~ match
|
2007-10-02 16:09:13 +00:00
|
|
|
|
2011-06-07 01:25:12 +00:00
|
|
|
x = mod.new
|
|
|
|
x.references.each do |r|
|
|
|
|
if type=='All' or type==r.ctx_id
|
|
|
|
ref = r.ctx_id + '-' + r.ctx_val
|
|
|
|
tbl << [ x.fullname, ref ]
|
2011-06-07 00:20:21 +00:00
|
|
|
end
|
2011-06-07 01:25:12 +00:00
|
|
|
end
|
|
|
|
}
|
2011-06-07 00:20:21 +00:00
|
|
|
|
|
|
|
if sort == 1
|
|
|
|
tbl.sort_rows(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if sort == 2
|
|
|
|
tbl.sort_rows(1)
|
|
|
|
tbl.rows.reverse
|
|
|
|
end
|
2007-10-02 16:09:13 +00:00
|
|
|
|
|
|
|
|
2009-01-10 22:26:58 +00:00
|
|
|
puts tbl.to_s
|