2010-12-28 19:47:56 +00:00
|
|
|
##
|
2011-10-23 11:56:13 +00:00
|
|
|
# $Id$
|
|
|
|
# $Revision$
|
2010-12-28 19:47:56 +00:00
|
|
|
##
|
|
|
|
|
2010-07-29 03:50:59 +00:00
|
|
|
$:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'lab'))
|
|
|
|
|
|
|
|
require 'yaml'
|
2010-12-28 19:47:56 +00:00
|
|
|
require 'vm_controller'
|
2010-07-29 03:50:59 +00:00
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
class Plugin::Lab < Msf::Plugin
|
|
|
|
class LabCommandDispatcher
|
|
|
|
include Msf::Ui::Console::CommandDispatcher
|
|
|
|
|
|
|
|
attr_accessor :controller
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-07-29 03:50:59 +00:00
|
|
|
def initialize(driver)
|
|
|
|
super(driver)
|
|
|
|
@controller = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the hash of commands supported by this dispatcher.
|
|
|
|
#
|
|
|
|
def commands
|
2010-12-28 19:47:56 +00:00
|
|
|
{
|
|
|
|
"lab_help" => "lab_help <lab command> - Show that command's description.",
|
|
|
|
"lab_show" => "lab_show - show all vms in the lab.",
|
2011-12-22 20:56:45 +00:00
|
|
|
"lab_search" => "lab_search - search local vms in the lab.",
|
|
|
|
"lab_search_tags" => "lab_search_tag - search local vms in the lab.",
|
|
|
|
#"lab_search_remote" => "lab_search_remote - search remote vms in the lab.",
|
2010-12-28 19:47:56 +00:00
|
|
|
"lab_show_running" => "lab_show_running - show running vms.",
|
2011-10-23 11:56:13 +00:00
|
|
|
"lab_load" => "lab_load [file] - load a lab definition from disk.",
|
2010-12-28 19:47:56 +00:00
|
|
|
"lab_save" => "lab_save [filename] - persist a lab definition in a file.",
|
2011-10-23 11:56:13 +00:00
|
|
|
"lab_load_running" => "lab_load_running [type] [user] [host] - use the running vms to create a lab.",
|
|
|
|
"lab_load_config" => "lab_load_config [type] [user] [host] - use the vms in the config to create a lab.",
|
2011-02-16 02:17:23 +00:00
|
|
|
"lab_load_dir" => "lab_load_dir [type] [directory] - create a lab from a specified directory.",
|
2011-10-23 11:56:13 +00:00
|
|
|
"lab_clear" => "lab_clear - clear the running lab.",
|
2010-12-28 19:47:56 +00:00
|
|
|
"lab_start" => "lab_start [vmid+|all] start the specified vm.",
|
|
|
|
"lab_reset" => "lab_reset [vmid+|all] reset the specified vm.",
|
|
|
|
"lab_suspend" => "lab_suspend [vmid+|all] suspend the specified vm.",
|
|
|
|
"lab_stop" => "lab_stop [vmid+|all] stop the specified vm.",
|
|
|
|
"lab_revert" => "lab_revert [vmid+|all] [snapshot] revert the specified vm.",
|
2011-05-30 05:04:11 +00:00
|
|
|
"lab_snapshot" => "lab_snapshot [vmid+|all] [snapshot] snapshot all targets for this exploit.",
|
2011-12-22 20:56:45 +00:00
|
|
|
"lab_upload" => "lab_upload [vmid] [local_path] [remote_path] upload a file.",
|
2011-05-30 04:46:29 +00:00
|
|
|
"lab_run_command" => "lab_run_command [vmid+|all] [command] run a command on all targets.",
|
|
|
|
"lab_browse_to" => "lab_browse_to [vmid+|all] [uri] use the default browser to browse to a uri."
|
2010-07-29 03:50:59 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
|
|
|
"Lab"
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-12-28 19:47:56 +00:00
|
|
|
##
|
|
|
|
## Regular Lab Commands
|
2011-10-23 11:56:13 +00:00
|
|
|
##
|
2010-12-28 19:47:56 +00:00
|
|
|
|
|
|
|
def cmd_lab_load(*args)
|
2011-10-23 11:56:13 +00:00
|
|
|
return lab_usage unless args.count == 1
|
2011-12-22 06:25:43 +00:00
|
|
|
|
|
|
|
res = args[0]
|
|
|
|
good_res = nil
|
|
|
|
if (File.file? res and File.readable? res)
|
|
|
|
# then the provided argument is an absolute path and is gtg.
|
|
|
|
good_res = res
|
|
|
|
elsif
|
|
|
|
# let's check to see if it's in the data/lab dir (like when tab completed)
|
|
|
|
[
|
|
|
|
::Msf::Config.data_directory + File::SEPARATOR + "lab",
|
|
|
|
# there isn't a user_data_directory, but could use:
|
|
|
|
#::Msf::Config.user_plugins_directory + File::SEPARATOR + "lab"
|
|
|
|
].each do |dir|
|
|
|
|
res_path = dir + File::SEPARATOR + res
|
|
|
|
if (File.file?(res_path) and File.readable?(res_path))
|
|
|
|
good_res = res_path
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if good_res
|
|
|
|
@controller.from_file(good_res)
|
|
|
|
else
|
|
|
|
print_error("#{res} is not a valid lab definition file (.yml)")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Tab completion for the lab_load command
|
|
|
|
#
|
|
|
|
def cmd_lab_load_tabs(str, words)
|
|
|
|
tabs = []
|
|
|
|
#return tabs if words.length > 1
|
|
|
|
if ( str and str =~ /^#{Regexp.escape(File::SEPARATOR)}/ )
|
|
|
|
# then you are probably specifying a full path so let's just use normal file completion
|
|
|
|
return tab_complete_filenames(str,words)
|
|
|
|
elsif (not words[1] or not words[1].match(/^\//))
|
|
|
|
# then let's start tab completion in the data/lab directory
|
|
|
|
begin
|
|
|
|
[
|
|
|
|
::Msf::Config.data_directory + File::SEPARATOR + "lab",
|
|
|
|
# there isn't a user_data_directory, but could use:
|
|
|
|
#::Msf::Config.user_plugins_directory + File::SEPARATOR + "lab"
|
|
|
|
].each do |dir|
|
|
|
|
next if not ::File.exist? dir
|
|
|
|
tabs += ::Dir.new(dir).find_all { |e|
|
|
|
|
path = dir + File::SEPARATOR + e
|
|
|
|
::File.file?(path) and File.readable?(path)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
rescue Exception
|
|
|
|
end
|
|
|
|
else
|
|
|
|
tabs += tab_complete_filenames(str,words)
|
|
|
|
end
|
|
|
|
return tabs
|
|
|
|
end
|
|
|
|
|
|
|
|
def cmd_lab_load_dir(*args)
|
|
|
|
return lab_usage unless args.count == 2
|
|
|
|
@controller.build_from_dir(args[0],args[1],true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def cmd_lab_clear(*args)
|
|
|
|
@controller.clear!
|
|
|
|
end
|
|
|
|
|
|
|
|
def cmd_lab_save(*args)
|
|
|
|
return lab_usage if args.empty?
|
|
|
|
@controller.to_file(args[0])
|
2010-09-17 19:29:59 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
|
2010-12-28 19:47:56 +00:00
|
|
|
def cmd_lab_load_running(*args)
|
2011-02-04 21:34:26 +00:00
|
|
|
return lab_usage if args.empty?
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-16 02:17:23 +00:00
|
|
|
if args[0] =~ /^remote_/
|
2011-10-23 11:56:13 +00:00
|
|
|
return lab_usage unless args.count == 3
|
2011-02-16 02:17:23 +00:00
|
|
|
## Expect a username & password
|
2011-02-04 21:34:26 +00:00
|
|
|
@controller.build_from_running(args[0], args[1], args[2])
|
|
|
|
else
|
2011-10-23 11:56:13 +00:00
|
|
|
return lab_usage unless args.count == 1
|
2011-02-04 21:34:26 +00:00
|
|
|
@controller.build_from_running(args[0])
|
|
|
|
end
|
2010-12-28 19:47:56 +00:00
|
|
|
end
|
|
|
|
|
2011-02-18 17:04:01 +00:00
|
|
|
def cmd_lab_load_config(*args)
|
|
|
|
return lab_usage if args.empty?
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-02-18 17:04:01 +00:00
|
|
|
if args[0] =~ /^remote_/
|
2011-10-23 11:56:13 +00:00
|
|
|
return lab_usage unless args.count == 3
|
2011-02-18 17:04:01 +00:00
|
|
|
## Expect a username & password
|
|
|
|
@controller.build_from_config(args[0], args[1], args[2])
|
|
|
|
else
|
2011-10-23 11:56:13 +00:00
|
|
|
return lab_usage unless args.count == 1
|
2011-02-18 17:04:01 +00:00
|
|
|
@controller.build_from_config(args[0])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
def cmd_lab_load_dir(*args)
|
2011-02-16 02:17:23 +00:00
|
|
|
return lab_usage unless args.count == 2
|
|
|
|
@controller.build_from_dir(args[0],args[1],true)
|
2010-12-28 19:47:56 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
|
|
|
|
def cmd_lab_clear(*args)
|
2010-12-28 19:47:56 +00:00
|
|
|
@controller.clear!
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
def cmd_lab_save(*args)
|
2010-09-17 19:29:59 +00:00
|
|
|
return lab_usage if args.empty?
|
2010-12-28 19:47:56 +00:00
|
|
|
@controller.to_file(args[0])
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
|
|
|
|
##
|
2010-07-29 03:50:59 +00:00
|
|
|
## Commands for dealing with a currently-loaded lab
|
2011-10-23 11:56:13 +00:00
|
|
|
##
|
2010-07-29 03:50:59 +00:00
|
|
|
def cmd_lab_show(*args)
|
2011-06-02 06:18:38 +00:00
|
|
|
if args.empty?
|
|
|
|
hlp_print_lab
|
|
|
|
else
|
2011-12-22 20:56:45 +00:00
|
|
|
args.each do |name|
|
|
|
|
if @controller.includes_hostname? name
|
|
|
|
print_line @controller[name].to_yaml
|
2011-06-02 06:18:38 +00:00
|
|
|
else
|
2011-12-22 20:56:45 +00:00
|
|
|
print_error "Unknown vm '#{name}'"
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2011-06-02 06:18:38 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
|
|
|
|
def cmd_lab_show_running(*args)
|
|
|
|
hlp_print_lab_running
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
|
|
|
|
2011-12-22 20:56:45 +00:00
|
|
|
|
|
|
|
def cmd_lab_search(*args)
|
|
|
|
if args.empty?
|
|
|
|
hlp_print_lab
|
|
|
|
else
|
|
|
|
args.each do |arg|
|
|
|
|
print_line "Searching for vms with hostname matching #{arg}"
|
|
|
|
@controller.each do |vm|
|
|
|
|
print_line "checking to see #{vm.hostname} matches #{arg}"
|
|
|
|
print_line "#{vm.hostname} matched #{arg}" if vm.hostname =~ Regexp.new(arg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def cmd_lab_search_tags(*args)
|
|
|
|
if args.empty?
|
|
|
|
hlp_print_lab
|
|
|
|
else
|
|
|
|
args.each do |arg|
|
|
|
|
print_line "Searching for vms with tags matching #{arg}"
|
|
|
|
@controller.each do |vm|
|
|
|
|
print_line "checking to see #{vm.hostname} is tagged #{arg}"
|
|
|
|
print_line "#{vm.hostname} tagged #{arg}" if vm.tagged?(arg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2010-09-17 19:29:59 +00:00
|
|
|
def cmd_lab_start(*args)
|
|
|
|
return lab_usage if args.empty?
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-07-29 03:50:59 +00:00
|
|
|
if args[0] == "all"
|
2011-10-23 11:56:13 +00:00
|
|
|
@controller.each do |vm|
|
2011-12-22 20:56:45 +00:00
|
|
|
print_line "Starting lab vm #{vm.hostname}."
|
2010-12-28 19:47:56 +00:00
|
|
|
if !vm.running?
|
|
|
|
vm.start
|
|
|
|
else
|
2011-12-22 20:56:45 +00:00
|
|
|
print_line "Lab vm #{vm.hostname} already running."
|
2010-12-28 19:47:56 +00:00
|
|
|
end
|
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
else
|
2010-12-28 19:47:56 +00:00
|
|
|
args.each do |arg|
|
2011-12-22 20:56:45 +00:00
|
|
|
if @controller.includes_hostname? arg
|
|
|
|
vm = @controller.find_by_hostname(arg)
|
2010-12-28 19:47:56 +00:00
|
|
|
if !vm.running?
|
2011-12-22 20:56:45 +00:00
|
|
|
print_line "Starting lab vm #{vm.hostname}."
|
2010-12-28 19:47:56 +00:00
|
|
|
vm.start
|
2010-07-29 03:50:59 +00:00
|
|
|
else
|
2011-12-22 20:56:45 +00:00
|
|
|
print_line "Lab vm #{vm.hostname} already running."
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
|
|
|
end
|
2010-09-17 19:29:59 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-07-29 03:50:59 +00:00
|
|
|
def cmd_lab_stop(*args)
|
2010-09-17 19:29:59 +00:00
|
|
|
return lab_usage if args.empty?
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-07-29 03:50:59 +00:00
|
|
|
if args[0] == "all"
|
2011-10-23 11:56:13 +00:00
|
|
|
@controller.each do |vm|
|
2011-12-22 20:56:45 +00:00
|
|
|
print_line "Stopping lab vm #{vm.hostname}."
|
2010-12-28 19:47:56 +00:00
|
|
|
if vm.running?
|
|
|
|
vm.stop
|
|
|
|
else
|
2011-12-22 20:56:45 +00:00
|
|
|
print_line "Lab vm #{vm.hostname} not running."
|
2010-12-28 19:47:56 +00:00
|
|
|
end
|
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
else
|
2010-12-28 19:47:56 +00:00
|
|
|
args.each do |arg|
|
2011-12-22 20:56:45 +00:00
|
|
|
if @controller.includes_hostname? arg
|
|
|
|
vm = @controller.find_by_hostname(arg)
|
2010-12-28 19:47:56 +00:00
|
|
|
if vm.running?
|
2011-12-22 20:56:45 +00:00
|
|
|
print_line "Stopping lab vm #{vm.hostname}."
|
2010-12-28 19:47:56 +00:00
|
|
|
vm.stop
|
2010-07-29 03:50:59 +00:00
|
|
|
else
|
2011-12-22 20:56:45 +00:00
|
|
|
print_line "Lab vm #{vm.hostname} not running."
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
|
|
|
|
def cmd_lab_suspend(*args)
|
2010-09-17 19:29:59 +00:00
|
|
|
return lab_usage if args.empty?
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-07-29 03:50:59 +00:00
|
|
|
if args[0] == "all"
|
2011-06-02 06:18:38 +00:00
|
|
|
@controller.each{ |vm| vm.suspend }
|
2010-07-29 03:50:59 +00:00
|
|
|
else
|
2010-12-28 19:47:56 +00:00
|
|
|
args.each do |arg|
|
2011-12-22 20:56:45 +00:00
|
|
|
if @controller.includes_hostname? arg
|
|
|
|
if @controller.find_by_hostname(arg).running?
|
2011-06-05 06:57:24 +00:00
|
|
|
print_line "Suspending lab vm #{arg}."
|
2011-12-22 20:56:45 +00:00
|
|
|
@controller.find_by_hostname(arg).suspend
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
|
|
|
|
def cmd_lab_reset(*args)
|
2010-09-17 19:29:59 +00:00
|
|
|
return lab_usage if args.empty?
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-07-29 03:50:59 +00:00
|
|
|
if args[0] == "all"
|
2010-12-28 19:47:56 +00:00
|
|
|
print_line "Resetting all lab vms."
|
2011-06-02 06:18:38 +00:00
|
|
|
@controller.each{ |vm| vm.reset }
|
2010-07-29 03:50:59 +00:00
|
|
|
else
|
2010-12-28 19:47:56 +00:00
|
|
|
args.each do |arg|
|
2011-12-22 20:56:45 +00:00
|
|
|
if @controller.includes_hostname? arg
|
|
|
|
if @controller.find_by_hostname(arg).running?
|
2011-06-05 06:57:24 +00:00
|
|
|
print_line "Resetting lab vm #{arg}."
|
2011-12-22 20:56:45 +00:00
|
|
|
@controller.find_by_hostname(arg).reset
|
2011-06-05 06:57:24 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
def cmd_lab_snapshot(*args)
|
2010-12-28 19:47:56 +00:00
|
|
|
return lab_usage if args.count < 2
|
2011-10-23 11:56:13 +00:00
|
|
|
snapshot = args[args.count-1]
|
|
|
|
|
2010-07-29 03:50:59 +00:00
|
|
|
if args[0] == "all"
|
2010-12-28 19:47:56 +00:00
|
|
|
print_line "Snapshotting all lab vms to snapshot: #{snapshot}."
|
2011-02-16 02:17:23 +00:00
|
|
|
@controller.each{ |vm| vm.create_snapshot(snapshot) }
|
2010-07-29 03:50:59 +00:00
|
|
|
else
|
2011-12-22 20:56:45 +00:00
|
|
|
args[0..-2].each do |name_arg|
|
|
|
|
next unless @controller.includes_hostname? name_arg
|
|
|
|
print_line "Snapshotting #{name_arg} to snapshot: #{snapshot}."
|
|
|
|
@controller[name_arg].create_snapshot(snapshot)
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
def cmd_lab_revert(*args)
|
2010-12-28 19:47:56 +00:00
|
|
|
return lab_usage if args.count < 2
|
2011-10-23 11:56:13 +00:00
|
|
|
snapshot = args[args.count-1]
|
2010-07-29 03:50:59 +00:00
|
|
|
|
|
|
|
if args[0] == "all"
|
2010-12-28 19:47:56 +00:00
|
|
|
print_line "Reverting all lab vms to snapshot: #{snapshot}."
|
2011-02-16 02:17:23 +00:00
|
|
|
@controller.each{ |vm| vm.revert_snapshot(snapshot) }
|
2010-07-29 03:50:59 +00:00
|
|
|
else
|
2011-12-22 20:56:45 +00:00
|
|
|
args[0..-2].each do |name_arg|
|
|
|
|
next unless @controller.includes_hostname? name_arg
|
|
|
|
print_line "Reverting #{name_arg} to snapshot: #{snapshot}."
|
|
|
|
@controller[name_arg].revert_snapshot(snapshot)
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
def cmd_lab_run_command(*args)
|
2010-09-17 19:29:59 +00:00
|
|
|
return lab_usage if args.empty?
|
2011-02-16 02:17:23 +00:00
|
|
|
command = args[args.count-1]
|
2011-05-30 04:46:29 +00:00
|
|
|
if args[0] == "all"
|
|
|
|
print_line "Running command #{command} on all vms."
|
2011-10-23 11:56:13 +00:00
|
|
|
@controller.each do |vm|
|
2011-06-05 06:57:24 +00:00
|
|
|
if vm.running?
|
2011-12-22 20:56:45 +00:00
|
|
|
print_line "#{vm.hostname} running command: #{command}."
|
2011-06-05 06:57:24 +00:00
|
|
|
vm.run_command(command)
|
|
|
|
end
|
|
|
|
end
|
2011-12-22 20:56:45 +00:00
|
|
|
else
|
|
|
|
args[0..-2].each do |name_arg|
|
|
|
|
next unless @controller.includes_hostname? name_arg
|
|
|
|
if @controller[name_arg].running?
|
|
|
|
print_line "#{name_arg} running command: #{command}."
|
|
|
|
@controller[name_arg].run_command(command)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Command: lab_upload [vmids] [from] [to]
|
|
|
|
#
|
|
|
|
# Description: Uploads a file to the guest(s)
|
|
|
|
#
|
|
|
|
# Quirks: Pass "all" as a vmid to have it operate on all vms.
|
|
|
|
#
|
|
|
|
def cmd_lab_upload(*args)
|
|
|
|
return lab_usage if args.empty?
|
|
|
|
return lab_usage if args.count < 3
|
|
|
|
|
|
|
|
local_path = args[args.count-2]
|
|
|
|
vm_path = args[args.count-1]
|
2012-01-06 00:26:05 +00:00
|
|
|
|
2011-12-22 20:56:45 +00:00
|
|
|
if args[0] == "all"
|
|
|
|
@controller.each do |vm|
|
|
|
|
if vm.running?
|
|
|
|
print_line "Copying from #{local_path} to #{vm_path} on #{vm.hostname}"
|
|
|
|
vm.copy_to_guest(local_path, vm_path)
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 04:46:29 +00:00
|
|
|
else
|
|
|
|
args[0..-2].each do |vmid_arg|
|
2012-01-06 02:42:58 +00:00
|
|
|
next unless @controller.includes_hostname? vmid_arg
|
2011-06-05 06:57:24 +00:00
|
|
|
if @controller[vmid_arg].running?
|
2011-12-22 20:56:45 +00:00
|
|
|
print_line "Copying from #{local_path} to #{vm_path} on #{vmid_arg}"
|
|
|
|
@controller[vmid_arg].copy_to_guest(local_path, vm_path)
|
2011-06-05 06:57:24 +00:00
|
|
|
end
|
2011-05-30 04:46:29 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
|
|
|
|
def cmd_lab_browse_to(*args)
|
2010-09-17 19:29:59 +00:00
|
|
|
return lab_usage if args.empty?
|
2011-02-16 02:17:23 +00:00
|
|
|
uri = args[args.count-1]
|
2011-05-30 04:46:29 +00:00
|
|
|
if args[0] == "all"
|
|
|
|
print_line "Opening: #{uri} on all vms."
|
2011-10-23 11:56:13 +00:00
|
|
|
@controller.each do |vm|
|
2011-06-05 06:57:24 +00:00
|
|
|
if vm.running?
|
2011-12-22 20:56:45 +00:00
|
|
|
print_line "#{vm.hostname} opening to uri: #{uri}."
|
2011-06-05 06:57:24 +00:00
|
|
|
vm.open_uri(uri)
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 04:46:29 +00:00
|
|
|
else
|
2011-12-22 20:56:45 +00:00
|
|
|
args[0..-2].each do |name_arg|
|
|
|
|
next unless @controller.includes_hostname? name_arg
|
|
|
|
if @controller[name_arg].running?
|
|
|
|
print_line "#{name_arg} opening to uri: #{uri}."
|
|
|
|
@controller[name_arg].open_uri(uri)
|
2011-06-05 06:57:24 +00:00
|
|
|
end
|
2011-05-30 04:46:29 +00:00
|
|
|
end
|
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-07-11 05:52:51 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
## Commands for help
|
|
|
|
##
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-07-11 05:52:51 +00:00
|
|
|
def longest_cmd_size
|
|
|
|
commands.keys.map {|x| x.size}.sort.last
|
|
|
|
end
|
|
|
|
|
|
|
|
# No extended help yet, but this is where more detailed documentation
|
|
|
|
# on particular commands would live. Key is command, (not cmd_command),
|
|
|
|
# value is the documentation.
|
|
|
|
def extended_help
|
|
|
|
{
|
|
|
|
"lab_fake_cmd" => "This is a fake command. It's got its own special docs." +
|
|
|
|
(" " * longest_cmd_size) + "It might be long so so deal with formatting somehow."
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
# Map for usages
|
|
|
|
def lab_usage
|
|
|
|
caller[0][/`cmd_(.*)'/]
|
|
|
|
cmd = $1
|
|
|
|
if extended_help[cmd] || commands[cmd]
|
|
|
|
cmd_lab_help cmd
|
|
|
|
else # Should never really get here...
|
|
|
|
print_error "Unknown command. Try 'help'"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def cmd_lab_help(*args)
|
|
|
|
if args.empty?
|
|
|
|
commands.each_pair {|k,v| print_line "%-#{longest_cmd_size}s - %s" % [k,v] }
|
|
|
|
else
|
|
|
|
args.each do |c|
|
|
|
|
if extended_help[c] || commands[c]
|
|
|
|
print_line "%-#{longest_cmd_size}s - %s" % [c,extended_help[c] || commands[c]]
|
|
|
|
else
|
|
|
|
print_error "Unknown command '#{c}'"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
print_line
|
2011-07-11 05:52:51 +00:00
|
|
|
print_line "In order to use this plugin, you'll want to configure a .yml lab file"
|
2011-10-23 11:56:13 +00:00
|
|
|
print_line "You can find an example in data/lab/test_targets.yml"
|
2011-07-11 05:52:51 +00:00
|
|
|
print_line
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2010-12-28 19:47:56 +00:00
|
|
|
private
|
|
|
|
def hlp_print_lab
|
|
|
|
indent = ' '
|
|
|
|
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => 'Available Lab VMs',
|
|
|
|
'Indent' => indent.length,
|
2011-12-22 20:56:45 +00:00
|
|
|
'Columns' => [ 'Hostname', 'Driver', 'Type' ]
|
2010-12-28 19:47:56 +00:00
|
|
|
)
|
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
@controller.each do |vm|
|
2011-12-22 20:56:45 +00:00
|
|
|
tbl << [ vm.hostname,
|
|
|
|
vm.driver.class,
|
|
|
|
vm.type]
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-12-28 19:47:56 +00:00
|
|
|
print_line tbl.to_s
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-12-28 19:47:56 +00:00
|
|
|
def hlp_print_lab_running
|
2011-10-23 11:56:13 +00:00
|
|
|
indent = ' '
|
2010-12-28 19:47:56 +00:00
|
|
|
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => 'Running Lab VMs',
|
|
|
|
'Indent' => indent.length,
|
2011-12-22 20:56:45 +00:00
|
|
|
'Columns' => [ 'Hostname', 'Driver', 'Type', 'Power?' ]
|
2010-12-28 19:47:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@controller.each do |vm|
|
2011-10-23 11:56:13 +00:00
|
|
|
if vm.running?
|
2011-12-22 20:56:45 +00:00
|
|
|
tbl << [ vm.hostname,
|
|
|
|
vm.driver.class,
|
|
|
|
vm.type,
|
2010-12-28 19:47:56 +00:00
|
|
|
vm.running?]
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
2010-12-28 19:47:56 +00:00
|
|
|
print_line tbl.to_s
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-07-29 03:50:59 +00:00
|
|
|
#
|
|
|
|
# The constructor is called when an instance of the plugin is created. The
|
|
|
|
# framework instance that the plugin is being associated with is passed in
|
|
|
|
# the framework parameter. Plugins should call the parent constructor when
|
|
|
|
# inheriting from Msf::Plugin to ensure that the framework attribute on
|
|
|
|
# their instance gets set.
|
|
|
|
#
|
2011-12-22 20:56:45 +00:00
|
|
|
attr_accessor :controller
|
|
|
|
|
2010-07-29 03:50:59 +00:00
|
|
|
def initialize(framework, opts)
|
|
|
|
super
|
|
|
|
|
|
|
|
## Register the commands above
|
|
|
|
console_dispatcher = add_console_dispatcher(LabCommandDispatcher)
|
|
|
|
|
2011-02-04 21:34:26 +00:00
|
|
|
@controller = ::Lab::Controllers::VmController.new
|
2010-07-29 03:50:59 +00:00
|
|
|
|
2010-12-28 19:47:56 +00:00
|
|
|
## Share the vms
|
|
|
|
console_dispatcher.controller = @controller
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# The cleanup routine for plugins gives them a chance to undo any actions
|
|
|
|
# they may have done to the framework. For instance, if a console
|
|
|
|
# dispatcher was added, then it should be removed in the cleanup routine.
|
|
|
|
#
|
|
|
|
def cleanup
|
|
|
|
# If we had previously registered a console dispatcher with the console,
|
|
|
|
# deregister it now.
|
|
|
|
remove_console_dispatcher('Lab')
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# This method returns a short, friendly name for the plugin.
|
|
|
|
#
|
|
|
|
def name
|
|
|
|
"lab"
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# This method returns a brief description of the plugin. It should be no
|
|
|
|
# more than 60 characters, but there are no hard limits.
|
|
|
|
#
|
|
|
|
def desc
|
2010-12-28 19:47:56 +00:00
|
|
|
"Adds the ability to manage VMs"
|
2010-07-29 03:50:59 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-07-29 03:50:59 +00:00
|
|
|
end ## End Class
|
2011-12-22 20:56:45 +00:00
|
|
|
end ## End Module
|